//*********************************************
// Animates the scroller by incrementing
// the left style attribute by the xInc ammount.
//
// At the end of the function it sets a timmer
// that calls itself again. If it can't find the
// layers to animate (ie, the page has been changed)
// it quits.
//
//
// NOTE: populate() needs to be run before tick()
//*********************************************
function tick(xInc, imgWidth, total, name, activeDocument)
{
   var rate = 32;          // Frames per second.
 //  var imgWidth = 108;     // Width of a ticker image.

   var time = 1000/rate;   // The time until recall of this function.
   var restartLimit = - imgWidth // The furtest distance of the left edge

   // Get every layer
   for(layerIdx = 0; layerIdx < total; layerIdx++)
   {
      var layerName = name+layerIdx;

      try
      { // Get a ref to the layer.
         var layerElement = activeDocument.getElementById(layerName);
      }
      catch(err)
      {
         // Abort on error. An err probably means the page has changed.
         return;
      }

      if(layerElement) // Do we have a valid reference?
      {

         // Get new left positions.
         var newXPos = layerElement.style.pixelLeft - xInc;

         // Set the left positions
         layerElement.style.pixelLeft = newXPos;

         // Restart a layer if it scolled to far
         if (layerElement.style.pixelLeft <= restartLimit)
         {
           layerElement.style.pixelLeft = imgWidth*total - imgWidth;
         }
      }
      else // Page has probably changed/or the layer wasn't made.
      {
         // Quit animating.
         return;
      }
   }
   var commandString = "tick("+xInc+","+imgWidth+","+total+",'"+name+"',document);"

   setTimeout(commandString, time);
   return;

}



