/*
* jamSlider v1 - http://www.jamback.se
*/

(function($) {
	$.fn.jamSlider = function(options) {
		var defaults = {
			speed : 1000,
			pause : 2000,
			transition : 'fade'
		},
		options = $.extend(defaults, options);

		if(options.pause <= options.speed) options.pause = options.speed + 100;
		return this.each(function() {
			var $this = $(this);
			$this.wrap('<div class="slider-wrap" />');
			
			$this.css({
				'position' : 'relative',
				'padding' : 0
			});

			$this.children().css({
				'width' : $this.children().width(),
				'position' : 'absolute',
				'left' : 0
			});
			
			for(var i = $this.children().length, y = 0; i > 0; i--, y++) { 		
				$this.children().eq(y).css('zIndex', i + 9999);
			}	
			fade();


			function fade() {
				setInterval(function() {
					$this.children(':first').animate({'opacity' : 0}, options.speed, function() {	
						$this
						   .children(':first')
						   .css('opacity', 1) // Return opacity back to 1 for next time.
						   .css('zIndex', $this.children(':last').css('zIndex') - 1) // Reduces zIndex by 1 so that it's no longer on top.					
						   .appendTo($this); // move it to the end of the line.
					})
				}, options.pause);
			} // end fade			
		}); // end each		
	}
})(jQuery);