var Testimonials =
{
	testimonials: new Array(
	"<p><strong>Billing Coordinator for Major Metro-Atlanta Physicians Group</strong></p>\n<p>Before we found CBA, I was searching for a new agency every year trying to find a permanent collection solution. We have been with CBA for 7 years now and our AR has never been in better shape. I recommend them to my colleagues on a regular basis and I am proud to recommend them here.</p>",
	"<p><strong>CFO of Local Telecom, Cable and Internet Provider</strong></p>\n<p>Our company has used CBA for over thirteen years. We often have other vendors approach us asking for an opportunity to win our business, but none of them have been able to equal the high level of return and professional representation that CBA provides. We regularly endorse their services to anyone in our industry who is in need of quality collections.</p>"),
	current: -1,
	heightDifference: 0,
	
	getCurrent: function()
	{
		return Testimonials.testimonials[Testimonials.current];
	},
	
	startScroll: function()
	{
		var T = $("#scrolling-testimonials .wrap .testimonial");

		T.animate({ top: "-" + Testimonials.heightDifference + "px" }, Testimonials.heightDifference * 100, "linear", function() { setTimeout(Testimonials.fadeOut, 7000); });
	},
	
	fadeOut: function()
	{
		var T = $("#scrolling-testimonials .wrap .testimonial");
		
		T.fadeOut(500, Testimonials.setupNext);
	},
	
	setupNext: function(fade)
	{
		++Testimonials.current;
		
		if(Testimonials.current >= Testimonials.testimonials.length)
			Testimonials.current = 0;
		
		var T = $("#scrolling-testimonials .wrap .testimonial");
		
		T.css("top", 0).empty().html(Testimonials.getCurrent());
		
		if(arguments.length == 0 || arguments[0])
			T.fadeIn(500);

		var ContainerHeight = $("#scrolling-testimonials").height();
		var InnerHeight = T.outerHeight();

		Testimonials.heightDifference = InnerHeight - ContainerHeight;

		if(Testimonials.heightDifference > 0)
			setTimeout(Testimonials.startScroll, 5000);
		else
			setTimeout(Testimonials.fadeOut, 5000);
	}
};

$(document).ready(function()
{
	Testimonials.setupNext(false);
});
