var TestimonialRotator = function()
{
	var numberOfItems = null;
	var currentItem = null;
	var currentTicket = null;

	this.init = function()
	{
		this.numberOfItems = $('#testimonials .testimonial').length;
		
		if(this.numberOfItems > 0)
		{
			this.currentItem = 1;
			this.start();
		}
	}
	
	this.start = function()
	{
		var ref = this;
		this.currentTicket = setTimeout(function(){
			ref.showNext();
		}, 5000);
	}
	
	this.showNext = function()
	{
		var next = this.currentItem + 1;
		if(next > this.numberOfItems)
		{
			next = 1;
		}
		
		this.switchTo(next);
	}
	
	this.switchTo = function(itemNumber)
	{
		this.stop();
		
		var oldItem = this.currentItem;
		
		$('#testimonial-' + itemNumber).fadeIn('slow');
		$('#testimonial-' + oldItem).fadeOut('slow');
		this.currentItem = itemNumber;
		
		this.start();
	}
	
	this.stop = function()
	{
		clearTimeout(this.currentTicket);
	}
}
