﻿var x;
if (x) {
    if (typeof (cf) == "undefined")
        var cf;
}
else {
    var cf = this;
}

cf.fader = function(obj, fadetime, delay) {
    this.el2 = -1;
    this.id = obj;
    for (i = 0; i < obj.length; i++) {
        var s = document.getElementById("img_" + obj[i]).style;
        s.position = "absolute";
        s.visibility = "hidden";
        s.opacity = 0; 
        s.filter = "alpha(opacity=0)";
    }
    this.dur = fadetime;
    this.delay = delay;
    this.fade2();
}

cf.fader.prototype.fade1 = function() {
    this.time += this.interval;
    var ieop = Math.round(this.fade(this.time, 0, 1, this.dur) * 100);
    var op = ieop / 100;
    var s = document.getElementById("img_" + this.id[this.el2]).style;
    s.opacity = op;
    s.filter = "alpha(opacity=" + ieop + ")";
    if (this.el1 > -1) {
        var s = document.getElementById("img_" + this.id[this.el1]).style;
        s.opacity = 1 - op;
        s.filter = "alpha(opacity=" + (100 - ieop) + ")";
    }

    if (ieop == 50) {
            if(this.el1 != -1)
                document.getElementById(this.id[this.el1]).className = "hidden";
            document.getElementById(this.id[this.el2]).className = "";        
    }
    
    if (this.time == this.dur) {
        clearInterval(this.id1);
        if (this.el1 > -1) {
            document.getElementById("img_" + this.id[this.el1]).style.visibility = "hidden";
        }
        var t = this;
        this.id2 = setInterval(function() { t.fade2() }, this.delay);
    }
}

cf.fader.prototype.fade2 = function() {
    if (this.id2)
        clearInterval(this.id2);
    this.el1 = this.el2;
    this.el2++;
    if (!this.id[this.el2]) this.el2 = 0;
    if (this.el2 == this.el1)
        return false;
    document.getElementById("img_" + this.id[this.el2]).style.visibility = "visible";
    this.interval = 50;
    this.time = 0;
    var t = this;
    this.id1 = setInterval(function() { t.fade1() }, this.interval);
}

cf.fader.prototype.fade = function(t, b, c, d) {
    return c / 2 * (1 - Math.cos(Math.PI * t / d)) + b;
}

cf.fader.prototype.pause = function() {

clearInterval(this.id1);
clearInterval(this.id2);
}


cf.fader.prototype.resume = function() {
    this.fade2();
}
