﻿function SlideShow(div, content) {

    this.id = SlideShow.Instances.length;
    SlideShow.Instances[this.id] = this;

    this.div = div;
    this.tmr1 = null;
    this.tmr2 = null;
    this.clevel = 100;
    this.level = 100;
    this.step = 1;
    this.speed = 5;
    this.dim = 0;
    this.bright = 100;
    this.Pic = content;
    this.p = this.Pic.length;
    this.j = 0;
    this.preLoad = new Array();
    this.wait = 2000;
    this.dwell = 300;
    this.period = 7000;
    this.elm = document.getElementById(div);
    this.slide = null;
    this.bottom = null;
    for (i = 0; i < this.p; i++) {
        this.preLoad[i] = new Image();
        this.preLoad[i].src = 'images/' + this.Pic[i] + '.gif';
    }

    this.elm.innerHTML = "";
    
    this.slide = document.createElement("img");
    this.slide.setAttribute("src", this.preLoad[this.j].src);
    this.slide.setAttribute("border", "0");
    this.elm.style.backgroundRepeat="no-repeat";
    this.elm.style.backgroundPosition="left top";
    this.elm.appendChild(this.slide);
    this.j++;

    if (!document.all) {
        this.tmr1 = setInterval('SlideShow.Instances[' + this.id + '].fader()', this.speed);
        }
    this.tmr1 = setInterval('SlideShow.Instances[' + this.id + '].next()', this.period);
    this.wait = this.dwell + (this.speed * (this.bright - this.dim) / this.step);
    this.dofade = function() {
        this.slide.style.opacity = this.clevel / 100;
        this.slide.style.filter = "alpha(opacity=" + this.clevel + ");";

    }
    this.fader = function() {
        //if (this.clevel < this.level - this.step) this.clevel += this.step;
        if (this.clevel > this.level + this.step) this.clevel -= this.step;
        else this.clevel = this.level;
        this.dofade();
    }
    this.next = function() {
        if (document.all) {
            this.slide.style.filter = "blendTrans(duration=3)";
            this.slide.filters.blendTrans.Apply();
            this.slide.src = this.preLoad[this.j].src;
            this.slide.filters.blendTrans.Play();
            this.j = this.j + 1;
            if (this.j > (this.p - 1)) this.j = 0;
        }
        else {
            this.elm.style.backgroundImage = "url(" + this.preLoad[this.j].src + ")";
            this.level = this.dim;
            setTimeout('SlideShow.Instances[' + this.id + '].nextSlide()', this.wait);
        }
    }
    this.nextSlide = function() {
    this.slide.setAttribute("src", this.preLoad[this.j].src);
    this.slide.style.opacity = this.bright / 100;
    this.slide.style.filter = "alpha(opacity=" + this.bright + ");";
        this.clevel = this.bright;
        this.level = this.bright;
        this.j = this.j + 1;
        if (this.j > (this.p - 1)) this.j = 0;
    }
}

