Projet

Général

Profil

Paste
Télécharger (27,6 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_slideshow / contrib / views_slideshow_cycle / js / views_slideshow_cycle.js @ 7547bb19

1
/**
2
 *  @file
3
 *  A simple jQuery Cycle Div Slideshow Rotator.
4
 */
5

    
6
/**
7
 * This will set our initial behavior, by starting up each individual slideshow.
8
 */
9
(function ($) {
10
  Drupal.behaviors.viewsSlideshowCycle = {
11
    attach: function (context) {
12
      $('.views_slideshow_cycle_main:not(.viewsSlideshowCycle-processed)', context).addClass('viewsSlideshowCycle-processed').each(function() {
13
        var fullId = '#' + $(this).attr('id');
14
        var settings = Drupal.settings.viewsSlideshowCycle[fullId];
15
        settings.targetId = '#' + $(fullId + " :first").attr('id');
16

    
17
        settings.slideshowId = settings.targetId.replace('#views_slideshow_cycle_teaser_section_', '');
18
        // Pager after function.
19
        var pager_after_fn = function(curr, next, opts) {
20
          // Need to do some special handling on first load.
21
          var slideNum = opts.currSlide;
22
          if (typeof settings.processedAfter == 'undefined' || !settings.processedAfter) {
23
            settings.processedAfter = 1;
24
            slideNum = (typeof settings.opts.startingSlide == 'undefined') ? 0 : settings.opts.startingSlide;
25
          }
26
          if (settings.pause_after_slideshow) {
27
            opts.counter += 1;
28
            if (opts.counter == settings.num_divs + 1) {
29
              opts.counter = 1;
30
              Drupal.viewsSlideshow.action({ "action": 'pause', "slideshowID": settings.slideshowId, "force": true });
31
            }
32
          }
33
          Drupal.viewsSlideshow.action({ "action": 'transitionEnd', "slideshowID": settings.slideshowId, "slideNum": slideNum });
34
        }
35
        // Pager before function.
36
        var pager_before_fn = function(curr, next, opts) {
37
          $(document).trigger('drupal:views_slideshow_cycle:before', {
38
            curr: curr, next: next, opts: opts, settings: settings
39
          });
40

    
41
          var slideNum = opts.nextSlide;
42

    
43
          // Remember last slide.
44
          if (settings.remember_slide) {
45
            createCookie(settings.vss_id, slideNum, settings.remember_slide_days);
46
          }
47

    
48
          // Make variable height.
49
          if (!settings.fixed_height) {
50
            //get the height of the current slide
51
            var $ht = $(next).height();
52
            //set the container's height to that of the current slide
53
            $(next).parent().animate({height: $ht});
54
          }
55

    
56
          // Need to do some special handling on first load.
57
          if (typeof settings.processedBefore == 'undefined' || !settings.processedBefore) {
58
            settings.processedBefore = 1;
59
            slideNum = (typeof opts.startingSlide == 'undefined') ? 0 : opts.startingSlide;
60
          }
61

    
62
          Drupal.viewsSlideshow.action({ "action": 'transitionBegin', "slideshowID": settings.slideshowId, "slideNum": slideNum });
63
        }
64
        settings.loaded = false;
65

    
66
        settings.opts = {
67
          speed:settings.speed,
68
          timeout:settings.timeout,
69
          delay:settings.delay,
70
          sync:settings.sync,
71
          random:settings.random,
72
          nowrap:settings.nowrap,
73
          pause_after_slideshow:settings.pause_after_slideshow,
74
          counter:0,
75
          after:pager_after_fn,
76
          before:pager_before_fn,
77
          cleartype:(settings.cleartype)? true : false,
78
          cleartypeNoBg:(settings.cleartypenobg)? true : false
79
        }
80

    
81
        // Set the starting slide if we are supposed to remember the slide
82
        if (settings.remember_slide) {
83
          var startSlide = readCookie(settings.vss_id);
84
          if (startSlide == null) {
85
            startSlide = 0;
86
          }
87
          settings.opts.startingSlide = parseInt(startSlide);
88
        }
89

    
90
        if (settings.effect == 'none') {
91
          settings.opts.speed = 1;
92
        }
93
        else {
94
          settings.opts.fx = settings.effect;
95
        }
96

    
97
        // Take starting item from fragment.
98
        var hash = location.hash;
99
        if (hash) {
100
          var hash = hash.replace('#', '');
101
          var aHash = hash.split(';');
102
          var aHashLen = aHash.length;
103

    
104
          // Loop through all the possible starting points.
105
          for (var i = 0; i < aHashLen; i++) {
106
            // Split the hash into two parts. One part is the slideshow id the
107
            // other is the slide number.
108
            var initialInfo = aHash[i].split(':');
109
            // The id in the hash should match our slideshow.
110
            // The slide number chosen shouldn't be larger than the number of
111
            // slides we have.
112
            if (settings.slideshowId == initialInfo[0] && settings.num_divs > initialInfo[1]) {
113
              settings.opts.startingSlide = parseInt(initialInfo[1]);
114
            }
115
          }
116
        }
117

    
118
        // Pause on hover.
119
        if (settings.pause) {
120
          var mouseIn = function() {
121
            Drupal.viewsSlideshow.action({ "action": 'pause', "slideshowID": settings.slideshowId });
122
          }
123

    
124
          var mouseOut = function() {
125
            Drupal.viewsSlideshow.action({ "action": 'play', "slideshowID": settings.slideshowId });
126
          }
127

    
128
          if (jQuery.fn.hoverIntent) {
129
            $('#views_slideshow_cycle_teaser_section_' + settings.vss_id).hoverIntent(mouseIn, mouseOut);
130
          }
131
          else {
132
            $('#views_slideshow_cycle_teaser_section_' + settings.vss_id).hover(mouseIn, mouseOut);
133
          }
134
        }
135

    
136
        // Play on hover.
137
        if (settings.play_on_hover) {
138
          var mouseIn = function() {
139
            Drupal.viewsSlideshow.action({ "action": 'play', "slideshowID": settings.slideshowId, "force": true });
140
          }
141

    
142
          var mouseOut = function() {
143
            Drupal.viewsSlideshow.action({ "action": 'pause', "slideshowID": settings.slideshowId });
144
          }
145

    
146
          if (jQuery.fn.hoverIntent) {
147
            $('#views_slideshow_cycle_teaser_section_' + settings.vss_id).hoverIntent(mouseIn, mouseOut);
148
          }
149
          else {
150
            $('#views_slideshow_cycle_teaser_section_' + settings.vss_id).hover(mouseIn, mouseOut);
151
          }
152
        }
153

    
154
        // Pause on clicking of the slide.
155
        if (settings.pause_on_click) {
156
          $('#views_slideshow_cycle_teaser_section_' + settings.vss_id).click(function() {
157
            Drupal.viewsSlideshow.action({ "action": 'pause', "slideshowID": settings.slideshowId, "force": true });
158
          });
159
        }
160

    
161
        if (typeof JSON != 'undefined') {
162
          var advancedOptions = JSON.parse(settings.advanced_options);
163
          for (var option in advancedOptions) {
164
            switch(option) {
165

    
166
              // Standard Options
167
              case "activePagerClass":
168
              case "allowPagerClickBubble":
169
              case "autostop":
170
              case "autostopCount":
171
              case "backwards":
172
              case "bounce":
173
              case "cleartype":
174
              case "cleartypeNoBg":
175
              case "containerResize":
176
              case "continuous":
177
              case "delay":
178
              case "easeIn":
179
              case "easeOut":
180
              case "easing":
181
              case "fastOnEvent":
182
              case "fit":
183
              case "fx":
184
              case "manualTrump":
185
              case "metaAttr":
186
              case "next":
187
              case "nowrap":
188
              case "pager":
189
              case "pagerEvent":
190
              case "pause":
191
              case "pauseOnPagerHover":
192
              case "prev":
193
              case "prevNextEvent":
194
              case "random":
195
              case "randomizeEffects":
196
              case "requeueOnImageNotLoaded":
197
              case "requeueTimeout":
198
              case "rev":
199
              case "slideExpr":
200
              case "slideResize":
201
              case "speed":
202
              case "speedIn":
203
              case "speedOut":
204
              case "startingSlide":
205
              case "sync":
206
              case "timeout":
207
                var optionValue = advancedOptions[option];
208
                optionValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(optionValue);
209
                settings.opts[option] = optionValue;
210
                break;
211

    
212
              // If width is set we need to disable resizing.
213
              case "width":
214
                var optionValue = advancedOptions["width"];
215
                optionValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(optionValue);
216
                settings.opts["width"] = optionValue;
217
                settings.opts["containerResize"] = 0;
218
                break;
219

    
220
              // If height is set we need to set fixed_height to true.
221
              case "height":
222
                var optionValue = advancedOptions["height"];
223
                optionValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(optionValue);
224
                settings.opts["height"] = optionValue;
225
                settings.fixed_height = 1;
226
                break;
227

    
228
              // These process options that look like {top:50, bottom:20}
229
              case "animIn":
230
              case "animInDelay":
231
              case "animOut":
232
              case "animOutDelay":
233
              case "cssBefore":
234
              case "cssAfter":
235
              case "shuffle":
236
                var cssValue = advancedOptions[option];
237
                cssValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(cssValue);
238
                settings.opts[option] = eval('(' + cssValue + ')');
239
                break;
240

    
241
              // These options have their own functions.
242
              case "after":
243
                var afterValue = advancedOptions[option];
244
                afterValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(afterValue);
245
                // transition callback (scope set to element that was shown): function(currSlideElement, nextSlideElement, options, forwardFlag)
246
                settings.opts[option] = function(currSlideElement, nextSlideElement, options, forwardFlag) {
247
                  pager_after_fn(currSlideElement, nextSlideElement, options);
248
                  eval(afterValue);
249
                }
250
                break;
251

    
252
              case "before":
253
                var beforeValue = advancedOptions[option];
254
                beforeValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(beforeValue);
255
                // transition callback (scope set to element to be shown):     function(currSlideElement, nextSlideElement, options, forwardFlag)
256
                settings.opts[option] = function(currSlideElement, nextSlideElement, options, forwardFlag) {
257
                  pager_before_fn(currSlideElement, nextSlideElement, options);
258
                  eval(beforeValue);
259
                }
260
                break;
261

    
262
              case "end":
263
                var endValue = advancedOptions[option];
264
                endValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(endValue);
265
                // callback invoked when the slideshow terminates (use with autostop or nowrap options): function(options)
266
                settings.opts[option] = function(options) {
267
                  eval(endValue);
268
                }
269
                break;
270

    
271
              case "fxFn":
272
                var fxFnValue = advancedOptions[option];
273
                fxFnValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(fxFnValue);
274
                // function used to control the transition: function(currSlideElement, nextSlideElement, options, afterCalback, forwardFlag)
275
                settings.opts[option] = function(currSlideElement, nextSlideElement, options, afterCalback, forwardFlag) {
276
                  eval(fxFnValue);
277
                }
278
                break;
279

    
280
              case "onPagerEvent":
281
                var onPagerEventValue = advancedOptions[option];
282
                onPagerEventValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(onPagerEventValue);
283
                settings.opts[option] = function(zeroBasedSlideIndex, slideElement) {
284
                  eval(onPagerEventValue);
285
                }
286
                break;
287

    
288
              case "onPrevNextEvent":
289
                var onPrevNextEventValue = advancedOptions[option];
290
                onPrevNextEventValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(onPrevNextEventValue);
291
                settings.opts[option] = function(isNext, zeroBasedSlideIndex, slideElement) {
292
                  eval(onPrevNextEventValue);
293
                }
294
                break;
295

    
296
              case "pagerAnchorBuilder":
297
                var pagerAnchorBuilderValue = advancedOptions[option];
298
                pagerAnchorBuilderValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(pagerAnchorBuilderValue);
299
                // callback fn for building anchor links:  function(index, DOMelement)
300
                settings.opts[option] = function(index, DOMelement) {
301
                  var returnVal = '';
302
                  eval(pagerAnchorBuilderValue);
303
                  return returnVal;
304
                }
305
                break;
306

    
307
              case "pagerClick":
308
                var pagerClickValue = advancedOptions[option];
309
                pagerClickValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(pagerClickValue);
310
                // callback fn for pager clicks:    function(zeroBasedSlideIndex, slideElement)
311
                settings.opts[option] = function(zeroBasedSlideIndex, slideElement) {
312
                  eval(pagerClickValue);
313
                }
314
                break;
315

    
316
              case "paused":
317
                var pausedValue = advancedOptions[option];
318
                pausedValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(pausedValue);
319
                // undocumented callback when slideshow is paused:    function(cont, opts, byHover)
320
                settings.opts[option] = function(cont, opts, byHover) {
321
                  eval(pausedValue);
322
                }
323
                break;
324

    
325
              case "resumed":
326
                var resumedValue = advancedOptions[option];
327
                resumedValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(resumedValue);
328
                // undocumented callback when slideshow is resumed:    function(cont, opts, byHover)
329
                settings.opts[option] = function(cont, opts, byHover) {
330
                  eval(resumedValue);
331
                }
332
                break;
333

    
334
              case "timeoutFn":
335
                var timeoutFnValue = advancedOptions[option];
336
                timeoutFnValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(timeoutFnValue);
337
                settings.opts[option] = function(currSlideElement, nextSlideElement, options, forwardFlag) {
338
                  // Set a sane return value unless function overrides it.
339
                  var returnVal = settings.timeout;
340
                  eval(timeoutFnValue);
341
                  return returnVal;
342
                }
343
                break;
344

    
345
              case "updateActivePagerLink":
346
                var updateActivePagerLinkValue = advancedOptions[option];
347
                updateActivePagerLinkValue = Drupal.viewsSlideshowCycle.advancedOptionCleanup(updateActivePagerLinkValue);
348
                // callback fn invoked to update the active pager link (adds/removes activePagerClass style)
349
                settings.opts[option] = function(pager, currSlideIndex) {
350
                  eval(updateActivePagerLinkValue);
351
                }
352
                break;
353
            }
354
          }
355
        }
356

    
357
        // If selected wait for the images to be loaded.
358
        // otherwise just load the slideshow.
359
        if (settings.wait_for_image_load) {
360
          // For IE/Chrome/Opera we if there are images then we need to make
361
          // sure the images are loaded before starting the slideshow.
362
          settings.totalImages = $(settings.targetId + ' img').length;
363
          if (settings.totalImages) {
364
            settings.loadedImages = 0;
365

    
366
            // Add a load event for each image.
367
            $(settings.targetId + ' img').each(function() {
368
              var $imageElement = $(this);
369
              $imageElement.bind('load', function () {
370
                Drupal.viewsSlideshowCycle.imageWait(fullId);
371
              });
372

    
373
              // Removing the source and adding it again will fire the load event.
374
              var imgSrc = $imageElement.attr('src');
375
              $imageElement.attr('src', '');
376
              $imageElement.attr('src', imgSrc);
377
            });
378

    
379
            // We need to set a timeout so that the slideshow doesn't wait
380
            // indefinitely for all images to load.
381
            setTimeout("Drupal.viewsSlideshowCycle.load('" + fullId + "')", settings.wait_for_image_load_timeout);
382
          }
383
          else {
384
            Drupal.viewsSlideshowCycle.load(fullId);
385
          }
386
        }
387
        else {
388
          Drupal.viewsSlideshowCycle.load(fullId);
389
        }
390
      });
391
    }
392
  };
393

    
394
  /**
395
   * Views Slideshow swipe support.
396
   */
397
  Drupal.behaviors.viewsSlideshowSwipe = {
398
    attach: function (context) {
399
      var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));
400
      if (isTouch === true && $('.views-slideshow-cycle-main-frame').length) {
401
        var $slider = $('.views-slideshow-cycle-main-frame'),
402
          opts = {
403
            start: {x: 0, y: 0},
404
            end: {x: 0, y: 0},
405
            hdiff: 0,
406
            vdiff: 0,
407
            length: 0,
408
            angle: null,
409
            direction: null,
410
          },
411
          optsReset = $.extend(true, {}, opts),
412
         H_THRESHOLD =  110, // roughly one inch effective resolution on ipad
413
         V_THRESHOLD = 50;
414
        $slider.data('bw', opts)
415
        .bind('touchstart.cycle', function (e) {
416
          var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
417
          if (e.originalEvent.touches.length == 1) {
418
            var data = $(this).data('bw');
419
            data.start.x = touch.pageX;
420
            data.start.y = touch.pageY;
421
            $(this).data('bw', data);
422
          }
423
        })
424
        .bind('touchend.cycle', function (e) {
425
          var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
426
          var data = $(this).data('bw');
427
          data.end.x = touch.pageX;
428
          data.end.y = touch.pageY;
429
          $(this).data('bw', data);
430
          if (data.start.x != 0 && data.start.y != 0) {
431
            data.vdiff = data.start.x - data.end.x;
432
            data.hdiff = data.end.y - data.start.y;
433
            if (Math.abs(data.vdiff) == data.start.x && Math.abs(data.hdiff) == data.start.y) {
434
              data.vdiff = 0;
435
              data.hdiff = 0;
436
            }
437
            var length = Math.round(Math.sqrt(Math.pow(data.vdiff,2) + Math.pow(data.hdiff,2)));
438
            var rads = Math.atan2(data.hdiff, data.vdiff);
439
            var angle = Math.round(rads*180/Math.PI);
440
            if (angle < 0) { angle = 360 - Math.abs(angle); }
441
            if (length > H_THRESHOLD && V_THRESHOLD > data.hdiff) {
442
              e.preventDefault();
443
              if (angle > 135 && angle < 225) {
444
                var cyopt = $slider.data('cycle.opts');
445
                if (cyopt.currSlide > 0) {
446
                  $slider.cycle((cyopt.currSlide - 1), 'scrollRight');
447
                }
448
                else {
449
                   $slider.cycle((cyopt.slideCount - 1), 'scrollRight');
450
                }
451
              }
452
              else if (angle > 315 || angle < 45) {
453
                $slider.cycle('next');
454
              }
455
            }
456
          }
457
          data = $.extend(true, {}, optsReset);
458
        });
459
      }
460
    }
461
  };
462

    
463
  Drupal.viewsSlideshowCycle = Drupal.viewsSlideshowCycle || {};
464

    
465
  // Cleanup the values of advanced options.
466
  Drupal.viewsSlideshowCycle.advancedOptionCleanup = function(value) {
467
    value = $.trim(value);
468
    value = value.replace(/\n/g, '');
469
    if (value.match(/^[\d.]+%$/)) {
470
      // noop
471
    }
472
    else if (!isNaN(parseInt(value))) {
473
      value = parseInt(value);
474
    }
475
    else if (value.toLowerCase() == 'true') {
476
      value = true;
477
    }
478
    else if (value.toLowerCase() == 'false') {
479
      value = false;
480
    }
481

    
482
    return value;
483
  }
484

    
485
  // This checks to see if all the images have been loaded.
486
  // If they have then it starts the slideshow.
487
  Drupal.viewsSlideshowCycle.imageWait = function(fullId) {
488
    if (++Drupal.settings.viewsSlideshowCycle[fullId].loadedImages == Drupal.settings.viewsSlideshowCycle[fullId].totalImages) {
489
      Drupal.viewsSlideshowCycle.load(fullId);
490
    }
491
  };
492

    
493
  // Start the slideshow.
494
  Drupal.viewsSlideshowCycle.load = function (fullId) {
495
    var settings = Drupal.settings.viewsSlideshowCycle[fullId];
496

    
497
    // Make sure the slideshow isn't already loaded.
498
    if (!settings.loaded) {
499
      $(settings.targetId).cycle(settings.opts);
500
      settings.loaded = true;
501

    
502
      // Start Paused
503
      if (settings.start_paused) {
504
        Drupal.viewsSlideshow.action({ "action": 'pause', "slideshowID": settings.slideshowId, "force": true });
505
      }
506

    
507
      // Pause if hidden.
508
      if (settings.pause_when_hidden) {
509
        var checkPause = function(settings) {
510
          // If the slideshow is visible and it is paused then resume.
511
          // otherwise if the slideshow is not visible and it is not paused then
512
          // pause it.
513
          var visible = viewsSlideshowCycleIsVisible(settings.targetId, settings.pause_when_hidden_type, settings.amount_allowed_visible);
514
          if (visible) {
515
            Drupal.viewsSlideshow.action({ "action": 'play', "slideshowID": settings.slideshowId });
516
          }
517
          else {
518
            Drupal.viewsSlideshow.action({ "action": 'pause', "slideshowID": settings.slideshowId });
519
          }
520
        }
521

    
522
        // Check when scrolled.
523
        $(window).scroll(function() {
524
         checkPause(settings);
525
        });
526

    
527
        // Check when the window is resized.
528
        $(window).resize(function() {
529
          checkPause(settings);
530
        });
531
      }
532
    }
533
  };
534

    
535
  Drupal.viewsSlideshowCycle.pause = function (options) {
536
    //Eat TypeError, cycle doesn't handle pause well if options isn't defined.
537
    try{
538
      if (options.pause_in_middle && $.fn.pause) {
539
        $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).pause();
540
      }
541
      else {
542
        $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).cycle('pause');
543
      }
544
    }
545
    catch(e){
546
      if(!e instanceof TypeError){
547
        throw e;
548
      }
549
    }
550
  };
551

    
552
  Drupal.viewsSlideshowCycle.play = function (options) {
553
    Drupal.settings.viewsSlideshowCycle['#views_slideshow_cycle_main_' + options.slideshowID].paused = false;
554
    if (options.pause_in_middle && $.fn.resume) {
555
      $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).resume();
556
    }
557
    else {
558
      $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).cycle('resume');
559
    }
560
  };
561

    
562
  Drupal.viewsSlideshowCycle.previousSlide = function (options) {
563
    $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).cycle('prev');
564
  };
565

    
566
  Drupal.viewsSlideshowCycle.nextSlide = function (options) {
567
    $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).cycle('next');
568
  };
569

    
570
  Drupal.viewsSlideshowCycle.goToSlide = function (options) {
571
    $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).cycle(options.slideNum);
572
  };
573

    
574
  // Verify that the value is a number.
575
  function IsNumeric(sText) {
576
    var ValidChars = "0123456789";
577
    var IsNumber=true;
578
    var Char;
579

    
580
    for (var i=0; i < sText.length && IsNumber == true; i++) {
581
      Char = sText.charAt(i);
582
      if (ValidChars.indexOf(Char) == -1) {
583
        IsNumber = false;
584
      }
585
    }
586
    return IsNumber;
587
  }
588

    
589
  /**
590
   * Cookie Handling Functions
591
   */
592
  function createCookie(name,value,days) {
593
    if (days) {
594
      var date = new Date();
595
      date.setTime(date.getTime()+(days*24*60*60*1000));
596
      var expires = "; expires="+date.toGMTString();
597
    }
598
    else {
599
      var expires = "";
600
    }
601
    document.cookie = name+"="+value+expires+"; path=/";
602
  }
603

    
604
  function readCookie(name) {
605
    var nameEQ = name + "=";
606
    var ca = document.cookie.split(';');
607
    for(var i=0;i < ca.length;i++) {
608
      var c = ca[i];
609
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
610
      if (c.indexOf(nameEQ) == 0) {
611
        return c.substring(nameEQ.length,c.length);
612
      }
613
    }
614
    return null;
615
  }
616

    
617
  function eraseCookie(name) {
618
    createCookie(name,"",-1);
619
  }
620

    
621
  /**
622
   * Checks to see if the slide is visible enough.
623
   * elem = element to check.
624
   * type = The way to calculate how much is visible.
625
   * amountVisible = amount that should be visible. Either in percent or px. If
626
   *                it's not defined then all of the slide must be visible.
627
   *
628
   * Returns true or false
629
   */
630
  function viewsSlideshowCycleIsVisible(elem, type, amountVisible) {
631
    // Get the top and bottom of the window;
632
    var docViewTop = $(window).scrollTop();
633
    var docViewBottom = docViewTop + $(window).height();
634
    var docViewLeft = $(window).scrollLeft();
635
    var docViewRight = docViewLeft + $(window).width();
636

    
637
    // Get the top, bottom, and height of the slide;
638
    var elemTop = $(elem).offset().top;
639
    var elemHeight = $(elem).height();
640
    var elemBottom = elemTop + elemHeight;
641
    var elemLeft = $(elem).offset().left;
642
    var elemWidth = $(elem).width();
643
    var elemRight = elemLeft + elemWidth;
644
    var elemArea = elemHeight * elemWidth;
645

    
646
    // Calculate what's hiding in the slide.
647
    var missingLeft = 0;
648
    var missingRight = 0;
649
    var missingTop = 0;
650
    var missingBottom = 0;
651

    
652
    // Find out how much of the slide is missing from the left.
653
    if (elemLeft < docViewLeft) {
654
      missingLeft = docViewLeft - elemLeft;
655
    }
656

    
657
    // Find out how much of the slide is missing from the right.
658
    if (elemRight > docViewRight) {
659
      missingRight = elemRight - docViewRight;
660
    }
661

    
662
    // Find out how much of the slide is missing from the top.
663
    if (elemTop < docViewTop) {
664
      missingTop = docViewTop - elemTop;
665
    }
666

    
667
    // Find out how much of the slide is missing from the bottom.
668
    if (elemBottom > docViewBottom) {
669
      missingBottom = elemBottom - docViewBottom;
670
    }
671

    
672
    // If there is no amountVisible defined then check to see if the whole slide
673
    // is visible.
674
    if (type == 'full') {
675
      return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom)
676
      && (elemBottom <= docViewBottom) &&  (elemTop >= docViewTop)
677
      && (elemLeft >= docViewLeft) && (elemRight <= docViewRight)
678
      && (elemLeft <= docViewRight) && (elemRight >= docViewLeft));
679
    }
680
    else if(type == 'vertical') {
681
      var verticalShowing = elemHeight - missingTop - missingBottom;
682

    
683
      // If user specified a percentage then find out if the current shown percent
684
      // is larger than the allowed percent.
685
      // Otherwise check to see if the amount of px shown is larger than the
686
      // allotted amount.
687
      if (typeof amountVisible === 'string' && amountVisible.indexOf('%')) {
688
        return (((verticalShowing/elemHeight)*100) >= parseInt(amountVisible));
689
      }
690
      else {
691
        return (verticalShowing >= parseInt(amountVisible));
692
      }
693
    }
694
    else if(type == 'horizontal') {
695
      var horizontalShowing = elemWidth - missingLeft - missingRight;
696

    
697
      // If user specified a percentage then find out if the current shown percent
698
      // is larger than the allowed percent.
699
      // Otherwise check to see if the amount of px shown is larger than the
700
      // allotted amount.
701
      if (typeof amountVisible === 'string' && amountVisible.indexOf('%')) {
702
        return (((horizontalShowing/elemWidth)*100) >= parseInt(amountVisible));
703
      }
704
      else {
705
        return (horizontalShowing >= parseInt(amountVisible));
706
      }
707
    }
708
    else if(type == 'area') {
709
      var areaShowing = (elemWidth - missingLeft - missingRight) * (elemHeight - missingTop - missingBottom);
710

    
711
      // If user specified a percentage then find out if the current shown percent
712
      // is larger than the allowed percent.
713
      // Otherwise check to see if the amount of px shown is larger than the
714
      // allotted amount.
715
      if (typeof amountVisible === 'string' && amountVisible.indexOf('%')) {
716
        return (((areaShowing/elemArea)*100) >= parseInt(amountVisible));
717
      }
718
      else {
719
        return (areaShowing >= parseInt(amountVisible));
720
      }
721
    }
722
  }
723
})(jQuery);