currentLoc = 5
totalMoves = 0
totalRight = 0

function pkTest()
{
   randomNum = Math.floor((Math.random() * 2))
   if (randomNum == 0)
   {
      if (currentLoc == 1)
	  {
	     currentLoc = 9
	  }
	  else
	  {
	     currentLoc--
	  }
	  swapLeft(currentLoc)
   }
   else
   {
      if (currentLoc == 9)
	  {
	     currentLoc = 1
	  }
	  else
	  {
	     currentLoc++
	  }
	  totalRight++
	  swapRight(currentLoc)
   }
   totalMoves++
   if (totalMoves == 24)
   {
      message = "This score is chance."
	  if (totalRight <= 12)
	  {
	     message = "This score is not significant."
	  }
	  else if (totalRight <= 17)
	  {
	     message = "This score is slighly significant."
	  }
	  else if (totalRight <= 22)
	  {
	     message = "This score is highly significant."
	  }
	  else
	  {
	     message = "You must be psychic! That's an incredible score!"
	  }
	  if (confirm("You have completed the run. Out of a total 24 trials, you were able to move the square to the right " + totalRight + " times. " + message + " Would you like to play agan?"))
	  {
         window.location="onlinepk.html"
	  }
   }
}

function swapLeft(currentLoc)
{
   if (currentLoc == 1)
   {
      document.loc1.src="images/testpk2.jpg"
	  document.loc2.src="images/testpk.jpg"
   }
   if (currentLoc == 2)
   {
      document.loc2.src="images/testpk2.jpg"
	  document.loc3.src="images/testpk.jpg"
   }
   if (currentLoc == 3)
   {
      document.loc3.src="images/testpk2.jpg"
	  document.loc4.src="images/testpk.jpg"
   }
   if (currentLoc == 4)
   {
      document.loc4.src="images/testpk2.jpg"
	  document.loc5.src="images/testpk.jpg"
   }
   if (currentLoc == 5)
   {
      document.loc5.src="images/testpk2.jpg"
	  document.loc6.src="images/testpk.jpg"
   }
   if (currentLoc == 6)
   {
      document.loc6.src="images/testpk2.jpg"
	  document.loc7.src="images/testpk.jpg"
   }
   if (currentLoc == 7)
   {
      document.loc7.src="images/testpk2.jpg"
	  document.loc8.src="images/testpk.jpg"
   }
   if (currentLoc == 8)
   {
      document.loc8.src="images/testpk2.jpg"
	  document.loc9.src="images/testpk.jpg"
   }
   if (currentLoc == 9)
   {
      document.loc9.src="images/testpk2.jpg"
	  document.loc1.src="images/testpk.jpg"
   }
}

function swapRight(currentLoc)
{
   if (currentLoc == 1)
   {
      document.loc1.src="images/testpk2.jpg"
	  document.loc9.src="images/testpk.jpg"
   }
   if (currentLoc == 2)
   {
      document.loc2.src="images/testpk2.jpg"
	  document.loc1.src="images/testpk.jpg"
   }
   if (currentLoc == 3)
   {
      document.loc3.src="images/testpk2.jpg"
	  document.loc2.src="images/testpk.jpg"
   }
   if (currentLoc == 4)
   {
      document.loc4.src="images/testpk2.jpg"
	  document.loc3.src="images/testpk.jpg"
   }
   if (currentLoc == 5)
   {
      document.loc5.src="images/testpk2.jpg"
	  document.loc4.src="images/testpk.jpg"
   }
   if (currentLoc == 6)
   {
      document.loc6.src="images/testpk2.jpg"
	  document.loc5.src="images/testpk.jpg"
   }
   if (currentLoc == 7)
   {
      document.loc7.src="images/testpk2.jpg"
	  document.loc6.src="images/testpk.jpg"
   }
   if (currentLoc == 8)
   {
      document.loc8.src="images/testpk2.jpg"
	  document.loc7.src="images/testpk.jpg"
   }
   if (currentLoc == 9)
   {
      document.loc9.src="images/testpk2.jpg"
	  document.loc8.src="images/testpk.jpg"
   }
}
