/*
 *  jquery.rotator
 *  Version: 0.1
 */
 
(function($){ $.fn.rotator = function(options){

	var defaults = {
		duration: 5000,   // time between animations
		animate: 500,    // animation speed
		n: 1,             // number of items to display at a time
		autoHeight: false // change height for each scroll
	};
	
	// OVERRIDE DEFAULTS
	var options = $.extend(defaults, options);

	
	return this.each(function(index) {

		var $this = $(this);

		var initialHeight = 0;
		
		$this.children().filter(":lt("+options.n+")").each(function(index,item){
			initialHeight += $(item).height();
		});

		$this.height(initialHeight);

		setInterval(function() {

			var childHeight = $this.children().filter(":first-child").height();
			var animParams = {scrollTop: (childHeight) + "px"};
			var autoHeight = 0;
			
			$this.children().filter(":lt("+(options.n+1)+")").each(function(index,item){
				if(index>0)autoHeight += $(item).height();
			});
			
			if(options.autoHeight) animParams = $.extend({height:(autoHeight) + "px"}, animParams);

			$this.animate(animParams, options.animate, function(){
				$this.scrollTop(0);
				$this.append($this.children().filter(":first-child"));
				$this.css("overflow","hidden"); //Chrome hack
			});
		}, options.duration);
	});
}})(jQuery);

