var testimonialsArray;
var divCounter = 0;
var myInterval;
var numberOfTestimonials;
var currentDiv;
var nextDiv;
var toggleButton;
var isPlaying=true;

function changeDiv() {
	if (divCounter==numberOfTestimonials-1) {
		divCounter=0;
 		nextDiv= testimonialsArray[0];
	} else {
 		nextDiv= testimonialsArray[divCounter];
	}
	currentDiv.style.display= 'none';
	nextDiv.style.display= 'block';
}

function goNext() {
	currentDiv = testimonialsArray[divCounter];
		divCounter++;
	if (divCounter==numberOfTestimonials) {
		divCounter=0;
 		nextDiv= testimonialsArray[0];
	} else {
 		nextDiv= testimonialsArray[divCounter];
 		
	}

	currentDiv.style.display= 'none';
	nextDiv.style.display= 'block';
	}

function pause() {
isPlaying=false;
   //toggleButton.src = "images/play_up.gif";
	window.clearInterval(myInterval);
 }
	
function next() {
  if(isPlaying) {
         pause();
         }
	goNext();
}



function goPrev() {
		currentDiv = testimonialsArray[divCounter];
		divCounter--;
	if (divCounter==-1) {
		divCounter=numberOfTestimonials-1;
 		nextDiv= testimonialsArray[divCounter];
	} else {
 		nextDiv= testimonialsArray[divCounter];
 		
	}
	currentDiv.style.display= 'none';
	nextDiv.style.display= 'block';
	}

function prev() {
	  if(isPlaying) {
         pause();
		   
         }
	goPrev();
	}


 
function play() {
   //toggleButton.src="images/pause_up.gif";
	isPlaying=true;
	myInterval = setInterval(goNext,20000);
}
	
function initRollovers() {
   if (!document.getElementById) {
      return;
      }
   var prevOver = new Image();
   prevOver.src = "images/back_down.gif";
   var pauseOver = new Image();
   pauseOver.src = "images/pause_down.gif";
   var nextOver = new Image();
   nextOver.src = "images/next_down.gif";
   var playOver = new Image();
   playOver.src = "images/play_down.gif";
   var playUp= new Image();
   playUp.src = "images/play_up.gif";

   /*document.getElementById('playPauseLink').onclick = function() {
      if(isPlaying) {
         pause();
         }
      else {
         play();
         isPlaying = true;
         }
      return false;
      };
   toggleButton.onmouseover = function() {
      if(isPlaying) {
         toggleButton.src = "images/pause_down.gif";
         }
      else {
         toggleButton.src = "images/play_down.gif";
         }
      };
   toggleButton.onmouseout = function() {
      if(isPlaying) {
         toggleButton.src = "images/pause_up.gif";
         }
      else {
         toggleButton.src = "images/play_up.gif";
         }
      };
   }*/
}

function changeImg( imgName, imgLocation ){
document.getElementById(imgName).src = imgLocation;
}

function cycleDivs() {
	testimonialsArray= document.getElementById('testimonials').getElementsByTagName('div');
	numberOfTestimonials = testimonialsArray.length;
	currentDiv= testimonialsArray[0];
	toggleButton=document.getElementById('tPlayPause');
	play();
	initRollovers();
}

window.onload=cycleDivs;





