// slideshow
function Fader(id, fadetime) {
    this.id = id;
    this.fadetime = fadetime;
    
    this.images = document.getElementById(this.id).getElementsByTagName("img");
    this.counter = 0;

    this.fade = function(step) {
        var fader = this;

        step = step || 0;

        this.images[this.counter].style.opacity = step/100;
        this.images[this.counter].style.filter = "alpha(opacity=" + step + ")"; // IE?

        step = step + 2;

        if (step <= 100) {
            window.setTimeout(function() { fader.fade(step); }, 1);
        } else {
            window.setTimeout(function() { fader.next(); }, this.fadetime);
        }
    };
	
    this.fadeOut = function(step) {
        var fader = this;

        step = step || 100;

        this.images[this.counter].style.opacity = step/100;
        this.images[this.counter].style.filter = "alpha(opacity=" + step + ")"; // IE?

        step = step - 2;

        if (step > 0) {
            window.setTimeout(function() { fader.fadeOut(step); }, 1);
        } else {
            window.setTimeout(function() {
				fader.counter = 0;
				fader.next(); 
			}, this.fadetime);
        }
    };

    this.next = function() {
	    if (this.images.length > 1) {
	        if (this.counter+1 < this.images.length) {
				this.counter++;
				this.fade();
			} else {			
				for (var i=1; i<this.images.length-1; i++) {
	        		this.images[i].style.opacity = 0;
	        		this.images[i].style.filter = "alpha(opacity=0)"; // IE?
				}
				
				this.fadeOut();
	        }
	    }
    }
    
    this.start = function() {
        var fader = this;
        window.setTimeout(function() { fader.next(); }, this.fadetime);
    }
}
