// Dieses Java-Script dient dazu, ein Bild von rechts nach linkt über den Bildschirm zubewegen
// Es basiert auf auf einem Java-Script aus der c't 3/2002
// globale Variablen
var breite=64, hoehe=64;  //Dimensionen des Banners
var phase = 1;  //Animationsphase (1=rechts aussen, 2=Bewegung, 3=permanent links aussen)
var ID1, ID2; //Timeout-IDs
var banner, bannerstil; //Referenzen auf Banner und Stileigenschaften

// Browser
var N4=false, IE=false, W3C=false;
if (document.layers)
  N4 = true;
else if (document.all)
  IE = true;
if (document.getElementById)
  W3C = true;

function init() {
  // globale Referenz auf Banner
  if (N4) {
    banner = document.Grafik;
    bannerstil = document.Grafik;
  } else if (IE) {
    banner = document.all.Grafik;
    bannerstil = document.all.Grafik.style;
  } else if (W3C) {
    banner = document.getElementById("Grafik");
    bannerstil = document.getElementById("Grafik").style;
  }
  if (IE && W3C && !bannerstil.left) // Abgrenzung zwischen IE und Opera der sich als IE5 ausgibt
    W3C = false;
  animation();
}

// Hilfsfunktionen

function XOffset() {
  if (N4 || W3C)
    return window.pageXOffset;
  if (IE)
    return document.body.scrollLeft;
}

function YOffset() {
  if (N4 || W3C)
    return window.pageYOffset;
  if (IE)
    return document.body.scrollTop;
}

function browserbreite() {
  if (N4 || W3C)
    return window.innerWidth;
  if (IE)
    return document.body.clientWidth;
}

function browserhoehe() {
  if (N4 || W3C)
    return window.innerHeight;
  if (IE)
    return document.body.clientHeight;
}

function positionX() {  //x-Koordinate der Grafik
  if (N4 || W3C)
    return parseInt(bannerstil.left);
  if (IE)
    return parseInt(bannerstil.posLeft);
}

function positionY() {  //y-Koordinate der Grafik
  if (N4 || W3C)
    return parseInt(bannerstil.top);
  if (IE)
    return parseInt(bannerstil.posTop);
}

function bewege(x, y) {
  if (N4) {
    bannerstil.left = x;
    bannerstil.top = y;
  } else if (W3C) {
    bannerstil.left = x + "px";
    bannerstil.top = y + "px";
  } else if (IE) {
    bannerstil.posLeft = x;
    bannerstil.posTop = y;
  }
}

function zeige() {
  bannerstil.visibility = "visible";
}

function verstecke() {
  bannerstil.visibility = "hidden";
}

function animation() {
  switch(phase) {

    case 1:  //Startpos rechts ausserhalb des Bildes
      bewege(browserbreite() + breite + 5, 100);
      zeige();
      ID1 = window.setTimeout("animation()", 100); //Position auch beim Scrollen beibehalten
      ID2 = window.setTimeout("weiter(2)", 3000); //nächste Phase nach 5 Sekunden
      break;

    case 2:  //Bewegung von rechts nach links
      if (positionX() < - breite) //schon da?
        weiter(3);
      else {
        bewege(positionX() - 5 , 100 );
        ID1 = window.setTimeout("animation()", 100); //Weiter in einer Zehntelsekunde
      }
      break;

    case 3:  //Wenn links aussen, dann ende
      bewege(- breite -5 , 100);
      ID1 = window.setTimeout("animation()", 100); //Position auch beim Scrollen beibehalten
      ende();

  }
}

function weiter(nr) {  //nächste Phase der Animation
  phase = nr;
  window.clearTimeout(ID1);
  animation();
}

function ende() {  //Animation beenden
  verstecke();
  window.clearTimeout(ID1);
  window.clearTimeout(ID2);
}
