var FirstImage = 1;
var LastImage = 22;
var CurrentImage = FirstImage;


/* This function converts a number to a string */
function ConvertNumberToString(iNum) {
  return ("" + iNum);
}


/* This function prefixes strings with the correct # of 0's      */
function ZeroFill(iNum, iDigits) {
  var sNum = ConvertNumberToString(iNum);
  while (sNum.length < iDigits)
    sNum = "0" + sNum;
  return sNum;
}


/* This function changes the jpg-file on the window according to the selected number  */
function ItemClicked(iIndex) {
  var sIndex = ZeroFill(iIndex, 3);
  var BildName = "img" + sIndex + ".jpg"
  document.bild.src = BildName;
  CurrentImage = iIndex;
  Bildzaehler();
}


/* This function increases or decreases the image counter */
function MoveRelative(iRel) {
  var newI = parseInt(CurrentImage) + parseInt(iRel);
  if ( (newI >= FirstImage) && (newI <= LastImage) )
    ItemClicked(newI);
}


/* This function displays a message, which image is actually shown */
function Bildzaehler() {
  var bildtext = "Bild " + CurrentImage + " von " + LastImage;

  if (document.all)
    document.all.AktuellesBild.innerText = bildtext;

  if (document.layers) {
    document.Tabelle.document.open();
    Text = "<table><tr><td><a href='JavaScript:MoveRelative(-1)'><img src='prev.gif' alt='eins zurück' border=0></a></td>"
           + "<td><p id='AktuellesBild'>" + bildtext + "</p></td>"
           + "<td><a href='JavaScript:MoveRelative(1)'><img src='next.gif' alt='eins vorwärts' border=0></a></td></tr></table>"

    document.Tabelle.document.write(Text);
    document.Tabelle.document.close();
  }
}

