Fade = {};

browserName = navigator.appName;
isIE = function() {
    if (browserName == "Microsoft Internet Explorer") {
        return true;
    }
    return false;
}

Fade.max = (isIE()) ? 100 : 1.00;
Fade.inc = (isIE()) ? 5 : 0.10;
Fade.time = 100;
Fade.id = null;
Fade.fadeOutHandler = null;
Fade.fadeInHandler = null;

Fade.fadeOut = function(id) {
    clearTimeout(Fade.id);
    var elm = document.getElementById(id);
    var opac;
    if (isIE()) {
        if (!elm.filters[0]) {
            return;
        }
        opac = elm.filters[0].opacity;
    } else {
        if(elm.style.MozOpacity){
            opac = elm.style.MozOpacity != '' ? parseFloat(elm.style.MozOpacity) : 0.8;
        }else{
            opac = elm.style.opacity != '' ? parseFloat(elm.style.opacity) : 0.8;
        }
    }

    if (opac > 0) {
        if (isIE()){
            elm.filters[0].opacity = opac - Fade.inc;
            }
        else {
            var value = parseFloat(opac) - Fade.inc;
            elm.style.MozOpacity = value;
            elm.style.opacity = value;
        }
        Fade.id = setTimeout("Fade.fadeOut('" + id + "')", 40);
    } else {
        if(Fade.fadeOutHandler != null){
            Fade.fadeOutHandler();
            Fade.fadeOutHandler = null;
        }
        if (elm.fadeLocation)
            window.location = elm.fadeLocation;
    }
}

Fade.fadeIn = function(id) {
    var done = false;
    clearTimeout(Fade.id);
    var elm = document.getElementById(id);
    if (isIE()) {
        if (!elm.filters[0]) {
            return;
        }
        opac = elm.filters[0].opacity;
    } else {
        if(elm.style.MozOpacity){
            opac = (elm.style.MozOpacity != '' && elm.style.MozOpacity != 0) ? parseFloat(elm.style.MozOpacity): 0;
        } else{
            opac = (elm.style.opacity != '' && elm.style.opacity != 0)? parseFloat(elm.style.opacity): 0;
        }
    }

    if (opac < Fade.max) {
        if (isIE()) {
            elm.filters[0].opacity = opac + Fade.inc;
        }
        else {
            var value = parseFloat(opac) + Fade.inc;
            elm.style.MozOpacity = value;

            elm.style.opacity = value;
        }

        Fade.id = setTimeout("Fade.fadeIn('" + id + "')", Fade.time);
    } else {
        if (elm.nextFadeId)
            setTimeout("Fade.fadeIn('" + elm.nextFadeId + "')", Fade.time);
        if(Fade.fateOutHandler != null){
            Fade.fateOutHandler();
            Fade.fateOutHandler = null;
        }
    }
}

Fade.reset = function(id) {
    var elm = document.getElementById(id);
    if (isIE()) {
        if (!elm.filters[0]) {
            return;
        }
        elm.filters[0].opacity = 0;
    }
    else {
        elm.style.MozOpacity = 0;
    }
}
