Advertisement
iamdangavin

jQuery Cycle All

Jul 7th, 2011
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*!
  2.  * jQuery Cycle Plugin (with Transition Definitions)
  3.  * Examples and documentation at: http://jquery.malsup.com/cycle/
  4.  * Copyright (c) 2007-2010 M. Alsup
  5.  * Version: 2.94 (20-DEC-2010)
  6.  * Dual licensed under the MIT and GPL licenses.
  7.  * http://jquery.malsup.com/license.html
  8.  * Requires: jQuery v1.2.6 or later
  9.  */
  10. ;(function($) {
  11.  
  12. var ver = '2.94';
  13.  
  14. // if $.support is not defined (pre jQuery 1.3) add what I need
  15. if ($.support == undefined) {
  16.     $.support = {
  17.         opacity: !($.browser.msie)
  18.     };
  19. }
  20.  
  21. function debug(s) {
  22.     if ($.fn.cycle.debug)
  23.         log(s);
  24. }      
  25. function log() {
  26.     if (window.console && window.console.log)
  27.         window.console.log('[cycle] ' + Array.prototype.join.call(arguments,' '));
  28. };
  29.  
  30. // the options arg can be...
  31. //   a number  - indicates an immediate transition should occur to the given slide index
  32. //   a string  - 'pause', 'resume', 'toggle', 'next', 'prev', 'stop', 'destroy' or the name of a transition effect (ie, 'fade', 'zoom', etc)
  33. //   an object - properties to control the slideshow
  34. //
  35. // the arg2 arg can be...
  36. //   the name of an fx (only used in conjunction with a numeric value for 'options')
  37. //   the value true (only used in first arg == 'resume') and indicates
  38. //   that the resume should occur immediately (not wait for next timeout)
  39.  
  40. $.fn.cycle = function(options, arg2) {
  41.     var o = { s: this.selector, c: this.context };
  42.  
  43.     // in 1.3+ we can fix mistakes with the ready state
  44.     if (this.length === 0 && options != 'stop') {
  45.         if (!$.isReady && o.s) {
  46.             log('DOM not ready, queuing slideshow');
  47.             $(function() {
  48.                 $(o.s,o.c).cycle(options,arg2);
  49.             });
  50.             return this;
  51.         }
  52.         // is your DOM ready?  http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
  53.         log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
  54.         return this;
  55.     }
  56.  
  57.     // iterate the matched nodeset
  58.     return this.each(function() {
  59.         var opts = handleArguments(this, options, arg2);
  60.         if (opts === false)
  61.             return;
  62.  
  63.         opts.updateActivePagerLink = opts.updateActivePagerLink || $.fn.cycle.updateActivePagerLink;
  64.        
  65.         // stop existing slideshow for this container (if there is one)
  66.         if (this.cycleTimeout)
  67.             clearTimeout(this.cycleTimeout);
  68.         this.cycleTimeout = this.cyclePause = 0;
  69.  
  70.         var $cont = $(this);
  71.         var $slides = opts.slideExpr ? $(opts.slideExpr, this) : $cont.children();
  72.         var els = $slides.get();
  73.         if (els.length < 2) {
  74.             log('terminating; too few slides: ' + els.length);
  75.             return;
  76.         }
  77.  
  78.         var opts2 = buildOptions($cont, $slides, els, opts, o);
  79.         if (opts2 === false)
  80.             return;
  81.  
  82.         var startTime = opts2.continuous ? 10 : getTimeout(els[opts2.currSlide], els[opts2.nextSlide], opts2, !opts2.backwards);
  83.  
  84.         // if it's an auto slideshow, kick it off
  85.         if (startTime) {
  86.             startTime += (opts2.delay || 0);
  87.             if (startTime < 10)
  88.                 startTime = 10;
  89.             debug('first timeout: ' + startTime);
  90.             this.cycleTimeout = setTimeout(function(){go(els,opts2,0,!opts.backwards)}, startTime);
  91.         }
  92.     });
  93. };
  94.  
  95. // process the args that were passed to the plugin fn
  96. function handleArguments(cont, options, arg2) {
  97.     if (cont.cycleStop == undefined)
  98.         cont.cycleStop = 0;
  99.     if (options === undefined || options === null)
  100.         options = {};
  101.     if (options.constructor == String) {
  102.         switch(options) {
  103.         case 'destroy':
  104.         case 'stop':
  105.             var opts = $(cont).data('cycle.opts');
  106.             if (!opts)
  107.                 return false;
  108.             cont.cycleStop++; // callbacks look for change
  109.             if (cont.cycleTimeout)
  110.                 clearTimeout(cont.cycleTimeout);
  111.             cont.cycleTimeout = 0;
  112.             $(cont).removeData('cycle.opts');
  113.             if (options == 'destroy')
  114.                 destroy(opts);
  115.             return false;
  116.         case 'toggle':
  117.             cont.cyclePause = (cont.cyclePause === 1) ? 0 : 1;
  118.             checkInstantResume(cont.cyclePause, arg2, cont);
  119.             return false;
  120.         case 'pause':
  121.             cont.cyclePause = 1;
  122.             return false;
  123.         case 'resume':
  124.             cont.cyclePause = 0;
  125.             checkInstantResume(false, arg2, cont);
  126.             return false;
  127.         case 'prev':
  128.         case 'next':
  129.             var opts = $(cont).data('cycle.opts');
  130.             if (!opts) {
  131.                 log('options not found, "prev/next" ignored');
  132.                 return false;
  133.             }
  134.             $.fn.cycle[options](opts);
  135.             return false;
  136.         default:
  137.             options = { fx: options };
  138.         };
  139.         return options;
  140.     }
  141.     else if (options.constructor == Number) {
  142.         // go to the requested slide
  143.         var num = options;
  144.         options = $(cont).data('cycle.opts');
  145.         if (!options) {
  146.             log('options not found, can not advance slide');
  147.             return false;
  148.         }
  149.         if (num < 0 || num >= options.elements.length) {
  150.             log('invalid slide index: ' + num);
  151.             return false;
  152.         }
  153.         options.nextSlide = num;
  154.         if (cont.cycleTimeout) {
  155.             clearTimeout(cont.cycleTimeout);
  156.             cont.cycleTimeout = 0;
  157.         }
  158.         if (typeof arg2 == 'string')
  159.             options.oneTimeFx = arg2;
  160.         go(options.elements, options, 1, num >= options.currSlide);
  161.         return false;
  162.     }
  163.     return options;
  164.    
  165.     function checkInstantResume(isPaused, arg2, cont) {
  166.         if (!isPaused && arg2 === true) { // resume now!
  167.             var options = $(cont).data('cycle.opts');
  168.             if (!options) {
  169.                 log('options not found, can not resume');
  170.                 return false;
  171.             }
  172.             if (cont.cycleTimeout) {
  173.                 clearTimeout(cont.cycleTimeout);
  174.                 cont.cycleTimeout = 0;
  175.             }
  176.             go(options.elements, options, 1, !options.backwards);
  177.         }
  178.     }
  179. };
  180.  
  181. function removeFilter(el, opts) {
  182.     if (!$.support.opacity && opts.cleartype && el.style.filter) {
  183.         try { el.style.removeAttribute('filter'); }
  184.         catch(smother) {} // handle old opera versions
  185.     }
  186. };
  187.  
  188. // unbind event handlers
  189. function destroy(opts) {
  190.     if (opts.next)
  191.         $(opts.next).unbind(opts.prevNextEvent);
  192.     if (opts.prev)
  193.         $(opts.prev).unbind(opts.prevNextEvent);
  194.    
  195.     if (opts.pager || opts.pagerAnchorBuilder)
  196.         $.each(opts.pagerAnchors || [], function() {
  197.             this.unbind().remove();
  198.         });
  199.     opts.pagerAnchors = null;
  200.     if (opts.destroy) // callback
  201.         opts.destroy(opts);
  202. };
  203.  
  204. // one-time initialization
  205. function buildOptions($cont, $slides, els, options, o) {
  206.     // support metadata plugin (v1.0 and v2.0)
  207.     var opts = $.extend({}, $.fn.cycle.defaults, options || {}, $.metadata ? $cont.metadata() : $.meta ? $cont.data() : {});
  208.     if (opts.autostop)
  209.         opts.countdown = opts.autostopCount || els.length;
  210.  
  211.     var cont = $cont[0];
  212.     $cont.data('cycle.opts', opts);
  213.     opts.$cont = $cont;
  214.     opts.stopCount = cont.cycleStop;
  215.     opts.elements = els;
  216.     opts.before = opts.before ? [opts.before] : [];
  217.     opts.after = opts.after ? [opts.after] : [];
  218.     opts.after.unshift(function(){ opts.busy=0; });
  219.  
  220.     // push some after callbacks
  221.     if (!$.support.opacity && opts.cleartype)
  222.         opts.after.push(function() { removeFilter(this, opts); });
  223.     if (opts.continuous)
  224.         opts.after.push(function() { go(els,opts,0,!opts.backwards); });
  225.  
  226.     saveOriginalOpts(opts);
  227.  
  228.     // clearType corrections
  229.     if (!$.support.opacity && opts.cleartype && !opts.cleartypeNoBg)
  230.         clearTypeFix($slides);
  231.  
  232.     // container requires non-static position so that slides can be position within
  233.     if ($cont.css('position') == 'static')
  234.         $cont.css('position', 'relative');
  235.     if (opts.width)
  236.         $cont.width(opts.width);
  237.     if (opts.height && opts.height != 'auto')
  238.         $cont.height(opts.height);
  239.  
  240.     if (opts.startingSlide)
  241.         opts.startingSlide = parseInt(opts.startingSlide);
  242.     else if (opts.backwards)
  243.         opts.startingSlide = els.length - 1;
  244.  
  245.     // if random, mix up the slide array
  246.     if (opts.random) {
  247.         opts.randomMap = [];
  248.         for (var i = 0; i < els.length; i++)
  249.             opts.randomMap.push(i);
  250.         opts.randomMap.sort(function(a,b) {return Math.random() - 0.5;});
  251.         opts.randomIndex = 1;
  252.         opts.startingSlide = opts.randomMap[1];
  253.     }
  254.     else if (opts.startingSlide >= els.length)
  255.         opts.startingSlide = 0; // catch bogus input
  256.     opts.currSlide = opts.startingSlide || 0;
  257.     var first = opts.startingSlide;
  258.  
  259.     // set position and zIndex on all the slides
  260.     $slides.css({position: 'absolute', top:0, left:0}).hide().each(function(i) {
  261.         var z;
  262.         if (opts.backwards)
  263.             z = first ? i <= first ? els.length + (i-first) : first-i : els.length-i;
  264.         else
  265.             z = first ? i >= first ? els.length - (i-first) : first-i : els.length-i;
  266.         $(this).css('z-index', z)
  267.     });
  268.  
  269.     // make sure first slide is visible
  270.     $(els[first]).css('opacity',1).show(); // opacity bit needed to handle restart use case
  271.     removeFilter(els[first], opts);
  272.  
  273.     // stretch slides
  274.     if (opts.fit && opts.width)
  275.         $slides.width(opts.width);
  276.     if (opts.fit && opts.height && opts.height != 'auto')
  277.         $slides.height(opts.height);
  278.  
  279.     // stretch container
  280.     var reshape = opts.containerResize && !$cont.innerHeight();
  281.     if (reshape) { // do this only if container has no size http://tinyurl.com/da2oa9
  282.         var maxw = 0, maxh = 0;
  283.         for(var j=0; j < els.length; j++) {
  284.             var $e = $(els[j]), e = $e[0], w = $e.outerWidth(), h = $e.outerHeight();
  285.             if (!w) w = e.offsetWidth || e.width || $e.attr('width')
  286.             if (!h) h = e.offsetHeight || e.height || $e.attr('height');
  287.             maxw = w > maxw ? w : maxw;
  288.             maxh = h > maxh ? h : maxh;
  289.         }
  290.         if (maxw > 0 && maxh > 0)
  291.             $cont.css({width:maxw+'px',height:maxh+'px'});
  292.     }
  293.  
  294.     if (opts.pause)
  295.         $cont.hover(function(){this.cyclePause++;},function(){this.cyclePause--;});
  296.  
  297.     if (supportMultiTransitions(opts) === false)
  298.         return false;
  299.  
  300.     // apparently a lot of people use image slideshows without height/width attributes on the images.
  301.     // Cycle 2.50+ requires the sizing info for every slide; this block tries to deal with that.
  302.     var requeue = false;
  303.     options.requeueAttempts = options.requeueAttempts || 0;
  304.     $slides.each(function() {
  305.         // try to get height/width of each slide
  306.         var $el = $(this);
  307.         this.cycleH = (opts.fit && opts.height) ? opts.height : ($el.height() || this.offsetHeight || this.height || $el.attr('height') || 0);
  308.         this.cycleW = (opts.fit && opts.width) ? opts.width : ($el.width() || this.offsetWidth || this.width || $el.attr('width') || 0);
  309.  
  310.         if ( $el.is('img') ) {
  311.             // sigh..  sniffing, hacking, shrugging...  this crappy hack tries to account for what browsers do when
  312.             // an image is being downloaded and the markup did not include sizing info (height/width attributes);
  313.             // there seems to be some "default" sizes used in this situation
  314.             var loadingIE   = ($.browser.msie  && this.cycleW == 28 && this.cycleH == 30 && !this.complete);
  315.             var loadingFF   = ($.browser.mozilla && this.cycleW == 34 && this.cycleH == 19 && !this.complete);
  316.             var loadingOp   = ($.browser.opera && ((this.cycleW == 42 && this.cycleH == 19) || (this.cycleW == 37 && this.cycleH == 17)) && !this.complete);
  317.             var loadingOther = (this.cycleH == 0 && this.cycleW == 0 && !this.complete);
  318.             // don't requeue for images that are still loading but have a valid size
  319.             if (loadingIE || loadingFF || loadingOp || loadingOther) {
  320.                 if (o.s && opts.requeueOnImageNotLoaded && ++options.requeueAttempts < 100) { // track retry count so we don't loop forever
  321.                     log(options.requeueAttempts,' - img slide not loaded, requeuing slideshow: ', this.src, this.cycleW, this.cycleH);
  322.                     setTimeout(function() {$(o.s,o.c).cycle(options)}, opts.requeueTimeout);
  323.                     requeue = true;
  324.                     return false; // break each loop
  325.                 }
  326.                 else {
  327.                     log('could not determine size of image: '+this.src, this.cycleW, this.cycleH);
  328.                 }
  329.             }
  330.         }
  331.         return true;
  332.     });
  333.  
  334.     if (requeue)
  335.         return false;
  336.  
  337.     opts.cssBefore = opts.cssBefore || {};
  338.     opts.animIn = opts.animIn || {};
  339.     opts.animOut = opts.animOut || {};
  340.  
  341.     $slides.not(':eq('+first+')').css(opts.cssBefore);
  342.     if (opts.cssFirst)
  343.         $($slides[first]).css(opts.cssFirst);
  344.  
  345.     if (opts.timeout) {
  346.         opts.timeout = parseInt(opts.timeout);
  347.         // ensure that timeout and speed settings are sane
  348.         if (opts.speed.constructor == String)
  349.             opts.speed = $.fx.speeds[opts.speed] || parseInt(opts.speed);
  350.         if (!opts.sync)
  351.             opts.speed = opts.speed / 2;
  352.        
  353.         var buffer = opts.fx == 'shuffle' ? 500 : 250;
  354.         while((opts.timeout - opts.speed) < buffer) // sanitize timeout
  355.             opts.timeout += opts.speed;
  356.     }
  357.     if (opts.easing)
  358.         opts.easeIn = opts.easeOut = opts.easing;
  359.     if (!opts.speedIn)
  360.         opts.speedIn = opts.speed;
  361.     if (!opts.speedOut)
  362.         opts.speedOut = opts.speed;
  363.  
  364.     opts.slideCount = els.length;
  365.     opts.currSlide = opts.lastSlide = first;
  366.     if (opts.random) {
  367.         if (++opts.randomIndex == els.length)
  368.             opts.randomIndex = 0;
  369.         opts.nextSlide = opts.randomMap[opts.randomIndex];
  370.     }
  371.     else if (opts.backwards)
  372.         opts.nextSlide = opts.startingSlide == 0 ? (els.length-1) : opts.startingSlide-1;
  373.     else
  374.         opts.nextSlide = opts.startingSlide >= (els.length-1) ? 0 : opts.startingSlide+1;
  375.  
  376.     // run transition init fn
  377.     if (!opts.multiFx) {
  378.         var init = $.fn.cycle.transitions[opts.fx];
  379.         if ($.isFunction(init))
  380.             init($cont, $slides, opts);
  381.         else if (opts.fx != 'custom' && !opts.multiFx) {
  382.             log('unknown transition: ' + opts.fx,'; slideshow terminating');
  383.             return false;
  384.         }
  385.     }
  386.  
  387.     // fire artificial events
  388.     var e0 = $slides[first];
  389.     if (opts.before.length)
  390.         opts.before[0].apply(e0, [e0, e0, opts, true]);
  391.     if (opts.after.length > 1)
  392.         opts.after[1].apply(e0, [e0, e0, opts, true]);
  393.  
  394.     if (opts.next)
  395.         $(opts.next).bind(opts.prevNextEvent,function(){return advance(opts,1)});
  396.     if (opts.prev)
  397.         $(opts.prev).bind(opts.prevNextEvent,function(){return advance(opts,0)});
  398.     if (opts.pager || opts.pagerAnchorBuilder)
  399.         buildPager(els,opts);
  400.  
  401.     exposeAddSlide(opts, els);
  402.  
  403.     return opts;
  404. };
  405.  
  406. // save off original opts so we can restore after clearing state
  407. function saveOriginalOpts(opts) {
  408.     opts.original = { before: [], after: [] };
  409.     opts.original.cssBefore = $.extend({}, opts.cssBefore);
  410.     opts.original.cssAfter  = $.extend({}, opts.cssAfter);
  411.     opts.original.animIn    = $.extend({}, opts.animIn);
  412.     opts.original.animOut   = $.extend({}, opts.animOut);
  413.     $.each(opts.before, function() { opts.original.before.push(this); });
  414.     $.each(opts.after,  function() { opts.original.after.push(this); });
  415. };
  416.  
  417. function supportMultiTransitions(opts) {
  418.     var i, tx, txs = $.fn.cycle.transitions;
  419.     // look for multiple effects
  420.     if (opts.fx.indexOf(',') > 0) {
  421.         opts.multiFx = true;
  422.         opts.fxs = opts.fx.replace(/\s*/g,'').split(',');
  423.         // discard any bogus effect names
  424.         for (i=0; i < opts.fxs.length; i++) {
  425.             var fx = opts.fxs[i];
  426.             tx = txs[fx];
  427.             if (!tx || !txs.hasOwnProperty(fx) || !$.isFunction(tx)) {
  428.                 log('discarding unknown transition: ',fx);
  429.                 opts.fxs.splice(i,1);
  430.                 i--;
  431.             }
  432.         }
  433.         // if we have an empty list then we threw everything away!
  434.         if (!opts.fxs.length) {
  435.             log('No valid transitions named; slideshow terminating.');
  436.             return false;
  437.         }
  438.     }
  439.     else if (opts.fx == 'all') {  // auto-gen the list of transitions
  440.         opts.multiFx = true;
  441.         opts.fxs = [];
  442.         for (p in txs) {
  443.             tx = txs[p];
  444.             if (txs.hasOwnProperty(p) && $.isFunction(tx))
  445.                 opts.fxs.push(p);
  446.         }
  447.     }
  448.     if (opts.multiFx && opts.randomizeEffects) {
  449.         // munge the fxs array to make effect selection random
  450.         var r1 = Math.floor(Math.random() * 20) + 30;
  451.         for (i = 0; i < r1; i++) {
  452.             var r2 = Math.floor(Math.random() * opts.fxs.length);
  453.             opts.fxs.push(opts.fxs.splice(r2,1)[0]);
  454.         }
  455.         debug('randomized fx sequence: ',opts.fxs);
  456.     }
  457.     return true;
  458. };
  459.  
  460. // provide a mechanism for adding slides after the slideshow has started
  461. function exposeAddSlide(opts, els) {
  462.     opts.addSlide = function(newSlide, prepend) {
  463.         var $s = $(newSlide), s = $s[0];
  464.         if (!opts.autostopCount)
  465.             opts.countdown++;
  466.         els[prepend?'unshift':'push'](s);
  467.         if (opts.els)
  468.             opts.els[prepend?'unshift':'push'](s); // shuffle needs this
  469.         opts.slideCount = els.length;
  470.  
  471.         $s.css('position','absolute');
  472.         $s[prepend?'prependTo':'appendTo'](opts.$cont);
  473.  
  474.         if (prepend) {
  475.             opts.currSlide++;
  476.             opts.nextSlide++;
  477.         }
  478.  
  479.         if (!$.support.opacity && opts.cleartype && !opts.cleartypeNoBg)
  480.             clearTypeFix($s);
  481.  
  482.         if (opts.fit && opts.width)
  483.             $s.width(opts.width);
  484.         if (opts.fit && opts.height && opts.height != 'auto')
  485.             $s.height(opts.height);
  486.         s.cycleH = (opts.fit && opts.height) ? opts.height : $s.height();
  487.         s.cycleW = (opts.fit && opts.width) ? opts.width : $s.width();
  488.  
  489.         $s.css(opts.cssBefore);
  490.  
  491.         if (opts.pager || opts.pagerAnchorBuilder)
  492.             $.fn.cycle.createPagerAnchor(els.length-1, s, $(opts.pager), els, opts);
  493.  
  494.         if ($.isFunction(opts.onAddSlide))
  495.             opts.onAddSlide($s);
  496.         else
  497.             $s.hide(); // default behavior
  498.     };
  499. }
  500.  
  501. // reset internal state; we do this on every pass in order to support multiple effects
  502. $.fn.cycle.resetState = function(opts, fx) {
  503.     fx = fx || opts.fx;
  504.     opts.before = []; opts.after = [];
  505.     opts.cssBefore = $.extend({}, opts.original.cssBefore);
  506.     opts.cssAfter  = $.extend({}, opts.original.cssAfter);
  507.     opts.animIn = $.extend({}, opts.original.animIn);
  508.     opts.animOut   = $.extend({}, opts.original.animOut);
  509.     opts.fxFn = null;
  510.     $.each(opts.original.before, function() { opts.before.push(this); });
  511.     $.each(opts.original.after,  function() { opts.after.push(this); });
  512.  
  513.     // re-init
  514.     var init = $.fn.cycle.transitions[fx];
  515.     if ($.isFunction(init))
  516.         init(opts.$cont, $(opts.elements), opts);
  517. };
  518.  
  519. // this is the main engine fn, it handles the timeouts, callbacks and slide index mgmt
  520. function go(els, opts, manual, fwd) {
  521.     // opts.busy is true if we're in the middle of an animation
  522.     if (manual && opts.busy && opts.manualTrump) {
  523.         // let manual transitions requests trump active ones
  524.         debug('manualTrump in go(), stopping active transition');
  525.         $(els).stop(true,true);
  526.         opts.busy = false;
  527.     }
  528.     // don't begin another timeout-based transition if there is one active
  529.     if (opts.busy) {
  530.         debug('transition active, ignoring new tx request');
  531.         return;
  532.     }
  533.  
  534.     var p = opts.$cont[0], curr = els[opts.currSlide], next = els[opts.nextSlide];
  535.  
  536.     // stop cycling if we have an outstanding stop request
  537.     if (p.cycleStop != opts.stopCount || p.cycleTimeout === 0 && !manual)
  538.         return;
  539.  
  540.     // check to see if we should stop cycling based on autostop options
  541.     if (!manual && !p.cyclePause && !opts.bounce &&
  542.         ((opts.autostop && (--opts.countdown <= 0)) ||
  543.         (opts.nowrap && !opts.random && opts.nextSlide < opts.currSlide))) {
  544.         if (opts.end)
  545.             opts.end(opts);
  546.         return;
  547.     }
  548.  
  549.     // if slideshow is paused, only transition on a manual trigger
  550.     var changed = false;
  551.     if ((manual || !p.cyclePause) && (opts.nextSlide != opts.currSlide)) {
  552.         changed = true;
  553.         var fx = opts.fx;
  554.         // keep trying to get the slide size if we don't have it yet
  555.         curr.cycleH = curr.cycleH || $(curr).height();
  556.         curr.cycleW = curr.cycleW || $(curr).width();
  557.         next.cycleH = next.cycleH || $(next).height();
  558.         next.cycleW = next.cycleW || $(next).width();
  559.  
  560.         // support multiple transition types
  561.         if (opts.multiFx) {
  562.             if (opts.lastFx == undefined || ++opts.lastFx >= opts.fxs.length)
  563.                 opts.lastFx = 0;
  564.             fx = opts.fxs[opts.lastFx];
  565.             opts.currFx = fx;
  566.         }
  567.  
  568.         // one-time fx overrides apply to:  $('div').cycle(3,'zoom');
  569.         if (opts.oneTimeFx) {
  570.             fx = opts.oneTimeFx;
  571.             opts.oneTimeFx = null;
  572.         }
  573.  
  574.         $.fn.cycle.resetState(opts, fx);
  575.  
  576.         // run the before callbacks
  577.         if (opts.before.length)
  578.             $.each(opts.before, function(i,o) {
  579.                 if (p.cycleStop != opts.stopCount) return;
  580.                 o.apply(next, [curr, next, opts, fwd]);
  581.             });
  582.  
  583.         // stage the after callacks
  584.         var after = function() {
  585.             $.each(opts.after, function(i,o) {
  586.                 if (p.cycleStop != opts.stopCount) return;
  587.                 o.apply(next, [curr, next, opts, fwd]);
  588.             });
  589.         };
  590.  
  591.         debug('tx firing; currSlide: ' + opts.currSlide + '; nextSlide: ' + opts.nextSlide);
  592.        
  593.         // get ready to perform the transition
  594.         opts.busy = 1;
  595.         if (opts.fxFn) // fx function provided?
  596.             opts.fxFn(curr, next, opts, after, fwd, manual && opts.fastOnEvent);
  597.         else if ($.isFunction($.fn.cycle[opts.fx])) // fx plugin ?
  598.             $.fn.cycle[opts.fx](curr, next, opts, after, fwd, manual && opts.fastOnEvent);
  599.         else
  600.             $.fn.cycle.custom(curr, next, opts, after, fwd, manual && opts.fastOnEvent);
  601.     }
  602.  
  603.     if (changed || opts.nextSlide == opts.currSlide) {
  604.         // calculate the next slide
  605.         opts.lastSlide = opts.currSlide;
  606.         if (opts.random) {
  607.             opts.currSlide = opts.nextSlide;
  608.             if (++opts.randomIndex == els.length)
  609.                 opts.randomIndex = 0;
  610.             opts.nextSlide = opts.randomMap[opts.randomIndex];
  611.             if (opts.nextSlide == opts.currSlide)
  612.                 opts.nextSlide = (opts.currSlide == opts.slideCount - 1) ? 0 : opts.currSlide + 1;
  613.         }
  614.         else if (opts.backwards) {
  615.             var roll = (opts.nextSlide - 1) < 0;
  616.             if (roll && opts.bounce) {
  617.                 opts.backwards = !opts.backwards;
  618.                 opts.nextSlide = 1;
  619.                 opts.currSlide = 0;
  620.             }
  621.             else {
  622.                 opts.nextSlide = roll ? (els.length-1) : opts.nextSlide-1;
  623.                 opts.currSlide = roll ? 0 : opts.nextSlide+1;
  624.             }
  625.         }
  626.         else { // sequence
  627.             var roll = (opts.nextSlide + 1) == els.length;
  628.             if (roll && opts.bounce) {
  629.                 opts.backwards = !opts.backwards;
  630.                 opts.nextSlide = els.length-2;
  631.                 opts.currSlide = els.length-1;
  632.             }
  633.             else {
  634.                 opts.nextSlide = roll ? 0 : opts.nextSlide+1;
  635.                 opts.currSlide = roll ? els.length-1 : opts.nextSlide-1;
  636.             }
  637.         }
  638.     }
  639.     if (changed && opts.pager)
  640.         opts.updateActivePagerLink(opts.pager, opts.currSlide, opts.activePagerClass);
  641.    
  642.     // stage the next transition
  643.     var ms = 0;
  644.     if (opts.timeout && !opts.continuous)
  645.         ms = getTimeout(els[opts.currSlide], els[opts.nextSlide], opts, fwd);
  646.     else if (opts.continuous && p.cyclePause) // continuous shows work off an after callback, not this timer logic
  647.         ms = 10;
  648.     if (ms > 0)
  649.         p.cycleTimeout = setTimeout(function(){ go(els, opts, 0, !opts.backwards) }, ms);
  650. };
  651.  
  652. // invoked after transition
  653. $.fn.cycle.updateActivePagerLink = function(pager, currSlide, clsName) {
  654.    $(pager).each(function() {
  655.        $(this).children().removeClass(clsName).eq(currSlide).addClass(clsName);
  656.    });
  657. };
  658.  
  659. // calculate timeout value for current transition
  660. function getTimeout(curr, next, opts, fwd) {
  661.     if (opts.timeoutFn) {
  662.         // call user provided calc fn
  663.         var t = opts.timeoutFn.call(curr,curr,next,opts,fwd);
  664.         while ((t - opts.speed) < 250) // sanitize timeout
  665.             t += opts.speed;
  666.         debug('calculated timeout: ' + t + '; speed: ' + opts.speed);
  667.         if (t !== false)
  668.             return t;
  669.     }
  670.     return opts.timeout;
  671. };
  672.  
  673. // expose next/prev function, caller must pass in state
  674. $.fn.cycle.next = function(opts) { advance(opts,1); };
  675. $.fn.cycle.prev = function(opts) { advance(opts,0);};
  676.  
  677. // advance slide forward or back
  678. function advance(opts, moveForward) {
  679.     var val = moveForward ? 1 : -1;
  680.     var els = opts.elements;
  681.     var p = opts.$cont[0], timeout = p.cycleTimeout;
  682.     if (timeout) {
  683.         clearTimeout(timeout);
  684.         p.cycleTimeout = 0;
  685.     }
  686.     if (opts.random && val < 0) {
  687.         // move back to the previously display slide
  688.         opts.randomIndex--;
  689.         if (--opts.randomIndex == -2)
  690.             opts.randomIndex = els.length-2;
  691.         else if (opts.randomIndex == -1)
  692.             opts.randomIndex = els.length-1;
  693.         opts.nextSlide = opts.randomMap[opts.randomIndex];
  694.     }
  695.     else if (opts.random) {
  696.         opts.nextSlide = opts.randomMap[opts.randomIndex];
  697.     }
  698.     else {
  699.         opts.nextSlide = opts.currSlide + val;
  700.         if (opts.nextSlide < 0) {
  701.             if (opts.nowrap) return false;
  702.             opts.nextSlide = els.length - 1;
  703.         }
  704.         else if (opts.nextSlide >= els.length) {
  705.             if (opts.nowrap) return false;
  706.             opts.nextSlide = 0;
  707.         }
  708.     }
  709.  
  710.     var cb = opts.onPrevNextEvent || opts.prevNextClick; // prevNextClick is deprecated
  711.     if ($.isFunction(cb))
  712.         cb(val > 0, opts.nextSlide, els[opts.nextSlide]);
  713.     go(els, opts, 1, moveForward);
  714.     return false;
  715. };
  716.  
  717. function buildPager(els, opts) {
  718.     var $p = $(opts.pager);
  719.     $.each(els, function(i,o) {
  720.         $.fn.cycle.createPagerAnchor(i,o,$p,els,opts);
  721.     });
  722.     opts.updateActivePagerLink(opts.pager, opts.startingSlide, opts.activePagerClass);
  723. };
  724.  
  725. $.fn.cycle.createPagerAnchor = function(i, el, $p, els, opts) {
  726.     var a;
  727.     if ($.isFunction(opts.pagerAnchorBuilder)) {
  728.         a = opts.pagerAnchorBuilder(i,el);
  729.         debug('pagerAnchorBuilder('+i+', el) returned: ' + a);
  730.     }
  731.     else
  732.         a = '<a href="#">'+(i+1)+'</a>';
  733.        
  734.     if (!a)
  735.         return;
  736.     var $a = $(a);
  737.     // don't reparent if anchor is in the dom
  738.     if ($a.parents('body').length === 0) {
  739.         var arr = [];
  740.         if ($p.length > 1) {
  741.             $p.each(function() {
  742.                 var $clone = $a.clone(true);
  743.                 $(this).append($clone);
  744.                 arr.push($clone[0]);
  745.             });
  746.             $a = $(arr);
  747.         }
  748.         else {
  749.             $a.appendTo($p);
  750.         }
  751.     }
  752.  
  753.     opts.pagerAnchors =  opts.pagerAnchors || [];
  754.     opts.pagerAnchors.push($a);
  755.     $a.bind(opts.pagerEvent, function(e) {
  756.         e.preventDefault();
  757.         opts.nextSlide = i;
  758.         var p = opts.$cont[0], timeout = p.cycleTimeout;
  759.         if (timeout) {
  760.             clearTimeout(timeout);
  761.             p.cycleTimeout = 0;
  762.         }
  763.         var cb = opts.onPagerEvent || opts.pagerClick; // pagerClick is deprecated
  764.         if ($.isFunction(cb))
  765.             cb(opts.nextSlide, els[opts.nextSlide]);
  766.         go(els,opts,1,opts.currSlide < i); // trigger the trans
  767. //      return false; // <== allow bubble
  768.     });
  769.    
  770.     if ( ! /^click/.test(opts.pagerEvent) && !opts.allowPagerClickBubble)
  771.         $a.bind('click.cycle', function(){return false;}); // suppress click
  772.    
  773.     if (opts.pauseOnPagerHover)
  774.         $a.hover(function() { opts.$cont[0].cyclePause++; }, function() { opts.$cont[0].cyclePause--; } );
  775. };
  776.  
  777. // helper fn to calculate the number of slides between the current and the next
  778. $.fn.cycle.hopsFromLast = function(opts, fwd) {
  779.     var hops, l = opts.lastSlide, c = opts.currSlide;
  780.     if (fwd)
  781.         hops = c > l ? c - l : opts.slideCount - l;
  782.     else
  783.         hops = c < l ? l - c : l + opts.slideCount - c;
  784.     return hops;
  785. };
  786.  
  787. // fix clearType problems in ie6 by setting an explicit bg color
  788. // (otherwise text slides look horrible during a fade transition)
  789. function clearTypeFix($slides) {
  790.     debug('applying clearType background-color hack');
  791.     function hex(s) {
  792.         s = parseInt(s).toString(16);
  793.         return s.length < 2 ? '0'+s : s;
  794.     };
  795.     function getBg(e) {
  796.         for ( ; e && e.nodeName.toLowerCase() != 'html'; e = e.parentNode) {
  797.             var v = $.css(e,'background-color');
  798.             if (v.indexOf('rgb') >= 0 ) {
  799.                 var rgb = v.match(/\d+/g);
  800.                 return '#'+ hex(rgb[0]) + hex(rgb[1]) + hex(rgb[2]);
  801.             }
  802.             if (v && v != 'transparent')
  803.                 return v;
  804.         }
  805.         return '#ffffff';
  806.     };
  807.     $slides.each(function() { $(this).css('background-color', getBg(this)); });
  808. };
  809.  
  810. // reset common props before the next transition
  811. $.fn.cycle.commonReset = function(curr,next,opts,w,h,rev) {
  812.     $(opts.elements).not(curr).hide();
  813.     opts.cssBefore.opacity = 1;
  814.     opts.cssBefore.display = 'block';
  815.     if (opts.slideResize && w !== false && next.cycleW > 0)
  816.         opts.cssBefore.width = next.cycleW;
  817.     if (opts.slideResize && h !== false && next.cycleH > 0)
  818.         opts.cssBefore.height = next.cycleH;
  819.     opts.cssAfter = opts.cssAfter || {};
  820.     opts.cssAfter.display = 'none';
  821.     $(curr).css('zIndex',opts.slideCount + (rev === true ? 1 : 0));
  822.     $(next).css('zIndex',opts.slideCount + (rev === true ? 0 : 1));
  823. };
  824.  
  825. // the actual fn for effecting a transition
  826. $.fn.cycle.custom = function(curr, next, opts, cb, fwd, speedOverride) {
  827.     var $l = $(curr), $n = $(next);
  828.     var speedIn = opts.speedIn, speedOut = opts.speedOut, easeIn = opts.easeIn, easeOut = opts.easeOut;
  829.     $n.css(opts.cssBefore);
  830.     if (speedOverride) {
  831.         if (typeof speedOverride == 'number')
  832.             speedIn = speedOut = speedOverride;
  833.         else
  834.             speedIn = speedOut = 1;
  835.         easeIn = easeOut = null;
  836.     }
  837.     var fn = function() {$n.animate(opts.animIn, speedIn, easeIn, cb)};
  838.     $l.animate(opts.animOut, speedOut, easeOut, function() {
  839.         if (opts.cssAfter) $l.css(opts.cssAfter);
  840.         if (!opts.sync) fn();
  841.     });
  842.     if (opts.sync) fn();
  843. };
  844.  
  845. // transition definitions - only fade is defined here, transition pack defines the rest
  846. $.fn.cycle.transitions = {
  847.     fade: function($cont, $slides, opts) {
  848.         $slides.not(':eq('+opts.currSlide+')').css('opacity',0);
  849.         opts.before.push(function(curr,next,opts) {
  850.             $.fn.cycle.commonReset(curr,next,opts);
  851.             opts.cssBefore.opacity = 0;
  852.         });
  853.         opts.animIn    = { opacity: 1 };
  854.         opts.animOut   = { opacity: 0 };
  855.         opts.cssBefore = { top: 0, left: 0 };
  856.     }
  857. };
  858.  
  859. $.fn.cycle.ver = function() { return ver; };
  860.  
  861. // override these globally if you like (they are all optional)
  862. $.fn.cycle.defaults = {
  863.     fx:           'fade', // name of transition effect (or comma separated names, ex: 'fade,scrollUp,shuffle')
  864.     timeout:       4000,  // milliseconds between slide transitions (0 to disable auto advance)
  865.     timeoutFn:     null,  // callback for determining per-slide timeout value:  function(currSlideElement, nextSlideElement, options, forwardFlag)
  866.     continuous:    0,     // true to start next transition immediately after current one completes
  867.     speed:         1000,  // speed of the transition (any valid fx speed value)
  868.     speedIn:       null,  // speed of the 'in' transition
  869.     speedOut:      null,  // speed of the 'out' transition
  870.     next:          null,  // selector for element to use as event trigger for next slide
  871.     prev:          null,  // selector for element to use as event trigger for previous slide
  872. //  prevNextClick: null,  // @deprecated; please use onPrevNextEvent instead
  873.     onPrevNextEvent: null,  // callback fn for prev/next events: function(isNext, zeroBasedSlideIndex, slideElement)
  874.     prevNextEvent:'click.cycle',// event which drives the manual transition to the previous or next slide
  875.     pager:         null,  // selector for element to use as pager container
  876.     //pagerClick   null,  // @deprecated; please use onPagerEvent instead
  877.     onPagerEvent:  null,  // callback fn for pager events: function(zeroBasedSlideIndex, slideElement)
  878.     pagerEvent:   'click.cycle', // name of event which drives the pager navigation
  879.     allowPagerClickBubble: false, // allows or prevents click event on pager anchors from bubbling
  880.     pagerAnchorBuilder: null, // callback fn for building anchor links:  function(index, DOMelement)
  881.     before:        null,  // transition callback (scope set to element to be shown):     function(currSlideElement, nextSlideElement, options, forwardFlag)
  882.     after:         null,  // transition callback (scope set to element that was shown):  function(currSlideElement, nextSlideElement, options, forwardFlag)
  883.     end:           null,  // callback invoked when the slideshow terminates (use with autostop or nowrap options): function(options)
  884.     easing:        null,  // easing method for both in and out transitions
  885.     easeIn:        null,  // easing for "in" transition
  886.     easeOut:       null,  // easing for "out" transition
  887.     shuffle:       null,  // coords for shuffle animation, ex: { top:15, left: 200 }
  888.     animIn:        null,  // properties that define how the slide animates in
  889.     animOut:       null,  // properties that define how the slide animates out
  890.     cssBefore:     null,  // properties that define the initial state of the slide before transitioning in
  891.     cssAfter:      null,  // properties that defined the state of the slide after transitioning out
  892.     fxFn:          null,  // function used to control the transition: function(currSlideElement, nextSlideElement, options, afterCalback, forwardFlag)
  893.     height:       'auto', // container height
  894.     startingSlide: 0,     // zero-based index of the first slide to be displayed
  895.     sync:          1,     // true if in/out transitions should occur simultaneously
  896.     random:        0,     // true for random, false for sequence (not applicable to shuffle fx)
  897.     fit:           0,     // force slides to fit container
  898.     containerResize: 1,   // resize container to fit largest slide
  899.     slideResize:   1,     // force slide width/height to fixed size before every transition
  900.     pause:         0,     // true to enable "pause on hover"
  901.     pauseOnPagerHover: 0, // true to pause when hovering over pager link
  902.     autostop:      0,     // true to end slideshow after X transitions (where X == slide count)
  903.     autostopCount: 0,     // number of transitions (optionally used with autostop to define X)
  904.     delay:         0,     // additional delay (in ms) for first transition (hint: can be negative)
  905.     slideExpr:     null,  // expression for selecting slides (if something other than all children is required)
  906.     cleartype:     !$.support.opacity,  // true if clearType corrections should be applied (for IE)
  907.     cleartypeNoBg: false, // set to true to disable extra cleartype fixing (leave false to force background color setting on slides)
  908.     nowrap:        0,     // true to prevent slideshow from wrapping
  909.     fastOnEvent:   0,     // force fast transitions when triggered manually (via pager or prev/next); value == time in ms
  910.     randomizeEffects: 1,  // valid when multiple effects are used; true to make the effect sequence random
  911.     rev:           0,     // causes animations to transition in reverse (for effects that support it such as scrollHorz/scrollVert/shuffle)
  912.     manualTrump:   true,  // causes manual transition to stop an active transition instead of being ignored
  913.     requeueOnImageNotLoaded: true, // requeue the slideshow if any image slides are not yet loaded
  914.     requeueTimeout: 250,  // ms delay for requeue
  915.     activePagerClass: 'activeSlide', // class name used for the active pager link
  916.     updateActivePagerLink: null, // callback fn invoked to update the active pager link (adds/removes activePagerClass style)
  917.     backwards:     false  // true to start slideshow at last slide and move backwards through the stack
  918. };
  919.  
  920. })(jQuery);
  921.  
  922.  
  923. /*!
  924.  * jQuery Cycle Plugin Transition Definitions
  925.  * This script is a plugin for the jQuery Cycle Plugin
  926.  * Examples and documentation at: http://malsup.com/jquery/cycle/
  927.  * Copyright (c) 2007-2010 M. Alsup
  928.  * Version:  2.73
  929.  * Dual licensed under the MIT and GPL licenses:
  930.  * http://www.opensource.org/licenses/mit-license.php
  931.  * http://www.gnu.org/licenses/gpl.html
  932.  */
  933. (function($) {
  934.  
  935. //
  936. // These functions define one-time slide initialization for the named
  937. // transitions. To save file size feel free to remove any of these that you
  938. // don't need.
  939. //
  940. $.fn.cycle.transitions.none = function($cont, $slides, opts) {
  941.     opts.fxFn = function(curr,next,opts,after){
  942.         $(next).show();
  943.         $(curr).hide();
  944.         after();
  945.     };
  946. }
  947. // not a cross-fade, fadeout only fades out the top slide
  948. $.fn.cycle.transitions.fadeout = function($cont, $slides, opts) {
  949.     $slides.not(':eq('+opts.currSlide+')').css({ display: 'block', 'opacity': 1 });
  950.     opts.before.push(function(curr,next,opts,w,h,rev) {
  951.         $(curr).css('zIndex',opts.slideCount + (!rev === true ? 1 : 0));
  952.         $(next).css('zIndex',opts.slideCount + (!rev === true ? 0 : 1));
  953.     });
  954.     opts.animIn    = { opacity: 1 };
  955.     opts.animOut   = { opacity: 0 };
  956.     opts.cssBefore = { opacity: 1, display: 'block' };
  957.     opts.cssAfter  = { zIndex: 0 };
  958. };
  959.  
  960. // scrollUp/Down/Left/Right
  961. $.fn.cycle.transitions.scrollUp = function($cont, $slides, opts) {
  962.     $cont.css('overflow','hidden');
  963.     opts.before.push($.fn.cycle.commonReset);
  964.     var h = $cont.height();
  965.     opts.cssBefore ={ top: h, left: 0 };
  966.     opts.cssFirst = { top: 0 };
  967.     opts.animIn   = { top: 0 };
  968.     opts.animOut  = { top: -h };
  969. };
  970. $.fn.cycle.transitions.scrollDown = function($cont, $slides, opts) {
  971.     $cont.css('overflow','hidden');
  972.     opts.before.push($.fn.cycle.commonReset);
  973.     var h = $cont.height();
  974.     opts.cssFirst = { top: 0 };
  975.     opts.cssBefore= { top: -h, left: 0 };
  976.     opts.animIn   = { top: 0 };
  977.     opts.animOut  = { top: h };
  978. };
  979. $.fn.cycle.transitions.scrollLeft = function($cont, $slides, opts) {
  980.     $cont.css('overflow','hidden');
  981.     opts.before.push($.fn.cycle.commonReset);
  982.     var w = $cont.width();
  983.     opts.cssFirst = { left: 0 };
  984.     opts.cssBefore= { left: w, top: 0 };
  985.     opts.animIn   = { left: 0 };
  986.     opts.animOut  = { left: 0-w };
  987. };
  988. $.fn.cycle.transitions.scrollRight = function($cont, $slides, opts) {
  989.     $cont.css('overflow','hidden');
  990.     opts.before.push($.fn.cycle.commonReset);
  991.     var w = $cont.width();
  992.     opts.cssFirst = { left: 0 };
  993.     opts.cssBefore= { left: -w, top: 0 };
  994.     opts.animIn   = { left: 0 };
  995.     opts.animOut  = { left: w };
  996. };
  997. $.fn.cycle.transitions.scrollHorz = function($cont, $slides, opts) {
  998.     $cont.css('overflow','hidden').width();
  999.     opts.before.push(function(curr, next, opts, fwd) {
  1000.         if (opts.rev)
  1001.             fwd = !fwd;
  1002.         $.fn.cycle.commonReset(curr,next,opts);
  1003.         opts.cssBefore.left = fwd ? (next.cycleW-1) : (1-next.cycleW);
  1004.         opts.animOut.left = fwd ? -curr.cycleW : curr.cycleW;
  1005.     });
  1006.     opts.cssFirst = { left: 0 };
  1007.     opts.cssBefore= { top: 0 };
  1008.     opts.animIn   = { left: 0 };
  1009.     opts.animOut  = { top: 0 };
  1010. };
  1011. $.fn.cycle.transitions.scrollVert = function($cont, $slides, opts) {
  1012.     $cont.css('overflow','hidden');
  1013.     opts.before.push(function(curr, next, opts, fwd) {
  1014.         if (opts.rev)
  1015.             fwd = !fwd;
  1016.         $.fn.cycle.commonReset(curr,next,opts);
  1017.         opts.cssBefore.top = fwd ? (1-next.cycleH) : (next.cycleH-1);
  1018.         opts.animOut.top = fwd ? curr.cycleH : -curr.cycleH;
  1019.     });
  1020.     opts.cssFirst = { top: 0 };
  1021.     opts.cssBefore= { left: 0 };
  1022.     opts.animIn   = { top: 0 };
  1023.     opts.animOut  = { left: 0 };
  1024. };
  1025.  
  1026. // slideX/slideY
  1027. $.fn.cycle.transitions.slideX = function($cont, $slides, opts) {
  1028.     opts.before.push(function(curr, next, opts) {
  1029.         $(opts.elements).not(curr).hide();
  1030.         $.fn.cycle.commonReset(curr,next,opts,false,true);
  1031.         opts.animIn.width = next.cycleW;
  1032.     });
  1033.     opts.cssBefore = { left: 0, top: 0, width: 0 };
  1034.     opts.animIn  = { width: 'show' };
  1035.     opts.animOut = { width: 0 };
  1036. };
  1037. $.fn.cycle.transitions.slideY = function($cont, $slides, opts) {
  1038.     opts.before.push(function(curr, next, opts) {
  1039.         $(opts.elements).not(curr).hide();
  1040.         $.fn.cycle.commonReset(curr,next,opts,true,false);
  1041.         opts.animIn.height = next.cycleH;
  1042.     });
  1043.     opts.cssBefore = { left: 0, top: 0, height: 0 };
  1044.     opts.animIn  = { height: 'show' };
  1045.     opts.animOut = { height: 0 };
  1046. };
  1047.  
  1048. // shuffle
  1049. $.fn.cycle.transitions.shuffle = function($cont, $slides, opts) {
  1050.     var i, w = $cont.css('overflow', 'visible').width();
  1051.     $slides.css({left: 0, top: 0});
  1052.     opts.before.push(function(curr,next,opts) {
  1053.         $.fn.cycle.commonReset(curr,next,opts,true,true,true);
  1054.     });
  1055.     // only adjust speed once!
  1056.     if (!opts.speedAdjusted) {
  1057.         opts.speed = opts.speed / 2; // shuffle has 2 transitions
  1058.         opts.speedAdjusted = true;
  1059.     }
  1060.     opts.random = 0;
  1061.     opts.shuffle = opts.shuffle || {left:-w, top:15};
  1062.     opts.els = [];
  1063.     for (i=0; i < $slides.length; i++)
  1064.         opts.els.push($slides[i]);
  1065.  
  1066.     for (i=0; i < opts.currSlide; i++)
  1067.         opts.els.push(opts.els.shift());
  1068.  
  1069.     // custom transition fn (hat tip to Benjamin Sterling for this bit of sweetness!)
  1070.     opts.fxFn = function(curr, next, opts, cb, fwd) {
  1071.         if (opts.rev)
  1072.             fwd = !fwd;
  1073.         var $el = fwd ? $(curr) : $(next);
  1074.         $(next).css(opts.cssBefore);
  1075.         var count = opts.slideCount;
  1076.         $el.animate(opts.shuffle, opts.speedIn, opts.easeIn, function() {
  1077.             var hops = $.fn.cycle.hopsFromLast(opts, fwd);
  1078.             for (var k=0; k < hops; k++)
  1079.                 fwd ? opts.els.push(opts.els.shift()) : opts.els.unshift(opts.els.pop());
  1080.             if (fwd) {
  1081.                 for (var i=0, len=opts.els.length; i < len; i++)
  1082.                     $(opts.els[i]).css('z-index', len-i+count);
  1083.             }
  1084.             else {
  1085.                 var z = $(curr).css('z-index');
  1086.                 $el.css('z-index', parseInt(z)+1+count);
  1087.             }
  1088.             $el.animate({left:0, top:0}, opts.speedOut, opts.easeOut, function() {
  1089.                 $(fwd ? this : curr).hide();
  1090.                 if (cb) cb();
  1091.             });
  1092.         });
  1093.     };
  1094.     opts.cssBefore = { display: 'block', opacity: 1, top: 0, left: 0 };
  1095. };
  1096.  
  1097. // turnUp/Down/Left/Right
  1098. $.fn.cycle.transitions.turnUp = function($cont, $slides, opts) {
  1099.     opts.before.push(function(curr, next, opts) {
  1100.         $.fn.cycle.commonReset(curr,next,opts,true,false);
  1101.         opts.cssBefore.top = next.cycleH;
  1102.         opts.animIn.height = next.cycleH;
  1103.         opts.animOut.width = next.cycleW;
  1104.     });
  1105.     opts.cssFirst  = { top: 0 };
  1106.     opts.cssBefore = { left: 0, height: 0 };
  1107.     opts.animIn    = { top: 0 };
  1108.     opts.animOut   = { height: 0 };
  1109. };
  1110. $.fn.cycle.transitions.turnDown = function($cont, $slides, opts) {
  1111.     opts.before.push(function(curr, next, opts) {
  1112.         $.fn.cycle.commonReset(curr,next,opts,true,false);
  1113.         opts.animIn.height = next.cycleH;
  1114.         opts.animOut.top   = curr.cycleH;
  1115.     });
  1116.     opts.cssFirst  = { top: 0 };
  1117.     opts.cssBefore = { left: 0, top: 0, height: 0 };
  1118.     opts.animOut   = { height: 0 };
  1119. };
  1120. $.fn.cycle.transitions.turnLeft = function($cont, $slides, opts) {
  1121.     opts.before.push(function(curr, next, opts) {
  1122.         $.fn.cycle.commonReset(curr,next,opts,false,true);
  1123.         opts.cssBefore.left = next.cycleW;
  1124.         opts.animIn.width = next.cycleW;
  1125.     });
  1126.     opts.cssBefore = { top: 0, width: 0  };
  1127.     opts.animIn    = { left: 0 };
  1128.     opts.animOut   = { width: 0 };
  1129. };
  1130. $.fn.cycle.transitions.turnRight = function($cont, $slides, opts) {
  1131.     opts.before.push(function(curr, next, opts) {
  1132.         $.fn.cycle.commonReset(curr,next,opts,false,true);
  1133.         opts.animIn.width = next.cycleW;
  1134.         opts.animOut.left = curr.cycleW;
  1135.     });
  1136.     opts.cssBefore = { top: 0, left: 0, width: 0 };
  1137.     opts.animIn    = { left: 0 };
  1138.     opts.animOut   = { width: 0 };
  1139. };
  1140.  
  1141. // zoom
  1142. $.fn.cycle.transitions.zoom = function($cont, $slides, opts) {
  1143.     opts.before.push(function(curr, next, opts) {
  1144.         $.fn.cycle.commonReset(curr,next,opts,false,false,true);
  1145.         opts.cssBefore.top = next.cycleH/2;
  1146.         opts.cssBefore.left = next.cycleW/2;
  1147.         opts.animIn    = { top: 0, left: 0, width: next.cycleW, height: next.cycleH };
  1148.         opts.animOut   = { width: 0, height: 0, top: curr.cycleH/2, left: curr.cycleW/2 };
  1149.     });
  1150.     opts.cssFirst = { top:0, left: 0 };
  1151.     opts.cssBefore = { width: 0, height: 0 };
  1152. };
  1153.  
  1154. // fadeZoom
  1155. $.fn.cycle.transitions.fadeZoom = function($cont, $slides, opts) {
  1156.     opts.before.push(function(curr, next, opts) {
  1157.         $.fn.cycle.commonReset(curr,next,opts,false,false);
  1158.         opts.cssBefore.left = next.cycleW/2;
  1159.         opts.cssBefore.top = next.cycleH/2;
  1160.         opts.animIn = { top: 0, left: 0, width: next.cycleW, height: next.cycleH };
  1161.     });
  1162.     opts.cssBefore = { width: 0, height: 0 };
  1163.     opts.animOut  = { opacity: 0 };
  1164. };
  1165.  
  1166. // blindX
  1167. $.fn.cycle.transitions.blindX = function($cont, $slides, opts) {
  1168.     var w = $cont.css('overflow','hidden').width();
  1169.     opts.before.push(function(curr, next, opts) {
  1170.         $.fn.cycle.commonReset(curr,next,opts);
  1171.         opts.animIn.width = next.cycleW;
  1172.         opts.animOut.left   = curr.cycleW;
  1173.     });
  1174.     opts.cssBefore = { left: w, top: 0 };
  1175.     opts.animIn = { left: 0 };
  1176.     opts.animOut  = { left: w };
  1177. };
  1178. // blindY
  1179. $.fn.cycle.transitions.blindY = function($cont, $slides, opts) {
  1180.     var h = $cont.css('overflow','hidden').height();
  1181.     opts.before.push(function(curr, next, opts) {
  1182.         $.fn.cycle.commonReset(curr,next,opts);
  1183.         opts.animIn.height = next.cycleH;
  1184.         opts.animOut.top   = curr.cycleH;
  1185.     });
  1186.     opts.cssBefore = { top: h, left: 0 };
  1187.     opts.animIn = { top: 0 };
  1188.     opts.animOut  = { top: h };
  1189. };
  1190. // blindZ
  1191. $.fn.cycle.transitions.blindZ = function($cont, $slides, opts) {
  1192.     var h = $cont.css('overflow','hidden').height();
  1193.     var w = $cont.width();
  1194.     opts.before.push(function(curr, next, opts) {
  1195.         $.fn.cycle.commonReset(curr,next,opts);
  1196.         opts.animIn.height = next.cycleH;
  1197.         opts.animOut.top   = curr.cycleH;
  1198.     });
  1199.     opts.cssBefore = { top: h, left: w };
  1200.     opts.animIn = { top: 0, left: 0 };
  1201.     opts.animOut  = { top: h, left: w };
  1202. };
  1203.  
  1204. // growX - grow horizontally from centered 0 width
  1205. $.fn.cycle.transitions.growX = function($cont, $slides, opts) {
  1206.     opts.before.push(function(curr, next, opts) {
  1207.         $.fn.cycle.commonReset(curr,next,opts,false,true);
  1208.         opts.cssBefore.left = this.cycleW/2;
  1209.         opts.animIn = { left: 0, width: this.cycleW };
  1210.         opts.animOut = { left: 0 };
  1211.     });
  1212.     opts.cssBefore = { width: 0, top: 0 };
  1213. };
  1214. // growY - grow vertically from centered 0 height
  1215. $.fn.cycle.transitions.growY = function($cont, $slides, opts) {
  1216.     opts.before.push(function(curr, next, opts) {
  1217.         $.fn.cycle.commonReset(curr,next,opts,true,false);
  1218.         opts.cssBefore.top = this.cycleH/2;
  1219.         opts.animIn = { top: 0, height: this.cycleH };
  1220.         opts.animOut = { top: 0 };
  1221.     });
  1222.     opts.cssBefore = { height: 0, left: 0 };
  1223. };
  1224.  
  1225. // curtainX - squeeze in both edges horizontally
  1226. $.fn.cycle.transitions.curtainX = function($cont, $slides, opts) {
  1227.     opts.before.push(function(curr, next, opts) {
  1228.         $.fn.cycle.commonReset(curr,next,opts,false,true,true);
  1229.         opts.cssBefore.left = next.cycleW/2;
  1230.         opts.animIn = { left: 0, width: this.cycleW };
  1231.         opts.animOut = { left: curr.cycleW/2, width: 0 };
  1232.     });
  1233.     opts.cssBefore = { top: 0, width: 0 };
  1234. };
  1235. // curtainY - squeeze in both edges vertically
  1236. $.fn.cycle.transitions.curtainY = function($cont, $slides, opts) {
  1237.     opts.before.push(function(curr, next, opts) {
  1238.         $.fn.cycle.commonReset(curr,next,opts,true,false,true);
  1239.         opts.cssBefore.top = next.cycleH/2;
  1240.         opts.animIn = { top: 0, height: next.cycleH };
  1241.         opts.animOut = { top: curr.cycleH/2, height: 0 };
  1242.     });
  1243.     opts.cssBefore = { left: 0, height: 0 };
  1244. };
  1245.  
  1246. // cover - curr slide covered by next slide
  1247. $.fn.cycle.transitions.cover = function($cont, $slides, opts) {
  1248.     var d = opts.direction || 'left';
  1249.     var w = $cont.css('overflow','hidden').width();
  1250.     var h = $cont.height();
  1251.     opts.before.push(function(curr, next, opts) {
  1252.         $.fn.cycle.commonReset(curr,next,opts);
  1253.         if (d == 'right')
  1254.             opts.cssBefore.left = -w;
  1255.         else if (d == 'up')
  1256.             opts.cssBefore.top = h;
  1257.         else if (d == 'down')
  1258.             opts.cssBefore.top = -h;
  1259.         else
  1260.             opts.cssBefore.left = w;
  1261.     });
  1262.     opts.animIn = { left: 0, top: 0};
  1263.     opts.animOut = { opacity: 1 };
  1264.     opts.cssBefore = { top: 0, left: 0 };
  1265. };
  1266.  
  1267. // uncover - curr slide moves off next slide
  1268. $.fn.cycle.transitions.uncover = function($cont, $slides, opts) {
  1269.     var d = opts.direction || 'left';
  1270.     var w = $cont.css('overflow','hidden').width();
  1271.     var h = $cont.height();
  1272.     opts.before.push(function(curr, next, opts) {
  1273.         $.fn.cycle.commonReset(curr,next,opts,true,true,true);
  1274.         if (d == 'right')
  1275.             opts.animOut.left = w;
  1276.         else if (d == 'up')
  1277.             opts.animOut.top = -h;
  1278.         else if (d == 'down')
  1279.             opts.animOut.top = h;
  1280.         else
  1281.             opts.animOut.left = -w;
  1282.     });
  1283.     opts.animIn = { left: 0, top: 0 };
  1284.     opts.animOut = { opacity: 1 };
  1285.     opts.cssBefore = { top: 0, left: 0 };
  1286. };
  1287.  
  1288. // toss - move top slide and fade away
  1289. $.fn.cycle.transitions.toss = function($cont, $slides, opts) {
  1290.     var w = $cont.css('overflow','visible').width();
  1291.     var h = $cont.height();
  1292.     opts.before.push(function(curr, next, opts) {
  1293.         $.fn.cycle.commonReset(curr,next,opts,true,true,true);
  1294.         // provide default toss settings if animOut not provided
  1295.         if (!opts.animOut.left && !opts.animOut.top)
  1296.             opts.animOut = { left: w*2, top: -h/2, opacity: 0 };
  1297.         else
  1298.             opts.animOut.opacity = 0;
  1299.     });
  1300.     opts.cssBefore = { left: 0, top: 0 };
  1301.     opts.animIn = { left: 0 };
  1302. };
  1303.  
  1304. // wipe - clip animation
  1305. $.fn.cycle.transitions.wipe = function($cont, $slides, opts) {
  1306.     var w = $cont.css('overflow','hidden').width();
  1307.     var h = $cont.height();
  1308.     opts.cssBefore = opts.cssBefore || {};
  1309.     var clip;
  1310.     if (opts.clip) {
  1311.         if (/l2r/.test(opts.clip))
  1312.             clip = 'rect(0px 0px '+h+'px 0px)';
  1313.         else if (/r2l/.test(opts.clip))
  1314.             clip = 'rect(0px '+w+'px '+h+'px '+w+'px)';
  1315.         else if (/t2b/.test(opts.clip))
  1316.             clip = 'rect(0px '+w+'px 0px 0px)';
  1317.         else if (/b2t/.test(opts.clip))
  1318.             clip = 'rect('+h+'px '+w+'px '+h+'px 0px)';
  1319.         else if (/zoom/.test(opts.clip)) {
  1320.             var top = parseInt(h/2);
  1321.             var left = parseInt(w/2);
  1322.             clip = 'rect('+top+'px '+left+'px '+top+'px '+left+'px)';
  1323.         }
  1324.     }
  1325.  
  1326.     opts.cssBefore.clip = opts.cssBefore.clip || clip || 'rect(0px 0px 0px 0px)';
  1327.  
  1328.     var d = opts.cssBefore.clip.match(/(\d+)/g);
  1329.     var t = parseInt(d[0]), r = parseInt(d[1]), b = parseInt(d[2]), l = parseInt(d[3]);
  1330.  
  1331.     opts.before.push(function(curr, next, opts) {
  1332.         if (curr == next) return;
  1333.         var $curr = $(curr), $next = $(next);
  1334.         $.fn.cycle.commonReset(curr,next,opts,true,true,false);
  1335.         opts.cssAfter.display = 'block';
  1336.  
  1337.         var step = 1, count = parseInt((opts.speedIn / 13)) - 1;
  1338.         (function f() {
  1339.             var tt = t ? t - parseInt(step * (t/count)) : 0;
  1340.             var ll = l ? l - parseInt(step * (l/count)) : 0;
  1341.             var bb = b < h ? b + parseInt(step * ((h-b)/count || 1)) : h;
  1342.             var rr = r < w ? r + parseInt(step * ((w-r)/count || 1)) : w;
  1343.             $next.css({ clip: 'rect('+tt+'px '+rr+'px '+bb+'px '+ll+'px)' });
  1344.             (step++ <= count) ? setTimeout(f, 13) : $curr.css('display', 'none');
  1345.         })();
  1346.     });
  1347.     opts.cssBefore = { display: 'block', opacity: 1, top: 0, left: 0 };
  1348.     opts.animIn    = { left: 0 };
  1349.     opts.animOut   = { left: 0 };
  1350. };
  1351.  
  1352. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement