/*********************************************************************************************
/*
/*  Tekst Animaties, (c) 2006 Ben's Hobbyhoekje - Ben Boukes.
/*  Mag vrij worden gebruikt mits dit commentaar intact wordt gelaten.
/*
/********************************************************************************************/

var spd,stp,xdir,ydir,xpos,ypos,animObj; // Globale variabelen

function FlyText(fly,speed,steps) {
  animObj = document.getElementById("FlyingText");
  if (animObj == null) {
    window.alert('Id FlyingText ontbreekt\n\nAnimatie niet gestart');
    return false;
  }
// Stel zonodig de defaults in voor speed en steps
  var argv = FlyText.arguments;  
  var argc = FlyText.arguments.length;
  spd = (argc > 1) ? argv[1] : 50;   // Snelheid, wordt direct aan setTimeout gevoerd, Lager = sneller
  spd = (spd <= 0) ? 50 : spd;
  stp = (argc > 2) ? argv[2] : 100;  // Aantal stappen, rekenresultaten worden in StepsX en StepsY gezet
  stp = (stp <= 0) ? 100 : stp;
  
  // Test de juistheid van het keyword en plaats het object in de beginpositie (xpos, ypos).
  // stel de beweegrichtingen in (xdir, ydir == -1 of 0; wordt later hergedefinieerd)
  switch (fly) {
  case 'Top': xpos = 0; ypos = -1.1*screen.height; xdir = 0 ; ydir = -1;
    break;
  case 'Bottom': xpos = 0; ypos = 2.1*screen.height; xdir = 0 ; ydir = -1;
    break;
  case 'Left': xpos = -1.1*screen.width; ypos = 0; xdir = -1 ; ydir = 0;
    break;
  case 'Right': xpos = 2.1*screen.width; ypos = 0; xdir = -1 ; ydir = 0;
    break;
  case 'TopLeft': xpos = -1.1*screen.width; ypos = -1.1*screen.height; xdir = -1; ydir = -1;
    break;
  case 'BottomLeft': xpos = -1.1*screen.width; ypos = 2.1*screen.height; xdir = -1; ydir = -1;
    break;
  case 'TopRight': xpos = 2.1*screen.width; ypos = -1.1*screen.height; xdir = -1; ydir = -1;
    break;
  case 'BottomRight': xpos = 2.1*screen.width; ypos = 2.1*screen.height; xdir = -1; ydir = -1;
    break;
  default:
    window.alert('Fout keyword in aanroep van FlyText()\n\nAnimatie niet gestart');
    return false;
  }
  xdir = xdir*xpos/stp;              // Herdefineer bewegingen naar echte waarden
  ydir = ydir*ypos/stp;

//  Verplaats de positie van de tekst in het id = "FlyingText" in stp stappen
  Animate();  // (ver)plaats de tekst
}

var AnimationTimer;   // Hulpje voor Timeout
function Animate() {
  animObj.style.left = xpos+'px';
  animObj.style.top = ypos+'px';
  xpos += xdir;
  ypos += ydir;
  stp--;
  if (stp <= 0) { xpos = 0; ypos = 0}
  if (stp >= 0) AnimationTimer = window.setTimeout("Animate()", spd);
  if (stp < 0) clearTimeout(AnimationTimer); 
}