Fade = {};
/*
browserName = navigator.appName;
isIE = function() {
    if (browserName == "Microsoft Internet Explorer") {
        return true;
    }
    return false;
}
*/
isIE = function() { return (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; }
isCHROME = function() { return (navigator.appVersion.indexOf("Chrome") != -1) ? true : false; }

Fade.max = (isIE()) ? 100 : 1.00;
Fade.inc = (isIE())? 2 : 0.02;
Fade.time = 40;
Fade.time2 = 40;
Fade.id = null;
Fade.fadeOutHandler = null;
Fade.fadeInHandler = null;
Fade.xOpacity;
Fade.xOpacity2;
Fade.clearTimeout=false;

Fade.fadeOut = function(id) {
    if(Fade.clearTimeout) clearTimeout(Fade.id);
    var elm = document.getElementById(id);
    if (isIE()) {
        xOpacity=elm.style.opacity!=undefined?elm.style.opacity:99;
    } else {
        if (elm.style.MozOpacity) {
            xOpacity = elm.style.MozOpacity != '' ? parseFloat(elm.style.MozOpacity) : 0.99;
        } else {
            xOpacity = elm.style.opacity != '' ? parseFloat(elm.style.opacity) : 0.99;
        }
    }

    if (xOpacity > 0) {
        var val = 0;
        if (isIE()) {
            var tmpVal = (xOpacity - Fade.inc);
            if (tmpVal > Fade.inc && tmpVal< 100) {
                val = tmpVal;
            }
        } else {
            var tmpVal = (parseFloat(xOpacity) - Fade.inc);
            if (tmpVal > Fade.inc && tmpVal < 1) {
                val = tmpVal;
            }
        }
		xOpacity=val;
		Fade.changeOpac(id);
        Fade.id = setTimeout("Fade.fadeOut('" + id + "')", Fade.time);
    } else {
        xOpacity=0;
		Fade.changeOpac(id);
        if (Fade.fadeOutHandler != null) {
            Fade.fadeOutHandler();
            Fade.fadeOutHandler = null;
        }
        if (elm.fadeLocation)
            window.location = elm.fadeLocation;
    }
}

Fade.fadeIn = function(id) {
    var done = false;
    if(Fade.clearTimeout) clearTimeout(Fade.id);
    var elm = document.getElementById(id);
    if (isIE()) {
		xOpacity2=(elm.style.opacity!=undefined && elm.style.opacity != 0)?elm.style.opacity:0;;
    } else {
        if (elm.style.MozOpacity) {
            xOpacity2 = (elm.style.MozOpacity != '' && elm.style.MozOpacity != 0) ? parseFloat(elm.style.MozOpacity) : 0;
        } else {
            xOpacity2 = (elm.style.opacity != '' && elm.style.opacity != 0) ? parseFloat(elm.style.opacity) : 0;
        }
    }

    if (xOpacity2 < Fade.max) {
        if (isIE()) {
            xOpacity2 = xOpacity2 + Fade.inc;
        }
        else {
            xOpacity2 = parseFloat(xOpacity2) + Fade.inc;
        }
		Fade.changeOpac2(id);
        Fade.id = setTimeout("Fade.fadeIn('" + id + "')", Fade.time2);
    } else {
        if (elm.nextFadeId)
            setTimeout("Fade.fadeIn('" + elm.nextFadeId + "')", Fade.time2);
        if(Fade.fadeInHandler != null){
            Fade.fadeInHandler();
            Fade.fadeInHandler = null;
        }
    }
}

Fade.reset = function(id) {
    xOpacity=0;
	Fade.changeOpac(id);
}

Fade.reset2 = function(id) {
    xOpacity2=0;
	Fade.changeOpac2(id);
}

Fade.changeOpac = function(id) {
    var object = document.getElementById(id).style;
    object.opacity = (xOpacity);
    object.MozOpacity = (xOpacity);
    object.KhtmlOpacity = (xOpacity);
    object.filter = "alpha(opacity=" + xOpacity + ")";
}

Fade.changeOpac2 = function(id) {
    var object = document.getElementById(id).style;
    object.opacity = (xOpacity2);
    object.MozOpacity = (xOpacity2);
    object.KhtmlOpacity = (xOpacity2);
    object.filter = "alpha(opacity=" + xOpacity2 + ")";
}
