var Slideshow = function  (slideSetId, playSpeed) {

    this.playSpeed = playSpeed;
    this.slideSet = $(slideSetId);
    this.slideList = this.slideSet.getElementsByClassName('slide');
    this.currentSlideIndex = 0;
    this.showSlide(this.currentSlideIndex);
    for (var i=0; i < this.slideList.length; i++) {
        this.initSlide(i);
    }
    this.slideSet.style.display = 'block';
    this.playIntervalId = false;

}


Slideshow.prototype = {


    play : function () {
        if (this.playIntervalId) {
            return;
        }
        var slideshow = this;
        this.next();
        this.playIntervalId = setInterval(function () { slideshow.next(); }, this.playSpeed);
    },


    pause : function () {
        if (! this.playIntervalId) {
            return;
        }
        clearInterval(this.playIntervalId);
        this.playIntervalId = false;
    },


    togglePlay : function () {
        if (this.playIntervalId) {
            this.pause();
        } else {
            this.play();
        }
    },


    next : function () {
        if (this.currentSlideIndex == this.slideList.length - 1) {
            this.pause();
            return;
        }
        this.hideSlide(this.currentSlideIndex);
        this.currentSlideIndex++;
        this.showSlide(this.currentSlideIndex);
    },


    previous : function () {
        if (this.currentSlideIndex == 0) {
            return;
        }
        this.hideSlide(this.currentSlideIndex);
        this.currentSlideIndex--;
        this.showSlide(this.currentSlideIndex);
    },


    rewind : function () {
        this.hideSlide(this.currentSlideIndex);
        this.currentSlideIndex = 0;
        this.showSlide(this.currentSlideIndex);
    },


    hideSlide : function (slideIndex) {
        Effect.Fade(this.slideList[slideIndex]);
    },


    showSlide : function (slideIndex) {
        Effect.Appear(this.slideList[slideIndex]);
    },

    initSlide : function (slideIndex) {
        this.slideList[slideIndex].style.position = 'absolute';
        this.slideList[slideIndex].style.top = 0;
        this.slideList[slideIndex].style.left = 0;
        this.slideList[slideIndex].style.display = 'none';
    }


};