var offset = -2070;
var clipTimerId;
var userSubmits = 0;


/*****************************************************************************
 * function:    submitOnce
 *
 * Description: Prevents the user from invoking odd behaviour by pressing the
 *              play button more than once without an intervening "stop" or
 *              "reset".
 *****************************************************************************/
function submitOnce()
{
   if(userSubmits > 0)
   {
      return;
   }
   else
   {
      userSubmits++;
      runSeq();
   }
}


/*****************************************************************************
 * function:    runSeq
 *
 * Description: Runs the animated sequence.
 *****************************************************************************/
function runSeq()
{
   var obj = (document.all) ? document.all.clipIt : document.getElementById("clipIt");
   var play = (document.all) ? document.all.playClip : document.getElementById("playClip");
   
   play.value = " Play ";
   play.title="Run the animation";
   play.width = 80;
   
   if(offset < 0)
   {
      offset += 2;
      obj.style.backgroundPosition = offset + "px 0px";
      clipTimerId = setTimeout("runSeq()", 3);
   }
}

/*****************************************************************************
 * function:    stopSeq
 *
 * Description: Pauses the animated sequence. Clears the flag that prevents
 *              multiple runnings.
 *****************************************************************************/
function stopSeq()
{
   var obj = (document.all) ? document.all.playClip : document.getElementById("playClip");
   obj.value = "Resume";
   obj.title="Carry on with the animation";
   userSubmits = 0;
   
   clearTimeout(clipTimerId);
}

/*****************************************************************************
 * function:    resetSeq
 *
 * Description: Resets the animated sequence. Clears the flag that prevents
 *              multiple runnings.
 *****************************************************************************/
function resetSeq()
{
   var obj = (document.all) ? document.all.clipIt : document.getElementById("clipIt");
   var play = (document.all) ? document.all.playClip : document.getElementById("playClip");
   
   play.value="Play";
   play.title="Run the animation";
   play.width=80;
   
   userSubmits = 0;
   clearTimeout(clipTimerId);
   offset = -2070;
   obj.style.backgroundPosition = -2070 + 'px 0px';
}

addEvent(window, 'load', resetSeq, false);

