var numTestimonials = 0;
var animateTestimonials = true;

function initTestimonial(){
	// find out how many testimonials we have
	numTestimonials = $("#success_content div").length;

	// assign mouseover event to stop animation
	$("#success_content div").mouseover(
		function(){
			animateTestimonials = false;	
		}
	);
	// assign mouseout event to reenable animation
	$("#success_content div").mouseout(
		function(){
			animateTestimonials = true;	
		}
	);
		
	// show first one
	showTestimonial(1);
} 

function showTestimonial(thisTestimonial){	
	// this function needs to hide the previously showing testimonial
	// and show the one specified by index
	
	if(animateTestimonials){
		// only do it if animation hasn't been disabled
		
		// work out the index of the previously showing testimonial
		var previousTestimonial = thisTestimonial - 1;
		if(previousTestimonial == 0){
			previousTestimonial = numTestimonials;
		}	
		
		// work out the index of the next testimonial
		var nextTestimonial = thisTestimonial + 1;
		if(nextTestimonial > numTestimonials){
			nextTestimonial = 1;
		}	
		
		// hide the currently showing testimonial
		$("#testimonial" + previousTestimonial).fadeOut(1000,
			function(){
				// when fadeOut finished call fadeIn for this testimonial
				$("#testimonial" + thisTestimonial).fadeIn(1000,
					// when fadeIn finished set timer to show next testimonial
					function(){
						setTimeout("showTestimonial(" + nextTestimonial + ")", 3000);	
					}						
				);		
			}
		);	
	} else {
		setTimeout("showTestimonial(" + index + ")", 3000);	
	}	
}