(function($) {
	
	$.fn.jSlideshow = function(options) {
		
		var defaults = {
			time_wait: 5,
			time_fade: 1
		};
		
		var active = null;
		var timer = null;
		
		var methods = {
		
			start: function() {
				timer = setInterval(this.rotate, (options.time_wait + options.time_fade) * 1000);
			},
			
			stop: function () {
				
			},
			
			rotate: function() {
				active = elem.children('.active');
				var next = active.next();
				if (next.length == 0) {
					next = elem.children('.first');
				}
				active.fadeOut({duration: options.time_fade * 1000, complete: function(){$(this).removeClass('active')}});
				next.fadeIn({duration: options.time_fade * 1000, complete: function(){$(this).addClass('active')}});
				active = next;
			}
			
		}
		
		var options = $.extend({}, defaults, options || {});
		var elem = this.find('ul').first();
		elem.addClass('jSlideshow');
		elem.children('li').addClass('jSlideshow-item').first().addClass('first active');
		var height = elem.find('li').outerHeight();
		elem.css('height', height);
		methods.start();
	};
	
})(jQuery);
