/* ------------------------------------------------------------------------------------
JQuery plugin - Simple fadeout/fadein effect for series of elements
Version: 1.1
Author: Tom Adams, Reading Room
Last update: Feb 2010
Changes
	1.1 added a check so that it doesn't run if there's only one item
------------------------------------------------------------------------------------ */
(function($) {
$.fn.rrSimpleSlideshow = function(options) {
	//options
	var defaults = {
		fadeSpeed: "slow", //speed of fadein and fadeout - can be a jquery keyword, or a number (milliseconds)
		pauseTime: 6000, // length of time that images stay after fadein (milliseconds)
		slideElement: "div" //individual elements divs within the slidewhow - each one of these will become a 'slide'
	};
	var options = $.extend(defaults, options);

	return this.each(function() {
		$this = $(this);

		if($this.find(options.slideElement).size() > 1) {

			//ensure the slides are hidden
			$this.find(options.slideElement).hide()
			
			//show the first slide, add on state
			$this.find(options.slideElement+":eq(0)").addClass("on").fadeIn(options.fadeSpeed);
			
			//set time interval
			runSlideshow = setInterval( "fnSlideSwitch()", options.pauseTime )
	
			//
			fnSlideSwitch = function(){
				$this.find(" "+options.slideElement+".on").fadeOut(options.fadeSpeed, function(){
		
					$this.find(" "+options.slideElement+".on").removeClass("on").next().addClass("on").fadeIn(options.fadeSpeed);
					//check if that was the last item
					if ($this.find(" "+options.slideElement+".on").length==0){
						//fnStopSlideShow();
						$this.find(" "+options.slideElement+":eq(0)").addClass("on").fadeIn(options.fadeSpeed);
					};
				});
			};
			fnStopSlideShow = function(){
				clearInterval(runSlideshow);
				fnSlideshow();
			};
		};
	});
		
};
})(jQuery);

