﻿function SlideShow(name)
{
    this.CurrentElement = null;
    this.CurrentElementIndex = 0;
    this.CurrentImage = null;
    this.CurrentImageIndex = 0;
    this.Elements = new Array();
    this.Images = new Array();
    this.Initialized = false;
    this.Interval = 5000;
    this.Name = name;
    this.TransitionDuration = 0.5;
}

SlideShow.prototype.ShowNext = function()
{
    var doTrans;
    
    doTrans = false;   
    
    this.CurrentElementIndex++;
    this.CurrentImageIndex++;
    
    if (this.CurrentElementIndex >= this.Elements.length) this.CurrentElementIndex = 0;
    if (this.CurrentImageIndex >= this.Images.length) this.CurrentImageIndex = 0;
    
    this.CurrentElement = this.Elements[this.CurrentElementIndex];
    this.CurrentImage = this.Images[this.CurrentImageIndex];

    if (this.CurrentElement.filters) 
    {
        if (this.CurrentElement.filters.blendTrans) doTrans = true;
    }
    
    if (doTrans) this.CurrentElement.filters.blendTrans.apply();
    this.CurrentElement.src = this.CurrentImage;
    if (doTrans) this.CurrentElement.filters.blendTrans.play();

    this.Start();
}

SlideShow.prototype.Start = function()
{
    var idx;    

    if (!this.Initialized)
    {
        for (idx=0; idx<this.Elements.length; idx++)
        {           
            this.Elements[idx].style.filter = 'blendTrans(duration=' + this.TransitionDuration + ')';
        }
        
        this.Initialized = true;
    }
    
    setTimeout(this.Name + '.ShowNext();', this.Interval);
}

SlideShow.prototype.constructor = SlideShow; 