﻿// JScript File

var slideShows = new Array();

function createNewSlideShow(slides, displaySlide)
{
    var ss = new slideShow(slides, displaySlide, slideShows.length);
    
    slideShows.push(ss);

    ss.displayCurrentSlide();
    
    // Preload the images
    
    return ss;
}

function nextSlide(index, force)
{
    slideShows[index].nextSlide(force);
}

function previousSlide(index, force)
{
    slideShows[index].previousSlide(force);
}

function slideShow(slides, displaySlide, index)
{
    this.slides = slides;
    this.displaySlide = displaySlide;
    this.currentSlide = 0;
    this.slideTimer = 0;
    this.pauseSlideshow = false;
    this.displayCurrentSlide = displayCurrentSlide;
    this._index = index;
    this.started = false;
    
    slideShow.prototype.startShow = startShow;
    slideShow.prototype.previousSlide = previousSlide;
    slideShow.prototype.nextSlide = nextSlide;
    slideShow.prototype.doPauseSlideshow = doPauseSlideshow;

    function startShow()
    {           
        this.started = true;     
        this.slideTimer = setTimeout("nextSlide(" + this._index + ", false)", 5000);    
    }
    
    function displayCurrentSlide() 
    {
        if (this.slides.length == 0)
            return;
    
        this.displaySlide(
            this.slides[this.currentSlide]);
    }

    function previousSlide(force) 
    {
        if (force)
            this.pauseSlideshow = false;
            
        if (this.slideTimer)
            clearTimeout(this.slideTimer);
        
        if (this.pauseSlideshow)
            return;
        
        if (this.currentSlide == 0) {
            this.currentSlide = this.slides.length - 1;
        } else {
            this.currentSlide--;
        }
        this.displayCurrentSlide();
        
        if (this.started)
            this.slideTimer = setTimeout("previousSlide(" + this._index + ", false)", 5000);    
    }

    function nextSlide(force) 
    {
        if (force)
            this.pauseSlideshow = false;
            
        if (this.slideTimer)
            clearTimeout(this.slideTimer);

        if (this.pauseSlideshow)
            return;
                
        if (this.currentSlide == this.slides.length - 1) {
            this.currentSlide = 0;
        } else {
            this.currentSlide++;
        }
        this.displayCurrentSlide();
        
        if (this.started)
            this.slideTimer = setTimeout("nextSlide(" + this._index + ", false)", 5000);    
    }

    function doPauseSlideshow()
    {
        this.pauseSlideshow = true;
    }        
}


    
