/***********************************************************
* animate.js                                       by Ralp *
*   There are two animated elements in this project.  Each *
*   has a function to start the animation initially, and   *
*   another function which is iteratively called by        *
*   recurring Javascript timers for each step (or "frame") *
***********************************************************/

var aboutTimer=null, winTimer=null, winTicker=null;

function showAbout(dir) {  // dir: 1 for show or 0 for hide
  if (aboutTimer==null) {
    if (getId("aboutdiv").getAttribute("class")=="hidden" || dir==0) {
      hide("aboutcontent"); // Never show this during animation
      show("aboutdiv");  // but always show this during animation
      growAbout(100-dir*100, dir*2-1);
    }
  }
}
function growAbout(i, dir) { // dir: 1 for show (up) or -1 for hide (down)
  var animEl = getId("aboutanim");
  animEl.style.height = i+"%";
  animEl.style.left   = (100-i)/2 +"%";
  animEl.style.right  = (100-i)/2 +"%";
  if (i<100 && dir>0 || i>0 && dir<0) {
    aboutTimer = setTimeout("growAbout("+(i+dir*2)+","+dir+")", 20);
  }
  else {
    if (dir<0) hide("aboutdiv");
    if (dir>0) show("aboutcontent");
    aboutTimer = null;
  }
}


function showWinMsg() {
  /* We use a different method here than seen above to determine if an
      animation is already in progress and if so how far we are into it.
      (Because we could potentially trigger a new victory before the old
      one is finished.)  */
  winTicker = -25;
  show("message");
  if (winTimer==null) scrollWinMsg();
}
function scrollWinMsg() {
  var animEl = getId("message");
  animEl.style.left = winTicker+"%";
  if (winTicker<125) {
    winTicker++;
    winTimer = setTimeout("scrollWinMsg()", 20);
  }
  else {
    hide("message");
    winTimer = null;
  }
}

