
function moveEW(z, no) {
  n1=no;
  if (moved < Math.abs(limEW*72)) {
    z.style.pixelLeft+=6*(limEW/Math.abs(limEW));
    setTimeout("moveEW(z, n1)",50);
    moved += 6;
    }
  else {
    if (n1<moves.length-1) {
      solution((n1+1));
      }
    else {
      gameOver = true;
      }
    }
  }

function moveNS(z, no) {
  n1=no;
  if (moved < Math.abs(limNS*72)) {
    z.style.pixelTop+=6*(limNS/Math.abs(limNS));
    setTimeout("moveNS(z, n1)",50);
    moved += 6;
    }
  else {
    if (n1<moves.length-1) {
      solution((n1+1));
      }
    }
  }

function solution(no) {
  if (gameStart || gameOver) {
    alert("Press F5 to reset the Jam before attempting to view the solution")
    }
  else {
    z=document.getElementById(moves[no].vehicle);
    limEW=moves[no].moveEW;
    limNS=moves[no].moveNS;
    vehName=moves[no].vehicle;
    moved=0;
    if ( vehName.indexOf("EW") >0 ) {
      moveEW(z, no);
      }
    else {
      moveNS(z, no);
      }
    }
  }
