﻿SlideShow = function() {
    this.interval = 2500;
    this.index = -1;
    this.images = new Array();
    this.timeoutID = 0;
    this.isPaused = false;
    this.isPlaying = false;
    this.startText = "";
    this.endText = "";
    this.autoplay = false;
};
SlideShow.prototype.initialize = function() {
    $('slideShowImageText').innerHTML = this.startText;
    if (this.autoplay == true) {
        this.play();
    }   
};
SlideShow.prototype.addImage = function(galleryImage) {
    this.images.push(galleryImage);   
};
SlideShow.prototype.showImage = function(iIndex) {  
    $('slideShowImage').style.backgroundImage = 'url(\'' + this.images[this.index].url + '\')';  
    $('slideShowCaption').innerHTML = this.images[this.index].description; 
    $('slideShowStatus').innerHTML = 'Image ' + (this.index + 1) + " of " + this.images.length + "."; 
    $('slideShowInstructions').style.display = 'none';    
};
SlideShow.prototype.showNextImage = function() { 
   if (this.index  < this.images.length - 1) {
       if (++this.index == 0) {
        $('slideShowImageText').innerHTML = "";
       }       
       this.showImage(this.index);   
   } else {
        this.index = -1;
        $('slideShowImage').style.backgroundImage = "";        
        $('slideShowImageText').innerHTML = this.endText;
   }
};
SlideShow.prototype.showPreviousImage = function() {  
    if (this.index > 0) {
};
SlideShow.prototype.stop = function() {    
    window.clearTimeout(this.timeoutID);
        this.showImage(--this.index);
    }
    this.isPlaying = false;        
};
SlideShow.prototype.rotate = function() {
     this.showNextImage();
     this.timeoutID = window.setTimeout('slideShow.rotate()', this.interval);     
};
SlideShow.prototype.play = function() {   
    if (this.isPlaying == true) {
        this.isPlaying = false;
        this.stop();
        $('slideShowPlayButton').className = "playButton";
    } else if (this.isPlaying == false) {
        this.rotate();  
        this.isPlaying = true; 
        $('slideShowPlayButton').className = "pauseButton"; 
    }
};