(function($){
	
	$.fn.slideshow = function( options ){
		
		var settings = {
				speed : 500,
				duration : 2000
		};
		
		var opts = $.extend( settings , options );
		
		return this.each(function(){

			var $slides = $(this).find("img"),
			
				total = $slides.size(),
				current = $slides.eq(0).is(":visible")?0:-1;
			
			function next(){
			
				var n = current + 1;
			
				if( n == total ) n = 0;
			
				if( current !== -1 )
					$slides.eq(current).fadeOut(opts.speed);
				
				$slides.eq(n).fadeIn(opts.speed,function(){
			
					current = n;
					
					setTimeout( function(){
						next();
					} , opts.duration );
				});
			}
			
			next();
			
		})

	}

})(jQuery);
