/*
* jwSlider v1 - http://www.jeffrey-way.com
* Last Updated: October 29, 2009

* This is a very simple and convenient slider/fader to transition between images or content. it offers only fade and slide transitions to keep the script
* as lightweight as possible.

* Developed by Jeffrey Way
* http://www.jeffrey-way.com
* jeffrey@effrey-way.com

* This is an edited version of the original slider. Edited by Giovanni DiFeterici
*/


(function() {
	
	$.fn.jwSlider = function(options) {
		var defaults = 
		{
			speed : 3200,
			pause : 6100,
			transition : 'fade'
		},

		options = $.extend(defaults, options);
		
		if(options.pause <= options.speed) 
		{
			options.pause = options.speed + 100;
		}	
		
		return this.each(function() {								
			
			var $this = $(this)						
			
			if(options.transition === 'fade') 			
			{
				for(var i = $this.children().length, y = 0; i > 0; i--, y++) 
				{ 		
					$this.children().eq(y).css('zIndex', i + 79999);
				}									
				fade();
			}

			function fade() {
				setInterval(function() {
					$this.children(':first').animate({'opacity' : 0}, options.speed, function() {	
						$this
						   .children(':first')		
						   .css('opacity', 1) 			
						   .css('zIndex', $this.children(':last').css('zIndex') - 1) 				
						   .appendTo($this); 			
					})
				}, options.pause);
			} // end fade		
		}); // end each		
	} // End plugin.
})(jQuery);