var dir = 0;
var speed = 0;
var selectedImage = null;
var width = 0;

function myTicker()
{
  if (dir != 0)
  {
    if (dir > 0 && speed < 8)
      speed += dir;
    if (dir < 0 && speed > -8)
      speed += dir;
  } 
  else
  {
    if (speed < 0)
      speed += 1;
    else if (speed > 0)
      speed -= 1;
  }
    
  for (i=0; i<images.length; i++)
  {
    var theImage = images[i];
    if (theImage.xpos == null)
    {
      // we are initializing,

      // horizontal position
      theImage.xpos   = width;
      if ( i != images.length - 1)
        width += theImage.width + 4;
      else
        width +=  4;
      
      // original width of image
      theImage.orgWidth  = eval (theImage.width);
      
      // center vertically
      theImage.style.top = (128 - theImage.height)/2; 
      theImage.orgTop    = (128 - theImage.height)/2;
      
      // zoom factor
      theImage.zoom  = 0;
    }
    else
    {
      // we are running, 
      
      // scroll left or right
      theImage.xpos += speed;
      
      // wraparound
      if (theImage.xpos < -theImage.width)
        theImage.xpos += Math.max (700, width) + theImage.width;
      else if (theImage.xpos > 700)
        theImage.xpos -= Math.max (700, width) + theImage.width;
        
      // zoom down images if they are not selected
      if (theImage != selectedImage && theImage.zoom>0)
      {
        theImage.zoom -= 1;
      }

      if (theImage == selectedImage && theImage.zoom<10)
      {
        theImage.zoom += 2;
        theImage.zoom = Math.min (theImage.zoom, 10);
      }
      
      // keep track of z-indices
      theImage.style.zIndex = theImage.zoom;            
    }
    
    theImage.style.left   = images[i].xpos    - theImage.zoom;
    theImage.style.top    = images[i].orgTop  - theImage.zoom;
    theImage.width        = theImage.orgWidth + (2*theImage.zoom);
  }    

  setTimeout ('myTicker()',25);
}

function select(image)
{
  selectedImage = image;
}

function next()
{
  dir = 1;
}

function prev()
{
  dir = -1;
}

function pause()
{
  dir = 0;
}

