Projet

Général

Profil

Paste
Télécharger (44,1 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / lightbox2 / js / lightbox.js @ 76df55b7

1
/* $Id: lightbox.js,v 1.5.2.6.2.136 2010/09/24 08:39:40 snpower Exp $ */
2

    
3
/**
4
 * jQuery Lightbox
5
 * @author
6
 *   Stella Power, <http://drupal.org/user/66894>
7
 *
8
 * Based on Lightbox v2.03.3 by Lokesh Dhakar
9
 * <http://www.huddletogether.com/projects/lightbox2/>
10
 * Also partially based on the jQuery Lightbox by Warren Krewenki
11
 *   <http://warren.mesozen.com>
12
 *
13
 * Permission has been granted to Mark Ashmead & other Drupal Lightbox2 module
14
 * maintainers to distribute this file via Drupal.org
15
 * Under GPL license.
16
 *
17
 * Slideshow, iframe and video functionality added by Stella Power.
18
 */
19

    
20
var Lightbox;
21
(function($) {
22
Lightbox = {
23
  auto_modal : false,
24
  overlayOpacity : 0.8, // Controls transparency of shadow overlay.
25
  overlayColor : '000', // Controls colour of shadow overlay.
26
  disableCloseClick : true,
27
  // Controls the order of the lightbox resizing animation sequence.
28
  resizeSequence: 0, // 0: simultaneous, 1: width then height, 2: height then width.
29
  resizeSpeed: 'normal', // Controls the speed of the lightbox resizing animation.
30
  fadeInSpeed: 'normal', // Controls the speed of the image appearance.
31
  slideDownSpeed: 'slow', // Controls the speed of the image details appearance.
32
  minWidth: 240,
33
  borderSize : 10,
34
  boxColor : 'fff',
35
  fontColor : '000',
36
  topPosition : '',
37
  infoHeight: 20,
38
  alternative_layout : false,
39
  imageArray : [],
40
  imageNum : null,
41
  total : 0,
42
  activeImage : null,
43
  inprogress : false,
44
  disableResize : false,
45
  disableZoom : false,
46
  isZoomedIn : false,
47
  rtl : false,
48
  loopItems : false,
49
  keysClose : ['c', 'x', 27],
50
  keysPrevious : ['p', 37],
51
  keysNext : ['n', 39],
52
  keysZoom : ['z'],
53
  keysPlayPause : [32],
54

    
55
  // Slideshow options.
56
  slideInterval : 5000, // In milliseconds.
57
  showPlayPause : true,
58
  autoStart : true,
59
  autoExit : true,
60
  pauseOnNextClick : false, // True to pause the slideshow when the "Next" button is clicked.
61
  pauseOnPrevClick : true, // True to pause the slideshow when the "Prev" button is clicked.
62
  slideIdArray : [],
63
  slideIdCount : 0,
64
  isSlideshow : false,
65
  isPaused : false,
66
  loopSlides : false,
67

    
68
  // Iframe options.
69
  isLightframe : false,
70
  iframe_width : 600,
71
  iframe_height : 400,
72
  iframe_border : 1,
73

    
74
  // Video and modal options.
75
  enableVideo : false,
76
  flvPlayer : '/flvplayer.swf',
77
  flvFlashvars : '',
78
  isModal : false,
79
  isVideo : false,
80
  videoId : false,
81
  modalWidth : 400,
82
  modalHeight : 400,
83
  modalHTML : null,
84

    
85

    
86
  // initialize()
87
  // Constructor runs on completion of the DOM loading.
88
  // The function inserts html at the bottom of the page which is used
89
  // to display the shadow overlay and the image container.
90
  initialize: function() {
91

    
92
    var s = Drupal.settings.lightbox2;
93
    Lightbox.overlayOpacity = s.overlay_opacity;
94
    Lightbox.overlayColor = s.overlay_color;
95
    Lightbox.disableCloseClick = s.disable_close_click;
96
    Lightbox.resizeSequence = s.resize_sequence;
97
    Lightbox.resizeSpeed = s.resize_speed;
98
    Lightbox.fadeInSpeed = s.fade_in_speed;
99
    Lightbox.slideDownSpeed = s.slide_down_speed;
100
    Lightbox.borderSize = s.border_size;
101
    Lightbox.boxColor = s.box_color;
102
    Lightbox.fontColor = s.font_color;
103
    Lightbox.topPosition = s.top_position;
104
    Lightbox.rtl = s.rtl;
105
    Lightbox.loopItems = s.loop_items;
106
    Lightbox.keysClose = s.keys_close.split(" ");
107
    Lightbox.keysPrevious = s.keys_previous.split(" ");
108
    Lightbox.keysNext = s.keys_next.split(" ");
109
    Lightbox.keysZoom = s.keys_zoom.split(" ");
110
    Lightbox.keysPlayPause = s.keys_play_pause.split(" ");
111
    Lightbox.disableResize = s.disable_resize;
112
    Lightbox.disableZoom = s.disable_zoom;
113
    Lightbox.slideInterval = s.slideshow_interval;
114
    Lightbox.showPlayPause = s.show_play_pause;
115
    Lightbox.showCaption = s.show_caption;
116
    Lightbox.autoStart = s.slideshow_automatic_start;
117
    Lightbox.autoExit = s.slideshow_automatic_exit;
118
    Lightbox.pauseOnNextClick = s.pause_on_next_click;
119
    Lightbox.pauseOnPrevClick = s.pause_on_previous_click;
120
    Lightbox.loopSlides = s.loop_slides;
121
    Lightbox.alternative_layout = s.use_alt_layout;
122
    Lightbox.iframe_width = s.iframe_width;
123
    Lightbox.iframe_height = s.iframe_height;
124
    Lightbox.iframe_border = s.iframe_border;
125
    Lightbox.enableVideo = s.enable_video;
126
    if (s.enable_video) {
127
      Lightbox.flvPlayer = s.flvPlayer;
128
      Lightbox.flvFlashvars = s.flvFlashvars;
129
    }
130

    
131
    // Make the lightbox divs.
132
    var layout_class = (s.use_alt_layout ? 'lightbox2-alt-layout' : 'lightbox2-orig-layout');
133
    var output = '<div id="lightbox2-overlay" style="display: none;"></div>\
134
      <div id="lightbox" style="display: none;" class="' + layout_class + '">\
135
        <div id="outerImageContainer"></div>\
136
        <div id="imageDataContainer" class="clearfix">\
137
          <div id="imageData"></div>\
138
        </div>\
139
      </div>';
140
    var loading = '<div id="loading"><a href="#" id="loadingLink"></a></div>';
141
    var modal = '<div id="modalContainer" style="display: none;"></div>';
142
    var frame = '<div id="frameContainer" style="display: none;"></div>';
143
    var imageContainer = '<div id="imageContainer" style="display: none;"></div>';
144
    var details = '<div id="imageDetails"></div>';
145
    var bottomNav = '<div id="bottomNav"></div>';
146
    var image = '<img id="lightboxImage" alt="" />';
147
    var hoverNav = '<div id="hoverNav"><a id="prevLink" href="#"></a><a id="nextLink" href="#"></a></div>';
148
    var frameNav = '<div id="frameHoverNav"><a id="framePrevLink" href="#"></a><a id="frameNextLink" href="#"></a></div>';
149
    var hoverNav = '<div id="hoverNav"><a id="prevLink" title="' + Drupal.t('Previous') + '" href="#"></a><a id="nextLink" title="' + Drupal.t('Next') + '" href="#"></a></div>';
150
    var frameNav = '<div id="frameHoverNav"><a id="framePrevLink" title="' + Drupal.t('Previous') + '" href="#"></a><a id="frameNextLink" title="' + Drupal.t('Next') + '" href="#"></a></div>';
151
    var caption = '<span id="caption"></span>';
152
    var numberDisplay = '<span id="numberDisplay"></span>';
153
    var close = '<a id="bottomNavClose" title="' + Drupal.t('Close') + '" href="#"></a>';
154
    var zoom = '<a id="bottomNavZoom" href="#"></a>';
155
    var zoomOut = '<a id="bottomNavZoomOut" href="#"></a>';
156
    var pause = '<a id="lightshowPause" title="' + Drupal.t('Pause Slideshow') + '" href="#" style="display: none;"></a>';
157
    var play = '<a id="lightshowPlay" title="' + Drupal.t('Play Slideshow') + '" href="#" style="display: none;"></a>';
158

    
159
    $("body").append(output);
160
    $('#outerImageContainer').append(modal + frame + imageContainer + loading);
161
    if (!s.use_alt_layout) {
162
      $('#imageContainer').append(image + hoverNav);
163
      $('#imageData').append(details + bottomNav);
164
      $('#imageDetails').append(caption + numberDisplay);
165
      $('#bottomNav').append(frameNav + close + zoom + zoomOut + pause + play);
166
    }
167
    else {
168
      $('#outerImageContainer').append(bottomNav);
169
      $('#imageContainer').append(image);
170
      $('#bottomNav').append(close + zoom + zoomOut);
171
      $('#imageData').append(hoverNav + details);
172
      $('#imageDetails').append(caption + numberDisplay + pause + play);
173
    }
174

    
175
    // Setup onclick handlers.
176
    if (Lightbox.disableCloseClick) {
177
      $('#lightbox2-overlay').click(function() { Lightbox.end(); return false; } ).hide();
178
    }
179
    $('#loadingLink, #bottomNavClose').click(function() { Lightbox.end('forceClose'); return false; } );
180
    $('#prevLink, #framePrevLink').click(function() { Lightbox.changeData(Lightbox.activeImage - 1); return false; } );
181
    $('#nextLink, #frameNextLink').click(function() { Lightbox.changeData(Lightbox.activeImage + 1); return false; } );
182
    $('#bottomNavZoom').click(function() { Lightbox.changeData(Lightbox.activeImage, true); return false; } );
183
    $('#bottomNavZoomOut').click(function() { Lightbox.changeData(Lightbox.activeImage, false); return false; } );
184
    $('#lightshowPause').click(function() { Lightbox.togglePlayPause("lightshowPause", "lightshowPlay"); return false; } );
185
    $('#lightshowPlay').click(function() { Lightbox.togglePlayPause("lightshowPlay", "lightshowPause"); return false; } );
186

    
187
    // Fix positioning.
188
    $('#prevLink, #nextLink, #framePrevLink, #frameNextLink').css({ 'paddingTop': Lightbox.borderSize + 'px'});
189
    $('#imageContainer, #frameContainer, #modalContainer').css({ 'padding': Lightbox.borderSize + 'px'});
190
    $('#outerImageContainer, #imageDataContainer, #bottomNavClose').css({'backgroundColor': '#' + Lightbox.boxColor, 'color': '#'+Lightbox.fontColor});
191
    if (Lightbox.alternative_layout) {
192
      $('#bottomNavZoom, #bottomNavZoomOut').css({'bottom': Lightbox.borderSize + 'px', 'right': Lightbox.borderSize + 'px'});
193
    }
194
    else if (Lightbox.rtl == 1 && $.browser.msie) {
195
      $('#bottomNavZoom, #bottomNavZoomOut').css({'left': '0px'});
196
    }
197

    
198
    // Force navigation links to always be displayed
199
    if (s.force_show_nav) {
200
      $('#prevLink, #nextLink').addClass("force_show_nav");
201
    }
202

    
203
  },
204

    
205
  // initList()
206
  // Loops through anchor tags looking for 'lightbox', 'lightshow' and
207
  // 'lightframe', etc, references and applies onclick events to appropriate
208
  // links. You can rerun after dynamically adding images w/ajax.
209
  initList : function(context) {
210

    
211
    if (context == undefined || context == null) {
212
      context = document;
213
    }
214

    
215
    // Attach lightbox to any links with rel 'lightbox', 'lightshow' or
216
    // 'lightframe', etc.
217
    $("a[rel^='lightbox']:not(.lightbox-processed), area[rel^='lightbox']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
218
      if (Lightbox.disableCloseClick) {
219
        $('#lightbox').unbind('click');
220
        $('#lightbox').click(function() { Lightbox.end('forceClose'); } );
221
      }
222
      Lightbox.start(this, false, false, false, false);
223
      if (e.preventDefault) { e.preventDefault(); }
224
      return false;
225
    });
226
    $("a[rel^='lightshow']:not(.lightbox-processed), area[rel^='lightshow']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
227
      if (Lightbox.disableCloseClick) {
228
        $('#lightbox').unbind('click');
229
        $('#lightbox').click(function() { Lightbox.end('forceClose'); } );
230
      }
231
      Lightbox.start(this, true, false, false, false);
232
      if (e.preventDefault) { e.preventDefault(); }
233
      return false;
234
    });
235
    $("a[rel^='lightframe']:not(.lightbox-processed), area[rel^='lightframe']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
236
      if (Lightbox.disableCloseClick) {
237
        $('#lightbox').unbind('click');
238
        $('#lightbox').click(function() { Lightbox.end('forceClose'); } );
239
      }
240
      Lightbox.start(this, false, true, false, false);
241
      if (e.preventDefault) { e.preventDefault(); }
242
      return false;
243
    });
244
    if (Lightbox.enableVideo) {
245
      $("a[rel^='lightvideo']:not(.lightbox-processed), area[rel^='lightvideo']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
246
        if (Lightbox.disableCloseClick) {
247
          $('#lightbox').unbind('click');
248
          $('#lightbox').click(function() { Lightbox.end('forceClose'); } );
249
        }
250
        Lightbox.start(this, false, false, true, false);
251
        if (e.preventDefault) { e.preventDefault(); }
252
        return false;
253
      });
254
    }
255
    $("a[rel^='lightmodal']:not(.lightbox-processed), area[rel^='lightmodal']:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
256
      $('#lightbox').unbind('click');
257
      // Add classes from the link to the lightbox div - don't include lightbox-processed
258
      $('#lightbox').addClass($(this).attr('class'));
259
      $('#lightbox').removeClass('lightbox-processed');
260
      Lightbox.start(this, false, false, false, true);
261
      if (e.preventDefault) { e.preventDefault(); }
262
      return false;
263
    });
264
    $("#lightboxAutoModal:not(.lightbox-processed)", context).addClass('lightbox-processed').click(function(e) {
265
      Lightbox.auto_modal = true;
266
      $('#lightbox').unbind('click');
267
      Lightbox.start(this, false, false, false, true);
268
      if (e.preventDefault) { e.preventDefault(); }
269
      return false;
270
    });
271
  },
272

    
273
  // start()
274
  // Display overlay and lightbox. If image is part of a set, add siblings to
275
  // imageArray.
276
  start: function(imageLink, slideshow, lightframe, lightvideo, lightmodal) {
277

    
278
    Lightbox.isPaused = !Lightbox.autoStart;
279

    
280
    // Replaces hideSelectBoxes() and hideFlash() calls in original lightbox2.
281
    Lightbox.toggleSelectsFlash('hide');
282

    
283
    // Stretch overlay to fill page and fade in.
284
    var arrayPageSize = Lightbox.getPageSize();
285
    $("#lightbox2-overlay").hide().css({
286
      'width': '100%',
287
      'zIndex': '10090',
288
      'height': arrayPageSize[1] + 'px',
289
      'backgroundColor' : '#' + Lightbox.overlayColor
290
    });
291
    // Detect OS X FF2 opacity + flash issue.
292
    if (lightvideo && this.detectMacFF2()) {
293
      $("#lightbox2-overlay").removeClass("overlay_default");
294
      $("#lightbox2-overlay").addClass("overlay_macff2");
295
      $("#lightbox2-overlay").css({'opacity' : null});
296
    }
297
    else {
298
      $("#lightbox2-overlay").removeClass("overlay_macff2");
299
      $("#lightbox2-overlay").addClass("overlay_default");
300
      $("#lightbox2-overlay").css({'opacity' : Lightbox.overlayOpacity});
301
    }
302
    $("#lightbox2-overlay").fadeIn(Lightbox.fadeInSpeed);
303

    
304

    
305
    Lightbox.isSlideshow = slideshow;
306
    Lightbox.isLightframe = lightframe;
307
    Lightbox.isVideo = lightvideo;
308
    Lightbox.isModal = lightmodal;
309
    Lightbox.imageArray = [];
310
    Lightbox.imageNum = 0;
311

    
312
    var anchors = $(imageLink.tagName);
313
    var anchor = null;
314
    var rel_parts = Lightbox.parseRel(imageLink);
315
    var rel = rel_parts["rel"];
316
    var rel_group = rel_parts["group"];
317
    var title = (rel_parts["title"] ? rel_parts["title"] : imageLink.title);
318
    var rel_style = null;
319
    var i = 0;
320

    
321
    if (rel_parts["flashvars"]) {
322
      Lightbox.flvFlashvars = Lightbox.flvFlashvars + '&' + rel_parts["flashvars"];
323
    }
324

    
325
    // Set the title for image alternative text.
326
    var alt = imageLink.title;
327
    if (!alt) {
328
      var img = $(imageLink).find("img");
329
      if (img && $(img).attr("alt")) {
330
        alt = $(img).attr("alt");
331
      }
332
      else {
333
        alt = title;
334
      }
335
    }
336

    
337
    if ($(imageLink).attr('id') == 'lightboxAutoModal') {
338
      rel_style = rel_parts["style"];
339
      Lightbox.imageArray.push(['#lightboxAutoModal > *', title, alt, rel_style, 1]);
340
    }
341
    else {
342
      // Handle lightbox images with no grouping.
343
      if ((rel == 'lightbox' || rel == 'lightshow') && !rel_group) {
344
        Lightbox.imageArray.push([imageLink.href, title, alt]);
345
      }
346

    
347
      // Handle other items with no grouping.
348
      else if (!rel_group) {
349
        rel_style = rel_parts["style"];
350
        Lightbox.imageArray.push([imageLink.href, title, alt, rel_style]);
351
      }
352

    
353
      // Handle grouped items.
354
      else {
355

    
356
        // Loop through anchors and add them to imageArray.
357
        for (i = 0; i < anchors.length; i++) {
358
          anchor = anchors[i];
359
          if (anchor.href && typeof(anchor.href) == "string" && $(anchor).attr('rel')) {
360
            var rel_data = Lightbox.parseRel(anchor);
361
            var anchor_title = (rel_data["title"] ? rel_data["title"] : anchor.title);
362
            img_alt = anchor.title;
363
            if (!img_alt) {
364
              var anchor_img = $(anchor).find("img");
365
              if (anchor_img && $(anchor_img).attr("alt")) {
366
                img_alt = $(anchor_img).attr("alt");
367
              }
368
              else {
369
                img_alt = title;
370
              }
371
            }
372
            if (rel_data["rel"] == rel) {
373
              if (rel_data["group"] == rel_group) {
374
                if (Lightbox.isLightframe || Lightbox.isModal || Lightbox.isVideo) {
375
                  rel_style = rel_data["style"];
376
                }
377
                Lightbox.imageArray.push([anchor.href, anchor_title, img_alt, rel_style]);
378
              }
379
            }
380
          }
381
        }
382

    
383
        // Remove duplicates.
384
        for (i = 0; i < Lightbox.imageArray.length; i++) {
385
          for (j = Lightbox.imageArray.length-1; j > i; j--) {
386
            if (Lightbox.imageArray[i][0] == Lightbox.imageArray[j][0]) {
387
              Lightbox.imageArray.splice(j,1);
388
            }
389
          }
390
        }
391
        while (Lightbox.imageArray[Lightbox.imageNum][0] != imageLink.href) {
392
          Lightbox.imageNum++;
393
        }
394
      }
395
    }
396

    
397
    if (Lightbox.isSlideshow && Lightbox.showPlayPause && Lightbox.isPaused) {
398
      $('#lightshowPlay').show();
399
      $('#lightshowPause').hide();
400
    }
401

    
402
    // Calculate top and left offset for the lightbox.
403
    var arrayPageScroll = Lightbox.getPageScroll();
404
    var lightboxTop = arrayPageScroll[1] + (Lightbox.topPosition == '' ? (arrayPageSize[3] / 10) : Lightbox.topPosition) * 1;
405
    var lightboxLeft = arrayPageScroll[0];
406
    $('#frameContainer, #modalContainer, #lightboxImage').hide();
407
    $('#hoverNav, #prevLink, #nextLink, #frameHoverNav, #framePrevLink, #frameNextLink').hide();
408
    $('#imageDataContainer, #numberDisplay, #bottomNavZoom, #bottomNavZoomOut').hide();
409
    $('#outerImageContainer').css({'width': '250px', 'height': '250px'});
410
    $('#lightbox').css({
411
      'zIndex': '10500',
412
      'top': lightboxTop + 'px',
413
      'left': lightboxLeft + 'px'
414
    }).show();
415

    
416
    Lightbox.total = Lightbox.imageArray.length;
417
    Lightbox.changeData(Lightbox.imageNum);
418
  },
419

    
420
  // changeData()
421
  // Hide most elements and preload image in preparation for resizing image
422
  // container.
423
  changeData: function(imageNum, zoomIn) {
424

    
425
    if (Lightbox.inprogress === false) {
426
      if (Lightbox.total > 1 && ((Lightbox.isSlideshow && Lightbox.loopSlides) || (!Lightbox.isSlideshow && Lightbox.loopItems))) {
427
        if (imageNum >= Lightbox.total) imageNum = 0;
428
        if (imageNum < 0) imageNum = Lightbox.total - 1;
429
      }
430

    
431
      if (Lightbox.isSlideshow) {
432
        for (var i = 0; i < Lightbox.slideIdCount; i++) {
433
          window.clearTimeout(Lightbox.slideIdArray[i]);
434
        }
435
      }
436
      Lightbox.inprogress = true;
437
      Lightbox.activeImage = imageNum;
438

    
439
      if (Lightbox.disableResize && !Lightbox.isSlideshow) {
440
        zoomIn = true;
441
      }
442
      Lightbox.isZoomedIn = zoomIn;
443

    
444

    
445
      // Hide elements during transition.
446
      $('#loading').css({'zIndex': '10500'}).show();
447
      if (!Lightbox.alternative_layout) {
448
        $('#imageContainer').hide();
449
      }
450
      $('#frameContainer, #modalContainer, #lightboxImage').hide();
451
      $('#hoverNav, #prevLink, #nextLink, #frameHoverNav, #framePrevLink, #frameNextLink').hide();
452
      $('#imageDataContainer, #numberDisplay, #bottomNavZoom, #bottomNavZoomOut').hide();
453

    
454
      // Preload image content, but not iframe pages.
455
      if (!Lightbox.isLightframe && !Lightbox.isVideo && !Lightbox.isModal) {
456
        $("#lightbox #imageDataContainer").removeClass('lightbox2-alt-layout-data');
457
        imgPreloader = new Image();
458
        imgPreloader.onerror = function() { Lightbox.imgNodeLoadingError(this); };
459

    
460
        imgPreloader.onload = function() {
461
          var photo = document.getElementById('lightboxImage');
462
          photo.src = Lightbox.imageArray[Lightbox.activeImage][0];
463
          photo.alt = Lightbox.imageArray[Lightbox.activeImage][2];
464

    
465
          var imageWidth = imgPreloader.width;
466
          var imageHeight = imgPreloader.height;
467

    
468
          // Resize code.
469
          var arrayPageSize = Lightbox.getPageSize();
470
          var targ = { w:arrayPageSize[2] - (Lightbox.borderSize * 2), h:arrayPageSize[3] - (Lightbox.borderSize * 6) - (Lightbox.infoHeight * 4) - (arrayPageSize[3] / 10) };
471
          var orig = { w:imgPreloader.width, h:imgPreloader.height };
472

    
473
          // Image is very large, so show a smaller version of the larger image
474
          // with zoom button.
475
          if (zoomIn !== true) {
476
            var ratio = 1.0; // Shrink image with the same aspect.
477
            $('#bottomNavZoomOut, #bottomNavZoom').hide();
478
            if ((orig.w >= targ.w || orig.h >= targ.h) && orig.h && orig.w) {
479
              ratio = ((targ.w / orig.w) < (targ.h / orig.h)) ? targ.w / orig.w : targ.h / orig.h;
480
              if (!Lightbox.disableZoom && !Lightbox.isSlideshow) {
481
                $('#bottomNavZoom').css({'zIndex': '10500'}).show();
482
              }
483
            }
484

    
485
            imageWidth  = Math.floor(orig.w * ratio);
486
            imageHeight = Math.floor(orig.h * ratio);
487
          }
488

    
489
          else {
490
            $('#bottomNavZoom').hide();
491
            // Only display zoom out button if the image is zoomed in already.
492
            if ((orig.w >= targ.w || orig.h >= targ.h) && orig.h && orig.w) {
493
              // Only display zoom out button if not a slideshow and if the
494
              // buttons aren't disabled.
495
              if (!Lightbox.disableResize && Lightbox.isSlideshow === false && !Lightbox.disableZoom) {
496
                $('#bottomNavZoomOut').css({'zIndex': '10500'}).show();
497
              }
498
            }
499
          }
500

    
501
          photo.style.width = (imageWidth) + 'px';
502
          photo.style.height = (imageHeight) + 'px';
503
          Lightbox.resizeContainer(imageWidth, imageHeight);
504

    
505
          // Clear onLoad, IE behaves irratically with animated gifs otherwise.
506
          imgPreloader.onload = function() {};
507
        };
508

    
509
        imgPreloader.src = Lightbox.imageArray[Lightbox.activeImage][0];
510
        imgPreloader.alt = Lightbox.imageArray[Lightbox.activeImage][2];
511
      }
512

    
513
      // Set up frame size, etc.
514
      else if (Lightbox.isLightframe) {
515
        $("#lightbox #imageDataContainer").addClass('lightbox2-alt-layout-data');
516
        var src = Lightbox.imageArray[Lightbox.activeImage][0];
517
        $('#frameContainer').html('<iframe id="lightboxFrame" style="display: none;" src="'+src+'"></iframe>');
518

    
519
        // Enable swf support in Gecko browsers.
520
        if ($.browser.mozilla && src.indexOf('.swf') != -1) {
521
          setTimeout(function () {
522
            document.getElementById("lightboxFrame").src = Lightbox.imageArray[Lightbox.activeImage][0];
523
          }, 1000);
524
        }
525

    
526
        if (!Lightbox.iframe_border) {
527
          $('#lightboxFrame').css({'border': 'none'});
528
          $('#lightboxFrame').attr('frameborder', '0');
529
        }
530
        var iframe = document.getElementById('lightboxFrame');
531
        var iframeStyles = Lightbox.imageArray[Lightbox.activeImage][3];
532
        iframe = Lightbox.setStyles(iframe, iframeStyles);
533
        Lightbox.resizeContainer(parseInt(iframe.width, 10), parseInt(iframe.height, 10));
534
      }
535
      else if (Lightbox.isVideo || Lightbox.isModal) {
536
        $("#lightbox #imageDataContainer").addClass('lightbox2-alt-layout-data');
537
        var container = document.getElementById('modalContainer');
538
        var modalStyles = Lightbox.imageArray[Lightbox.activeImage][3];
539
        container = Lightbox.setStyles(container, modalStyles);
540
        if (Lightbox.isVideo) {
541
          Lightbox.modalHeight =  parseInt(container.height, 10) - 10;
542
          Lightbox.modalWidth =  parseInt(container.width, 10) - 10;
543
          Lightvideo.startVideo(Lightbox.imageArray[Lightbox.activeImage][0]);
544
        }
545
        Lightbox.resizeContainer(parseInt(container.width, 10), parseInt(container.height, 10));
546
      }
547
    }
548
  },
549

    
550
  // imgNodeLoadingError()
551
  imgNodeLoadingError: function(image) {
552
    var s = Drupal.settings.lightbox2;
553
    var original_image = Lightbox.imageArray[Lightbox.activeImage][0];
554
    if (s.display_image_size !== "") {
555
      original_image = original_image.replace(new RegExp("."+s.display_image_size), "");
556
    }
557
    Lightbox.imageArray[Lightbox.activeImage][0] = original_image;
558
    image.onerror = function() { Lightbox.imgLoadingError(image); };
559
    image.src = original_image;
560
  },
561

    
562
  // imgLoadingError()
563
  imgLoadingError: function(image) {
564
    var s = Drupal.settings.lightbox2;
565
    Lightbox.imageArray[Lightbox.activeImage][0] = s.default_image;
566
    image.src = s.default_image;
567
  },
568

    
569
  // resizeContainer()
570
  resizeContainer: function(imgWidth, imgHeight) {
571

    
572
    imgWidth = (imgWidth < Lightbox.minWidth ? Lightbox.minWidth : imgWidth);
573

    
574
    this.widthCurrent = $('#outerImageContainer').width();
575
    this.heightCurrent = $('#outerImageContainer').height();
576

    
577
    var widthNew = (imgWidth  + (Lightbox.borderSize * 2));
578
    var heightNew = (imgHeight  + (Lightbox.borderSize * 2));
579

    
580
    // Scalars based on change from old to new.
581
    this.xScale = ( widthNew / this.widthCurrent) * 100;
582
    this.yScale = ( heightNew / this.heightCurrent) * 100;
583

    
584
    // Calculate size difference between new and old image, and resize if
585
    // necessary.
586
    wDiff = this.widthCurrent - widthNew;
587
    hDiff = this.heightCurrent - heightNew;
588

    
589
    $('#modalContainer').css({'width': imgWidth, 'height': imgHeight});
590
    // Detect animation sequence.
591
    if (Lightbox.resizeSequence) {
592
      var animate1 = {width: widthNew};
593
      var animate2 = {height: heightNew};
594
      if (Lightbox.resizeSequence == 2) {
595
        animate1 = {height: heightNew};
596
        animate2 = {width: widthNew};
597
      }
598
      $('#outerImageContainer').animate(animate1, Lightbox.resizeSpeed).animate(animate2, Lightbox.resizeSpeed, 'linear', function() { Lightbox.showData(); });
599
    }
600
    // Simultaneous.
601
    else {
602
      $('#outerImageContainer').animate({'width': widthNew, 'height': heightNew}, Lightbox.resizeSpeed, 'linear', function() { Lightbox.showData(); });
603
    }
604

    
605
    // If new and old image are same size and no scaling transition is necessary
606
    // do a quick pause to prevent image flicker.
607
    if ((hDiff === 0) && (wDiff === 0)) {
608
      if ($.browser.msie) {
609
        Lightbox.pause(250);
610
      }
611
      else {
612
        Lightbox.pause(100);
613
      }
614
    }
615

    
616
    var s = Drupal.settings.lightbox2;
617
    if (!s.use_alt_layout) {
618
      $('#prevLink, #nextLink').css({'height': imgHeight + 'px'});
619
    }
620
    $('#imageDataContainer').css({'width': widthNew + 'px'});
621
  },
622

    
623
  // showData()
624
  // Display image and begin preloading neighbors.
625
  showData: function() {
626
    $('#loading').hide();
627

    
628
    if (Lightbox.isLightframe || Lightbox.isVideo || Lightbox.isModal) {
629
      Lightbox.updateDetails();
630
      if (Lightbox.isLightframe) {
631
        $('#frameContainer').show();
632
        if ($.browser.safari || Lightbox.fadeInSpeed === 0) {
633
          $('#lightboxFrame').css({'zIndex': '10500'}).show();
634
        }
635
        else {
636
          $('#lightboxFrame').css({'zIndex': '10500'}).fadeIn(Lightbox.fadeInSpeed);
637
        }
638
      }
639
      else {
640
        if (Lightbox.isVideo) {
641
          $("#modalContainer").html(Lightbox.modalHTML).click(function(){return false;}).css('zIndex', '10500').show();
642
        }
643
        else {
644
          var src = unescape(Lightbox.imageArray[Lightbox.activeImage][0]);
645
          if (Lightbox.imageArray[Lightbox.activeImage][4]) {
646
            $(src).appendTo("#modalContainer");
647
            $('#modalContainer').css({'zIndex': '10500'}).show();
648
          }
649
          else {
650
            // Use a callback to show the new image, otherwise you get flicker.
651
            $("#modalContainer").hide().load(src, function () {$('#modalContainer').css({'zIndex': '10500'}).show();});
652
          }
653
          $('#modalContainer').unbind('click');
654
        }
655
        // This might be needed in the Lightframe section above.
656
        //$('#modalContainer').css({'zIndex': '10500'}).show();
657
      }
658
    }
659

    
660
    // Handle display of image content.
661
    else {
662
      $('#imageContainer').show();
663
      if ($.browser.safari || Lightbox.fadeInSpeed === 0) {
664
        $('#lightboxImage').css({'zIndex': '10500'}).show();
665
      }
666
      else {
667
        $('#lightboxImage').css({'zIndex': '10500'}).fadeIn(Lightbox.fadeInSpeed);
668
      }
669
      Lightbox.updateDetails();
670
      this.preloadNeighborImages();
671
    }
672
    Lightbox.inprogress = false;
673

    
674
    // Slideshow specific stuff.
675
    if (Lightbox.isSlideshow) {
676
      if (!Lightbox.loopSlides && Lightbox.activeImage == (Lightbox.total - 1)) {
677
        if (Lightbox.autoExit) {
678
          Lightbox.slideIdArray[Lightbox.slideIdCount++] = setTimeout(function () {Lightbox.end('slideshow');}, Lightbox.slideInterval);
679
        }
680
      }
681
      else {
682
        if (!Lightbox.isPaused && Lightbox.total > 1) {
683
          Lightbox.slideIdArray[Lightbox.slideIdCount++] = setTimeout(function () {Lightbox.changeData(Lightbox.activeImage + 1);}, Lightbox.slideInterval);
684
        }
685
      }
686
      if (Lightbox.showPlayPause && Lightbox.total > 1 && !Lightbox.isPaused) {
687
        $('#lightshowPause').show();
688
        $('#lightshowPlay').hide();
689
      }
690
      else if (Lightbox.showPlayPause && Lightbox.total > 1) {
691
        $('#lightshowPause').hide();
692
        $('#lightshowPlay').show();
693
      }
694
    }
695

    
696
    // Adjust the page overlay size.
697
    var arrayPageSize = Lightbox.getPageSize();
698
    var arrayPageScroll = Lightbox.getPageScroll();
699
    var pageHeight = arrayPageSize[1];
700
    if (Lightbox.isZoomedIn && arrayPageSize[1] > arrayPageSize[3]) {
701
      var lightboxTop = (Lightbox.topPosition == '' ? (arrayPageSize[3] / 10) : Lightbox.topPosition) * 1;
702
      pageHeight = pageHeight + arrayPageScroll[1] + lightboxTop;
703
    }
704
    $('#lightbox2-overlay').css({'height': pageHeight + 'px', 'width': arrayPageSize[0] + 'px'});
705

    
706
    // Gecko browsers (e.g. Firefox, SeaMonkey, etc) don't handle pdfs as
707
    // expected.
708
    if ($.browser.mozilla) {
709
      if (Lightbox.imageArray[Lightbox.activeImage][0].indexOf(".pdf") != -1) {
710
        setTimeout(function () {
711
          document.getElementById("lightboxFrame").src = Lightbox.imageArray[Lightbox.activeImage][0];
712
        }, 1000);
713
      }
714
    }
715
  },
716

    
717
  // updateDetails()
718
  // Display caption, image number, and bottom nav.
719
  updateDetails: function() {
720

    
721
    $("#imageDataContainer").hide();
722

    
723
    var s = Drupal.settings.lightbox2;
724

    
725
    if (s.show_caption) {
726
      var caption = Lightbox.filterXSS(Lightbox.imageArray[Lightbox.activeImage][1]);
727
      if (!caption) caption = '';
728
      $('#caption').html(caption).css({'zIndex': '10500'}).show();
729
    }
730

    
731
    // If image is part of set display 'Image x of x'.
732
    var numberDisplay = null;
733
    if (s.image_count && Lightbox.total > 1) {
734
      var currentImage = Lightbox.activeImage + 1;
735
      if (!Lightbox.isLightframe && !Lightbox.isModal && !Lightbox.isVideo) {
736
        numberDisplay = s.image_count.replace(/\!current/, currentImage).replace(/\!total/, Lightbox.total);
737
      }
738
      else if (Lightbox.isVideo) {
739
        numberDisplay = s.video_count.replace(/\!current/, currentImage).replace(/\!total/, Lightbox.total);
740
      }
741
      else {
742
        numberDisplay = s.page_count.replace(/\!current/, currentImage).replace(/\!total/, Lightbox.total);
743
      }
744
      $('#numberDisplay').html(numberDisplay).css({'zIndex': '10500'}).show();
745
    }
746
    else {
747
      $('#numberDisplay').hide();
748
    }
749

    
750
    $("#imageDataContainer").hide().slideDown(Lightbox.slideDownSpeed, function() {
751
      $("#bottomNav").show();
752
    });
753
    if (Lightbox.rtl == 1) {
754
      $("#bottomNav").css({'float': 'left'});
755
    }
756
    Lightbox.updateNav();
757
  },
758

    
759
  // updateNav()
760
  // Display appropriate previous and next hover navigation.
761
  updateNav: function() {
762

    
763
    $('#hoverNav').css({'zIndex': '10500'}).show();
764
    var prevLink = '#prevLink';
765
    var nextLink = '#nextLink';
766

    
767
    // Slideshow is separated as we need to show play / pause button.
768
    if (Lightbox.isSlideshow) {
769
      if ((Lightbox.total > 1 && Lightbox.loopSlides) || Lightbox.activeImage !== 0) {
770
        $(prevLink).css({'zIndex': '10500'}).show().click(function() {
771
          if (Lightbox.pauseOnPrevClick) {
772
            Lightbox.togglePlayPause("lightshowPause", "lightshowPlay");
773
          }
774
          Lightbox.changeData(Lightbox.activeImage - 1); return false;
775
        });
776
      }
777
      else {
778
        $(prevLink).hide();
779
      }
780

    
781
      // If not last image in set, display next image button.
782
      if ((Lightbox.total > 1 && Lightbox.loopSlides) || Lightbox.activeImage != (Lightbox.total - 1)) {
783
        $(nextLink).css({'zIndex': '10500'}).show().click(function() {
784
          if (Lightbox.pauseOnNextClick) {
785
            Lightbox.togglePlayPause("lightshowPause", "lightshowPlay");
786
          }
787
          Lightbox.changeData(Lightbox.activeImage + 1); return false;
788
        });
789
      }
790
      // Safari browsers need to have hide() called again.
791
      else {
792
        $(nextLink).hide();
793
      }
794
    }
795

    
796
    // All other types of content.
797
    else {
798

    
799
      if ((Lightbox.isLightframe || Lightbox.isModal || Lightbox.isVideo) && !Lightbox.alternative_layout) {
800
        $('#frameHoverNav').css({'zIndex': '10500'}).show();
801
        $('#hoverNav').css({'zIndex': '10500'}).hide();
802
        prevLink = '#framePrevLink';
803
        nextLink = '#frameNextLink';
804
      }
805

    
806
      // If not first image in set, display prev image button.
807
      if ((Lightbox.total > 1 && Lightbox.loopItems) || Lightbox.activeImage !== 0) {
808
        // Unbind any other click handlers, otherwise this adds a new click handler
809
        // each time the arrow is clicked.
810
        $(prevLink).css({'zIndex': '10500'}).show().unbind().click(function() {
811
          Lightbox.changeData(Lightbox.activeImage - 1); return false;
812
        });
813
      }
814
      // Safari browsers need to have hide() called again.
815
      else {
816
        $(prevLink).hide();
817
      }
818

    
819
      // If not last image in set, display next image button.
820
      if ((Lightbox.total > 1 && Lightbox.loopItems) || Lightbox.activeImage != (Lightbox.total - 1)) {
821
        // Unbind any other click handlers, otherwise this adds a new click handler
822
        // each time the arrow is clicked.
823
        $(nextLink).css({'zIndex': '10500'}).show().unbind().click(function() {
824
          Lightbox.changeData(Lightbox.activeImage + 1); return false;
825
        });
826
      }
827
      // Safari browsers need to have hide() called again.
828
      else {
829
        $(nextLink).hide();
830
      }
831
    }
832

    
833
    // Don't enable keyboard shortcuts so forms will work.
834
    if (!Lightbox.isModal) {
835
      this.enableKeyboardNav();
836
    }
837
  },
838

    
839

    
840
  // enableKeyboardNav()
841
  enableKeyboardNav: function() {
842
    $(document).bind("keydown", this.keyboardAction);
843
  },
844

    
845
  // disableKeyboardNav()
846
  disableKeyboardNav: function() {
847
    $(document).unbind("keydown", this.keyboardAction);
848
  },
849

    
850
  // keyboardAction()
851
  keyboardAction: function(e) {
852
    if (e === null) { // IE.
853
      keycode = event.keyCode;
854
      escapeKey = 27;
855
    }
856
    else { // Mozilla.
857
      keycode = e.keyCode;
858
      escapeKey = e.DOM_VK_ESCAPE;
859
    }
860

    
861
    key = String.fromCharCode(keycode).toLowerCase();
862

    
863
    // Close lightbox.
864
    if (Lightbox.checkKey(Lightbox.keysClose, key, keycode)) {
865
      Lightbox.end('forceClose');
866
    }
867
    // Display previous image (p, <-).
868
    else if (Lightbox.checkKey(Lightbox.keysPrevious, key, keycode)) {
869
      if ((Lightbox.total > 1 && ((Lightbox.isSlideshow && Lightbox.loopSlides) || (!Lightbox.isSlideshow && Lightbox.loopItems))) || Lightbox.activeImage !== 0) {
870
        Lightbox.changeData(Lightbox.activeImage - 1);
871
      }
872

    
873
    }
874
    // Display next image (n, ->).
875
    else if (Lightbox.checkKey(Lightbox.keysNext, key, keycode)) {
876
      if ((Lightbox.total > 1 && ((Lightbox.isSlideshow && Lightbox.loopSlides) || (!Lightbox.isSlideshow && Lightbox.loopItems))) || Lightbox.activeImage != (Lightbox.total - 1)) {
877
        Lightbox.changeData(Lightbox.activeImage + 1);
878
      }
879
    }
880
    // Zoom in.
881
    else if (Lightbox.checkKey(Lightbox.keysZoom, key, keycode) && !Lightbox.disableResize && !Lightbox.disableZoom && !Lightbox.isSlideshow && !Lightbox.isLightframe) {
882
      if (Lightbox.isZoomedIn) {
883
        Lightbox.changeData(Lightbox.activeImage, false);
884
      }
885
      else if (!Lightbox.isZoomedIn) {
886
        Lightbox.changeData(Lightbox.activeImage, true);
887
      }
888
      return false;
889
    }
890
    // Toggle play / pause (space).
891
    else if (Lightbox.checkKey(Lightbox.keysPlayPause, key, keycode) && Lightbox.isSlideshow) {
892

    
893
      if (Lightbox.isPaused) {
894
        Lightbox.togglePlayPause("lightshowPlay", "lightshowPause");
895
      }
896
      else {
897
        Lightbox.togglePlayPause("lightshowPause", "lightshowPlay");
898
      }
899
      return false;
900
    }
901
  },
902

    
903
  preloadNeighborImages: function() {
904

    
905
    if ((Lightbox.total - 1) > Lightbox.activeImage) {
906
      preloadNextImage = new Image();
907
      preloadNextImage.src = Lightbox.imageArray[Lightbox.activeImage + 1][0];
908
    }
909
    if (Lightbox.activeImage > 0) {
910
      preloadPrevImage = new Image();
911
      preloadPrevImage.src = Lightbox.imageArray[Lightbox.activeImage - 1][0];
912
    }
913

    
914
  },
915

    
916
  end: function(caller) {
917
    var closeClick = (caller == 'slideshow' ? false : true);
918
    if (Lightbox.isSlideshow && Lightbox.isPaused && !closeClick) {
919
      return;
920
    }
921
    // To prevent double clicks on navigation links.
922
    if (Lightbox.inprogress === true && caller != 'forceClose') {
923
      return;
924
    }
925
    Lightbox.disableKeyboardNav();
926
    $('#lightbox').hide();
927
    $("#lightbox2-overlay").fadeOut();
928
    Lightbox.isPaused = true;
929
    Lightbox.inprogress = false;
930
    // Replaces calls to showSelectBoxes() and showFlash() in original
931
    // lightbox2.
932
    Lightbox.toggleSelectsFlash('visible');
933
    if (Lightbox.isSlideshow) {
934
      for (var i = 0; i < Lightbox.slideIdCount; i++) {
935
        window.clearTimeout(Lightbox.slideIdArray[i]);
936
      }
937
      $('#lightshowPause, #lightshowPlay').hide();
938
    }
939
    else if (Lightbox.isLightframe) {
940
      $('#frameContainer').empty().hide();
941
    }
942
    else if (Lightbox.isVideo || Lightbox.isModal) {
943
      if (!Lightbox.auto_modal) {
944
        $('#modalContainer').hide().html("");
945
      }
946
      Lightbox.auto_modal = false;
947
    }
948
  },
949

    
950

    
951
  // getPageScroll()
952
  // Returns array with x,y page scroll values.
953
  // Core code from - quirksmode.com.
954
  getPageScroll : function() {
955

    
956
    var xScroll, yScroll;
957

    
958
    if (self.pageYOffset || self.pageXOffset) {
959
      yScroll = self.pageYOffset;
960
      xScroll = self.pageXOffset;
961
    }
962
    else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {  // Explorer 6 Strict.
963
      yScroll = document.documentElement.scrollTop;
964
      xScroll = document.documentElement.scrollLeft;
965
    }
966
    else if (document.body) {// All other Explorers.
967
      yScroll = document.body.scrollTop;
968
      xScroll = document.body.scrollLeft;
969
    }
970

    
971
    arrayPageScroll = [xScroll,yScroll];
972
    return arrayPageScroll;
973
  },
974

    
975
  // getPageSize()
976
  // Returns array with page width, height and window width, height.
977
  // Core code from - quirksmode.com.
978
  // Edit for Firefox by pHaez.
979

    
980
  getPageSize : function() {
981

    
982
    var xScroll, yScroll;
983

    
984
    if (window.innerHeight && window.scrollMaxY) {
985
      xScroll = window.innerWidth + window.scrollMaxX;
986
      yScroll = window.innerHeight + window.scrollMaxY;
987
    }
988
    else if (document.body.scrollHeight > document.body.offsetHeight) { // All but Explorer Mac.
989
      xScroll = document.body.scrollWidth;
990
      yScroll = document.body.scrollHeight;
991
    }
992
    else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari.
993
      xScroll = document.body.offsetWidth;
994
      yScroll = document.body.offsetHeight;
995
    }
996

    
997
    var windowWidth, windowHeight;
998

    
999
    if (self.innerHeight) { // All except Explorer.
1000
      if (document.documentElement.clientWidth) {
1001
        windowWidth = document.documentElement.clientWidth;
1002
      }
1003
      else {
1004
        windowWidth = self.innerWidth;
1005
      }
1006
      windowHeight = self.innerHeight;
1007
    }
1008
    else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode.
1009
      windowWidth = document.documentElement.clientWidth;
1010
      windowHeight = document.documentElement.clientHeight;
1011
    }
1012
    else if (document.body) { // Other Explorers.
1013
      windowWidth = document.body.clientWidth;
1014
      windowHeight = document.body.clientHeight;
1015
    }
1016
    // For small pages with total height less than height of the viewport.
1017
    if (yScroll < windowHeight) {
1018
      pageHeight = windowHeight;
1019
    }
1020
    else {
1021
      pageHeight = yScroll;
1022
    }
1023
    // For small pages with total width less than width of the viewport.
1024
    if (xScroll < windowWidth) {
1025
      pageWidth = xScroll;
1026
    }
1027
    else {
1028
      pageWidth = windowWidth;
1029
    }
1030
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
1031
    return arrayPageSize;
1032
  },
1033

    
1034

    
1035
  // pause(numberMillis)
1036
  pause : function(ms) {
1037
    var date = new Date();
1038
    var curDate = null;
1039
    do { curDate = new Date(); }
1040
    while (curDate - date < ms);
1041
  },
1042

    
1043

    
1044
  // toggleSelectsFlash()
1045
  // Hide / unhide select lists and flash objects as they appear above the
1046
  // lightbox in some browsers.
1047
  toggleSelectsFlash: function (state) {
1048
    if (state == 'visible') {
1049
      $("select.lightbox_hidden, embed.lightbox_hidden, object.lightbox_hidden").show();
1050
    }
1051
    else if (state == 'hide') {
1052
      $("select:visible, embed:visible, object:visible").not('#lightboxAutoModal select, #lightboxAutoModal embed, #lightboxAutoModal object').addClass("lightbox_hidden");
1053
      $("select.lightbox_hidden, embed.lightbox_hidden, object.lightbox_hidden").hide();
1054
    }
1055
  },
1056

    
1057

    
1058
  // parseRel()
1059
  parseRel: function (link) {
1060
    var parts = [];
1061
    parts["rel"] = parts["title"] = parts["group"] = parts["style"] = parts["flashvars"] = null;
1062
    if (!$(link).attr('rel')) return parts;
1063
    parts["rel"] = $(link).attr('rel').match(/\w+/)[0];
1064

    
1065
    if ($(link).attr('rel').match(/\[(.*)\]/)) {
1066
      var info = $(link).attr('rel').match(/\[(.*?)\]/)[1].split('|');
1067
      parts["group"] = info[0];
1068
      parts["style"] = info[1];
1069
      if (parts["style"] != undefined && parts["style"].match(/flashvars:\s?(.*?);/)) {
1070
        parts["flashvars"] = parts["style"].match(/flashvars:\s?(.*?);/)[1];
1071
      }
1072
    }
1073
    if ($(link).attr('rel').match(/\[.*\]\[(.*)\]/)) {
1074
      parts["title"] = $(link).attr('rel').match(/\[.*\]\[(.*)\]/)[1];
1075
    }
1076
    return parts;
1077
  },
1078

    
1079
  // setStyles()
1080
  setStyles: function(item, styles) {
1081
    item.width = Lightbox.iframe_width;
1082
    item.height = Lightbox.iframe_height;
1083
    item.scrolling = "auto";
1084

    
1085
    if (!styles) return item;
1086
    var stylesArray = styles.split(';');
1087
    for (var i = 0; i< stylesArray.length; i++) {
1088
      if (stylesArray[i].indexOf('width:') >= 0) {
1089
        var w = stylesArray[i].replace('width:', '');
1090
        item.width = jQuery.trim(w);
1091
      }
1092
      else if (stylesArray[i].indexOf('height:') >= 0) {
1093
        var h = stylesArray[i].replace('height:', '');
1094
        item.height = jQuery.trim(h);
1095
      }
1096
      else if (stylesArray[i].indexOf('scrolling:') >= 0) {
1097
        var scrolling = stylesArray[i].replace('scrolling:', '');
1098
        item.scrolling = jQuery.trim(scrolling);
1099
      }
1100
      else if (stylesArray[i].indexOf('overflow:') >= 0) {
1101
        var overflow = stylesArray[i].replace('overflow:', '');
1102
        item.overflow = jQuery.trim(overflow);
1103
      }
1104
    }
1105
    return item;
1106
  },
1107

    
1108

    
1109
  // togglePlayPause()
1110
  // Hide the pause / play button as appropriate.  If pausing the slideshow also
1111
  // clear the timers, otherwise move onto the next image.
1112
  togglePlayPause: function(hideId, showId) {
1113
    if (Lightbox.isSlideshow && hideId == "lightshowPause") {
1114
      for (var i = 0; i < Lightbox.slideIdCount; i++) {
1115
        window.clearTimeout(Lightbox.slideIdArray[i]);
1116
      }
1117
    }
1118
    $('#' + hideId).hide();
1119
    $('#' + showId).show();
1120

    
1121
    if (hideId == "lightshowPlay") {
1122
      Lightbox.isPaused = false;
1123
      if (!Lightbox.loopSlides && Lightbox.activeImage == (Lightbox.total - 1)) {
1124
        Lightbox.end();
1125
      }
1126
      else if (Lightbox.total > 1) {
1127
        Lightbox.changeData(Lightbox.activeImage + 1);
1128
      }
1129
    }
1130
    else {
1131
      Lightbox.isPaused = true;
1132
    }
1133
  },
1134

    
1135
  triggerLightbox: function (rel_type, rel_group) {
1136
    if (rel_type.length) {
1137
      if (rel_group && rel_group.length) {
1138
        $("a[rel^='" + rel_type +"\[" + rel_group + "\]'], area[rel^='" + rel_type +"\[" + rel_group + "\]']").eq(0).trigger("click");
1139
      }
1140
      else {
1141
        $("a[rel^='" + rel_type +"'], area[rel^='" + rel_type +"']").eq(0).trigger("click");
1142
      }
1143
    }
1144
  },
1145

    
1146
  detectMacFF2: function() {
1147
    var ua = navigator.userAgent.toLowerCase();
1148
    if (/firefox[\/\s](\d+\.\d+)/.test(ua)) {
1149
      var ffversion = new Number(RegExp.$1);
1150
      if (ffversion < 3 && ua.indexOf('mac') != -1) {
1151
        return true;
1152
      }
1153
    }
1154
    return false;
1155
  },
1156

    
1157
  checkKey: function(keys, key, code) {
1158
    return (jQuery.inArray(key, keys) != -1 || jQuery.inArray(String(code), keys) != -1);
1159
  },
1160

    
1161
  filterXSS: function(str, allowed_tags) {
1162
    var output = "";
1163
    $.ajax({
1164
      url: Drupal.settings.basePath + 'system/lightbox2/filter-xss',
1165
      data: {
1166
        'string' : str,
1167
        'allowed_tags' : allowed_tags
1168
      },
1169
      type: "POST",
1170
      async: false,
1171
      dataType:  "json",
1172
      success: function(data) {
1173
        output = data;
1174
      }
1175
    });
1176
    return output;
1177
  }
1178

    
1179
};
1180

    
1181
// Initialize the lightbox.
1182
Drupal.behaviors.initLightbox = {
1183
  attach: function(context) {
1184

    
1185
  $('body:not(.lightbox-processed)', context).addClass('lightbox-processed').each(function() {
1186
    Lightbox.initialize();
1187
    return false; // Break the each loop.
1188
  });
1189

    
1190
  // Attach lightbox to any links with lightbox rels.
1191
  Lightbox.initList(context);
1192
  $('#lightboxAutoModal', context).triggerHandler('click');
1193
  }
1194
};
1195
})(jQuery);