
////////////////////////////////////////////////////////////////////
//
//   Name: animate.js
//
//   Description: Javascript to animate images.
//
//   Modification history:
//
//   DATE        MODIFIED BY        DESCRIPTION
//   11/2003     L.Nguyen           Created
//   01/2004     L.Nguyen           Modified call to "new Image" - 
//                                  Netscape 4.x didn't recognize it.
//
////////////////////////////////////////////////////////////////////

var myimages = new Array(); 
var frame = 0;         // keep track of what frame of the animation we're on.
var timeout_id = null; // allows us to stop the animation.

// Set up the animation images and run
function startAnimate(path,imageList,width,height) 
{

  initImages(path,imageList,width,height);
  if (timeout_id == null) {
    runIt();
  }

}

// Initialize the images
function initImages(path,imageList,width,height)
{

  var imageNames = new Array();
  imageNames = imageList.split(" ");

  for (var i in imageNames) {
//    myimages[i] = new Image(width,height); 
    myimages[i] = new Image(); 
    myimages[i].src = path + imageNames[i];
  }

}

// Run the animation
function runIt()
{

    document.theanimation.src = myimages[frame].src;
    frame = (frame + 1)%myimages.length;
    timeout_id = setTimeout("runIt()", 300);  // display next frame later

}

// Stop the animation
function stopAnimate(imageList) 
{

  if (timeout_id) {
    clearTimeout(timeout_id); 
    timeout_id=null;
  }

}

// Step through the animation
function stepAnimate(path,imageList,width,height)
{

  if (myimages.length == 0) {
    initImages(path,imageList,width,height);
  } else {
    stopAnimate(imageList);
  }
  document.theanimation.src = myimages[frame].src;
  frame = (frame + 1)%myimages.length;

}
