var timer = 0;							// keep track of time
var okayToGo = true;					// false locks the animation function while animation is in progress
var forwardBackward = 1;				// normal (1) or reverse (-1)
var currentReview = 0;
var newTransferBox = 1;
var oldTransferBox = 2;

function containerSwitch(thenewReview)
{
  newTransferBox = (newTransferBox == 1) ? 2 : 1;
  oldTransferBox = (oldTransferBox == 1) ? 2 : 1;
  document.getElementById("quoteDiv_"+newTransferBox).innerHTML = thenewReview.quote;
}


function itemSlideShow(prevOrNext)		// function used in Review Box Navigation
{
  if (okayToGo)							
  {
    newReview = currentReview + prevOrNext;						
    if (newReview >= quoteArray.length) newReview = 0;			
    else if (newReview < 0) newReview = quoteArray.length -1;	
    forwardBackward = prevOrNext;								
    moveItem(newReview);										
  }
}

function moveItem(clickedReview)								// Moving TransferBox
{
  if(okayToGo && clickedReview != currentReview)				
  {
    containerSwitch(quoteArray[clickedReview]);
	newReview = clickedReview;		
	
	// changes style of Z-index to slide new quoteDiv behind old quoteDiv when clicking next link or list link
	document.getElementById("transferBox_"+newTransferBox).style.zIndex = 50+10*forwardBackward;
	
	// changes style of Z-index to slide old quoteDiv in front new quoteDiv when clicking previous link
	document.getElementById("transferBox_"+oldTransferBox).style.zIndex = 50+20*forwardBackward;
	
	startTheMove = window.setInterval("rightOrLeft()",20);		
  }
}

function rightOrLeft()											// Moves the transferBox left and right
{
  if (timer == 1020)											
  {
    window.clearInterval(startTheMove);							// stops the animation at the end of it's cycle
	timer = 0;													// reset the following 4 parameters
	forwardBackward = 1;										
	currentReview = newReview;									
    okayToGo = true;											
  }
  else
  {
    okayToGo = false;											// lock the quoteDiv from changing to other quotes
	thisAngle = (Math.PI/2)*(timer/1000);						// sine and cosine curves - 0 to 1.5708 (90 degrees)
	
	// X,Y cords for newTransferBox Div
	document.getElementById("transferBox_"+newTransferBox).style.left = " "+(700-Math.sin(thisAngle)*700)+"px";
	document.getElementById("transferBox_"+newTransferBox).style.top = " "+(35-(forwardBackward*Math.cos(thisAngle)*55))+"px";
	
	// X,Y cords for oldTransferBox Div
	document.getElementById("transferBox_"+oldTransferBox).style.left = " "+(715-Math.sin(thisAngle+Math.PI/2)*700)+"px";
	document.getElementById("transferBox_"+oldTransferBox).style.top = " "+(35-(forwardBackward*Math.cos(thisAngle+Math.PI/2)*55))+"px";
	timer += 20;												//increase the timekeeper
  }
}