// +----------
// | jQuery infiniteSlider Lite v1.0
// | Author: Kai Johnson
// | Author URI: www.goldentreestudio.com
// +----------

(function($){ // Begin plugin
	
	$.infiniteSliderLite = function(el, t){ // Define the independent function
		var iSL = this; // Avoid scope issues
		iSL.$el = $(el); // parent element
		iSL.$panels = iSL.$el.children(); // set of sliding elements
		iSL.$clone = iSL.$panels.children().clone().appendTo(iSL.$panels); // Clone the sliding set and append to it
		
		iSL.slideW = iSL.$clone.width() * iSL.$clone.length; // Calc the width to slide
		iSL.time = typeof(t) == "undefined" ? 10000 : t; // Variable passed through function defines the time to animate set
		
		iSL.move = function(slideTime){ // Check the position, reset if necessary, run the animation			
			iSL.$panels.animate({'left' : '-'+iSL.slideW+'px'}, slideTime, "linear", function(){
				iSL.$panels.animate({'left':'0'},0); // Reset without pause for "infinite" effect
				iSL.move(iSL.time); // Continue sliding at the default time distance
			}); // Animate time must be less than setInterval time and more than 0 for webkit speed control!
		}
				
		iSL.$panels.hover(function(){ // Pause on hover
			iSL.timeLeft = ((iSL.slideW - Math.abs(iSL.$panels.position().left)) / iSL.slideW) * iSL.time; // Calc time left to complete 1 animation cycle
			iSL.$panels.stop(); // Stop the animation
		}, function(){
			iSL.move(iSL.timeLeft); // Restart the animation with the remaining time
		});
		
		iSL.move(iSL.time); // Get it moving
	}
	
	$.fn.infiniteSliderLite = function(t){ // Support multiple instances
		var iSLel = this;
		return iSLel.each(function(){
			new $.infiniteSliderLite(iSLel, t);
		});
	}

 })(jQuery);
