// JavaScript Document

var autoRotate = true;
var selectTestimonial = 1;
var currentRotation;

function showTestimonial(itmNbr){
	var displayTestimonial = document.getElementById('test'+itmNbr);
	if(displayTestimonial != undefined)
	{
		var i;
		for (i=1; i<=5; i++){
			document.getElementById('test'+i).className = 'hide';
		}
		displayTestimonial.className = 'testimonialTable';
		if (autoRotate){
			RotateTestimonials();
		}	
		selectTestimonial = itmNbr;
	}
}
function RotateTestimonials(){
	if (autoRotate){
		selectTestimonial ++;
		if (selectTestimonial > 5)
			selectTestimonial = 1;
		var string="showTestimonial("+selectTestimonial+")";
		currentRotation = setTimeout(string,2500);
	}	
}
function toggleTestimonialPlayer(pOrP){
	var playerImg = document.getElementById('testimonialPlayerButton');
	
	if(playerImg!=undefined)
	{
		if (pOrP == 'pause'){
				autoRotate = false;
				window.clearTimeout(currentRotation);
				playerImg.src = '/widgets/beforeAfter/images/play.gif';
			}	
		else{
		 
			if (autoRotate){
				autoRotate = false;
				window.clearTimeout(currentRotation);
				playerImg.src = '/widgets/beforeAfter/images/play.gif';
				
			}
			else{
				autoRotate = true;
				playerImg.src = '/widgets/beforeAfter/images/pause.gif';
				RotateTestimonials();
			}
		}		
	}
}

/* add to onload event */
if(window.addEventListener) window.addEventListener("load",RotateTestimonials,null);
else if(window.attachEvent) window.attachEvent('onload',RotateTestimonials);
else window['onload']=RotateTestimonials;
