/////////////////////////////////////////////////////////////////////////////

// var zugliste;
// var offset;

/////////////////////////////////////////////////////////////////////////////

var buttonout = new Array (4)
buttonout[0] =  new Image (); buttonout[0].src = "/partie/begin0.gif";
buttonout[1] =  new Image (); buttonout[1].src = "/partie/prev0.gif";
buttonout[2] =  new Image (); buttonout[2].src = "/partie/next0.gif";
buttonout[3] =  new Image (); buttonout[3].src = "/partie/end0.gif";

var buttonover = new Array (4)
buttonover[0] = new Image (); buttonover[0].src = "/partie/begin1.gif";
buttonover[1] = new Image (); buttonover[1].src = "/partie/prev1.gif";
buttonover[2] = new Image (); buttonover[2].src = "/partie/next1.gif";
buttonover[3] = new Image (); buttonover[3].src = "/partie/end1.gif";

var buttondown = new Array (4)
buttondown[0] = new Image (); buttondown[0].src = "/partie/begin2.gif";
buttondown[1] = new Image (); buttondown[1].src = "/partie/prev2.gif";
buttondown[2] = new Image (); buttondown[2].src = "/partie/next2.gif";
buttondown[3] = new Image (); buttondown[3].src = "/partie/end2.gif";

var size = "40";

/////////////////////////////////////////////////////////////////////////////

function elem (zug)
{
   var a1 = "_a1";
   var spalte = zug.charCodeAt(1) - a1.charCodeAt(1);
   var zeile =  zug.charCodeAt(2) - a1.charCodeAt(2);
   var feld = 8 * (7 - zeile) + spalte;
   window.document.images[offset+feld].src =
      "/partie/" + size + zug.charAt(0) + ".gif";
}

/////////////////////////////////////////////////////////////////////////////

function vor (zug)
{
   while (zug.length >= 3) {
      elem (zug.substring (0, 3));
      zug = zug.substring (3, zug.length);
   }
}

function rov (zug)
{
   while (zug.length >= 3) {
      elem (zug.substring (zug.length-3, zug.length));
      zug = zug.substring (0, zug.length-3);
   }
}

/////////////////////////////////////////////////////////////////////////////

function six (s)
{
   var zug = s.substr(0,3) + "_" + s.substr(1,2) +
      s.substr(3,3) + s.substr(0,1) + s.substr(4,2);
   if (s == "Ke1_g1")
      zug += "Rh1_h1_f1Rf1";
   else if (s == "Ke1_c1")
      zug += "Ra1_a1_d1Rd1";
   else if (s == "Ke8_g8")
      zug += "Rh8_h8_f8Rf8";
   else if (s == "Ke8_g8")
      zug += "Ra8_a8_d8Rd8";
   vor (zug);
}

function xis (s)
{
   var zug = s.substr(0,3) + "_" + s.substr(1,2) +
      s.substr(3,3) + s.substr(0,1) + s.substr(4,2);
   if (s == "Ke1_g1")
      zug += "Rh1_h1_f1Rf1";
   else if (s == "Ke1_c1")
      zug += "Ra1_a1_d1Rd1";
   else if (s == "Ke8_g8")
      zug += "Rh8_h8_f8Rf8";
   else if (s == "Ke8_g8")
      zug += "Ra8_a8_d8Rd8";
   rov (zug);
}

/////////////////////////////////////////////////////////////////////////////

var zugnummer = 0;

function rewind ()
{
   while (zugnummer != 0) {
      zugnummer--;
      xis (zugliste.substr (zugnummer*6, 6));
   }
}

function prev ()
{
   if (zugnummer != 0) {
      zugnummer--;
      xis (zugliste.substr (zugnummer*6, 6));
   }
}

function next ()
{
   if (zugliste.length >= zugnummer*6+6) {
      six (zugliste.substr (zugnummer*6, 6));
      zugnummer++;
   }
}

function gotoend ()
{
   while (zugliste.length >= zugnummer*6+6) {
      six (zugliste.substr (zugnummer*6, 6));
      zugnummer++;
   }
}

/////////////////////////////////////////////////////////////////////////////

function out (button)
{
   window.document.images[offset+64+button].src = buttonout[button].src;
}

function over (button)
{
   if (zugliste.charAt(0) == " ")
      zugliste = zugliste.replace (/ /g, "");
   window.document.images[offset+64+button].src = buttonover[button].src;
}

function down (button)
{
   window.document.images[offset+64+button].src = buttondown[button].src;
   if (button == 0)
     rewind ();
   else if (button == 1)
     prev ();
   else if (button == 2)
     next ();
   else
     gotoend ();
}

function up (button)
{
   window.document.images[offset+64+button].src = buttonover[button].src;
}

/////////////////////////////////////////////////////////////////////////////


