﻿/**
 * jQuery image cycle plugin - $.fn.imgCycle
 * Will rotate through images passed in via imgs array
 *
 * To be called by wrapping element
 * EXAMPLE
 * html: 
 * <div id="cycle-container"></div>
 * 
 * script: 
 * $(function() { 
 *   var imgs = [ 'cycle/1.jpg', 'cycle/2.jpg', 'cycle/3.jpg', 'cycle/4.jpg' ];
 *   $('#cycle-container').imgCycle(imgs);
 * });
 *
 * Accepts 4options:
 * 1. startRandom - default is true.  Will select a random position in the array of images to start displaying.
 * 2. interval - default is 5000 (5 seconds).  The time between rotation calls.
 * 3. speedOut - default is 1000 (1 second). The time it takes to fade out the current image.
 * 4. speedIn - default is 1250 (1 1/4 seconds). The time it takes to fade in the new image.
 *
 * Override options:
 * $(function() { 
 *   var imgs = [ 'cycle/1.jpg', 'cycle/2.jpg', 'cycle/3.jpg', 'cycle/4.jpg' ];
 *   var opts = {
 *     startRandom: false,
 *     interval: 2500,
 *     speedOut: 1500,
 *     speedIn: 1750
 *   };
 *   $('#cycle-container').imgCycle(imgs, opts);
 * });
 *
 * @author: Jeremy Burton (jermbo002@gmail.com)
 * @date: 20 January 2010
 * ------------------------------------------------------------------------------------------------------------*/


(function(a){a.fn.imgCycle=function(f,j){var c={startRandom:true,interval:5E3,speedOut:1E3,speedIn:1250};c=a.extend(c,j);return this.each(function(){if(f.length>0){var d=f.length,h=a(this).attr("id"),g=a(this),b;g.css("position","relative");if(c.startRandom){b=Math.floor(Math.random()*d);for(var e=0;e<d;e++){if(b>=d)b-=d;a("<img>").attr("src","/images/"+f[b++]).css("position","absolute").hide().appendTo(g)}b=1}else{b=1;for(e=0;e<d;e++)a("<img>").attr("src","/images/"+f[e]).css("position","absolute").hide().appendTo(g)}var i= a("#"+h+" img:first").show();setInterval(function(){i.fadeOut(c.speedOut);if(++b>d)b=1;a("#"+h+" img:eq("+(b-1)+")").fadeIn(c.speedIn,function(){i=a(this)})},c.interval)}else window.console&&console.log&&console.log("No images provided.")})}})(jQuery);