slideShow = new Object();

slideShow.initialized = false;
slideShow.blindAlpha = 0;
slideShow.boxTween = 0;
slideShow.boxAlpha = 0;
slideShow.imageTween = 0;
slideShow.imageAlpha = 0;
slideShow.curImage = 0;
slideShow.imageObject = new Image();
slideShow.imageList = Array();
slideShow.opacity = 0.8;

slideShow.initialize = function() {
  this.blindElement = document.getElementById("slideShowBlind");
  this.boxElement = document.getElementById("slideShowBox");
  this.lowImageFrameElement = document.getElementById("slideShowLowImageFrame");
  this.lowImageElement = document.getElementById("slideShowLowImage");
  this.highImageFrameElement = document.getElementById("slideShowHighImageFrame");
  this.highImageElement = document.getElementById("slideShowHighImage");
  this.previousElement = document.getElementById("slideShowPrevious");
  this.nextElement = document.getElementById("slideShowNext");
  this.loadingElement = document.getElementById("slideShowLoading");
}

slideShow.setOpacity = function(element, value) {
  element.style.filter = "alpha(opacity = " + value + ")";
  element.style.opacity = value / 100;
}

slideShow.openBox = function(getImage) {
  if (!this.initialized) {
    this.initialize();
  }
  if (getImage != undefined) {
    this.curImage = getImage - 1;
  }
  this.setOpacity(this.blindElement, 0);
  this.blindElement.style.display = "block";
  this.setOpacity(this.boxElement, 0);
  this.boxElement.style.display = "block";
  this.lowImageFrameElement.style.display = "none";
  this.highImageFrameElement.style.display = "none";
  this.previousElement.style.display = "none";
  this.nextElement.style.display = "none";
  this.loadingElement.style.display = "none";
  this.tweenBox(100);
}

slideShow.tweenBox = function(targetAlpha) {
  clearTimeout(this.boxTween);
  this.boxAlpha += (targetAlpha - this.boxAlpha) / 6;
  this.blindAlpha += ((this.opacity * targetAlpha) - this.blindAlpha) / 6;
  if (Math.round(this.boxAlpha) == targetAlpha) {
    this.boxAlpha = targetAlpha;
    this.blindAlpha = this.opacity * targetAlpha;
    if (targetAlpha == 100) {
      this.openImage();
    } else {
      this.blindElement.style.display = "none";
      this.boxElement.style.display = "none";
      this.lowImageFrameElement.style.display = "none";
    }
  } else {
    this.boxTween = setTimeout("slideShow.tweenBox(" + targetAlpha + ")", 25);
  }
  this.setOpacity(this.boxElement, this.boxAlpha);
  this.setOpacity(this.blindElement, this.blindAlpha);
  this.setOpacity(this.lowImageFrameElement, this.boxAlpha);
}

slideShow.closeBox = function() {
  if (this.imageAlpha == 100 && this.boxAlpha == 100) {
    this.previousElement.style.display = "none";
    this.nextElement.style.display = "none";
    this.tweenBox(0);
  }
}

slideShow.openImage = function() {
  this.imageAlpha = 0;
  this.previousElement.style.display = "none";
  this.nextElement.style.display = "none";
  this.loadingElement.style.display = "block";
  this.imageObject = new Image();
  this.imageObject.onload = this.imageLoaded;
  this.imageObject.src = this.imageList[this.curImage];
}

slideShow.imageLoaded = function() {
  slideShow.setOpacity(slideShow.highImageFrameElement, 0);
  slideShow.highImageFrameElement.style.display = "block";
  slideShow.highImageElement.src = slideShow.imageObject.src;
  slideShow.loadingElement.style.display = "none";
  slideShow.tweenImage();
}

slideShow.tweenImage = function() {
  clearTimeout(this.imageTween);
  this.imageAlpha += (100 - this.imageAlpha) / 6;
  if (Math.round(this.imageAlpha) == 100) {
    this.imageAlpha = 100;
    this.swapImage();
  } else {
    this.imageTween = setTimeout("slideShow.tweenImage()", 25);
  }
  this.setOpacity(this.highImageFrameElement, this.imageAlpha);
}

slideShow.swapImage = function() {
  this.lowImageElement.src = this.imageObject.src;
  this.lowImageFrameElement.style.display = "block";
  this.highImageFrameElement.style.display = "none";
  this.highImageElement.src = "";
  this.loadingElement.style.display = "none";
  if (this.curImage > 0) {
    this.previousElement.style.display = "block";
  }
  if (this.curImage + 1 < this.imageList.length) {
    this.nextElement.style.display = "block";
  }
}

slideShow.previousImage = function() {
  if (this.curImage > 0) {
    this.curImage--;
    this.openImage();
  }
}

slideShow.nextImage = function() {
  if (this.curImage + 1 < this.imageList.length) {
    this.curImage++;
    this.openImage();
  }
}
