/**
 * Profitroom
 * @author Bartlomiej Fryzowicz and others
 */

function Rotator(parent,box,n,delay){
this.parent=$(parent);
this.box=$(box);
this.delay=delay; 
this.n=n;
this.total=this.box.length;
var i=0;
var x=this.total-1;
var t=this;
if(this.box.length>this.n)
{
	this.Interval=setInterval(
			function (){
			if(i==t.n) i=0;
			if (x==(t.n-1)) x=t.total-1;
				t.box=$(box);
				var last=t.box[x];
				var actual=t.box[i];	
				$(actual).fadeTo('slow', 0, function() 
					{
						var targetHeight = $(last).height();
						$(last)
							.css({
								  'opacity': 0
								, 'height': $(this).height()
							})
							.animate({
								  'opacity': 1
								, 'height': targetHeight
							}, 'slow')
							.insertBefore(actual)

						$(actual).appendTo(t.parent); 
					}
				);
				i++;
				x--;
			},
		this.delay);
		}
	}
