function ImgSlide()
{
    this.opacity = 0;
    this.toid = null;
    this.curImage = 0;
    this.imageCount = 0;
    this.imgList = new Array();
    this.timeout = 50;
    this.swapTimeout = 4000;
}

ImgSlide.prototype.setTimeout = function(timeout)
{
    this.timeout = timeout;
}

ImgSlide.prototype.setSwapTimeout = function(timeout)
{
    this.swapTimeout = timeout;
}


ImgSlide.prototype.addImg = function(id)
{
    this.imgList.push(id);
    this.imageCount++;
}

ImgSlide.prototype.setOpacity = function(obj, val)
{
    if (val < 0) val = 0;
    if (val > 1) val = 1;
    if (isIE) {
        obj.style.filter = "alpha(opacity=" + (val * 100) + ")";
    } else {
        obj.style.opacity = val;
        obj.style.MozOpacity = val;
    }
};

ImgSlide.prototype.doFade = function(img_now, img_next)
{
    var tmpObject = this;
    this.opacity -= 0.04;
    this.setOpacity(img_now, this.opacity);
    this.setOpacity(img_next, 1 - this.opacity);
    if (this.opacity <= 0) {
      img_now.style.display = 'none';
    } else {
        setTimeout(
            function() {
                tmpObject.doFade(img_now, img_next);
            }, this.timeout);
    }
}

ImgSlide.prototype.doSwap = function()
{
    if (this.opacity > 0) return;
    var imgNow = document.getElementById(this.imgList[this.curImage]);

    if (++this.curImage >= this.imageCount) {
        this.curImage = 0;
    }
    var imgNext = document.getElementById(this.imgList[this.curImage]);

    this.setOpacity(imgNext, 0);
    imgNext.style.display = 'block';

    this.opacity = 1;
    var tmpObject = this;
    setTimeout(
        function() {
            tmpObject.doFade(imgNow, imgNext);
        }, this.timeout);
};


ImgSlide.prototype.slideSwap = function()
{
    if (this.toid != null) {
        clearTimeout(this.toid);
        this.doSwap();
    }

    var tmpObject = this;
    this.toid = setTimeout(
        function() {
            tmpObject.slideSwap();
        }, this.swapTimeout);
};

ImgSlide.prototype.run = function() {    
    add_event_listener(isIE ? document : window, 'load', this.slideSwap());
};

