imageSources = new Array ();
imageCaptions = new Array ();
imageURLs = new Array ();
imageX = 561;
imageY = 423;

imageData = new Array ();
currImage = 0;
nextImage = 1;
opacity = 0;
counter = 0;
paused = 0;
firstTime = 1;

function addImage (source,caption,url)
{
  var nextImg = imageSources.length;
  imageSources [nextImg] = source;
  imageCaptions [nextImg] = caption; 
  imageURLs [nextImg] = url;
}

function initRotate ()
{
  imageData [0] = new Image (imageX,imageY);
  imageData [0].src = imageSources [0];
  var recur_call = "doRotateTimer ()";
  setTimeout (recur_call, 40 * 75);
}

function doProductClick ()
{
  document.location.href = imageURLs [currImage];
}

function doRotateTimer ()
{
  var front = document.getElementById ('centerfront');
  var back = document.getElementById ('centerback');
  var cfront = document.getElementById ('captionfront');
  var cback = document.getElementById ('captionback');
  do {
    if (opacity >= 100) {
      if (counter <= 0) {
        back.style.display = 'none';
        back.src = imageSources [nextImage];
        back.style.display = 'block';
        currImage = nextImage;
        nextImage++;
        if (nextImage >= imageSources.length)
          nextImage = 0;
        if (imageData.length <= nextImage) {
          imageData [nextImage] = new Image (imageX,imageY);
          imageData [nextImage].src = imageSources [nextImage];
          }
        counter = 1;
        }
      else if (counter == 74) {
        front.style.display = 'none';
        front.style.opacity = 0;
        front.style.filter = 'alpha(opacity=' + 0 + ')';
        counter++;
        }
      else if (counter > 75) {
        front.src = imageSources [nextImage];
        front.style.display = 'block';
        cback.innerHTML = imageCaptions [nextImage];
        opacity = 0;
        counter = 0;
        }
      else if (!paused)
        counter++;
      }
    else {
      if (!front.complete)
        break;
      if (firstTime) {
        cback.innerHTML = imageCaptions [nextImage];
        firstTime = 0;
        }
      if (opacity < 40)
        opacity += 4;
      else opacity += 2;
      front.style.opacity = opacity / 100;
      front.style.filter = 'alpha(opacity=' + opacity + ')';
      }
    } while (0);
  var recur_call = "doRotateTimer ()";
  setTimeout (recur_call, 40);
}

function pauseRotate ()
{
  paused = 1;
}

function resumeRotate ()
{
  paused = 0;
}

window.onload = initRotate;
