(function($) {
	$.fn.rotate = function(options) {
		
		var total = $(this).children().length - 1;
		
		var defaults = {
		 	end: total,
			which: 0,
			prev: total,
			pause: 8000,
			fadeSpeed: 2000,
			type: 'fade'
		};
			
		var options = $.extend(defaults, options);
			
		return this.each(function() {
			
			$kids = $(this).children();
			
			if ($kids.length > 1) {
			
				if (options.type == 'fade') { $kids.hide().eq(options.which).show(); }
				if (options.type == 'animate') { $kids.animate({opacity: 0}, 0).eq(options.which).animate({opacity: 1}, 0); }
				
				
				(function fadeit() {
					
					if (options.type == 'fade') {
						$kids.eq(options.prev).fadeOut(options.fadeSpeed);
						$kids.eq(options.which).fadeIn(options.fadeSpeed);
					}
					 
					if (options.type == 'animate') {
						$kids.eq(options.prev).animate({opacity: 0}, options.fadeSpeed);
						$kids.eq(options.which).animate({opacity: 1}, options.fadeSpeed);
					}
					
					options.which = (options.which == options.end) ? 0 : options.which+1;
					options.prev = (options.which == 0) ? options.end : options.which-1;
					
					setTimeout(fadeit, options.pause);
					
				})();
			
			}
				
		});
	};
})(jQuery);
