﻿function Fade(obj, increment, time)
{
    oThis = this;
    inc = increment;
    tim = time;
    object = obj;
    //object = document.getElementById(objectId);
    object.setAttribute("style","-moz-opacity:1;");  
    
    brows = object.filters? "ie" : typeof object.style.MozOpacity=="string"? "mozilla" : ""
    instant = Fade.prototype.instant;
    clearTimer = Fade.prototype.clearTimer;
    run = Fade.prototype.run;
    makeFade = Fade.prototype.makeFade;
    highlight = 0;   
    highlightFade = 0; 
}
Fade.prototype.instant = function(degree)
{ 
    try
    {
        if (brows=="mozilla")
        {
            object.style.MozOpacity=degree/100;   
        }
        else if (brows=="ie")
        {
            object.style.filter = "alpha(opacity=100)";
            object.filters.alpha.opacity=degree;
        }
    }
    catch(e)
    {
    }
}

Fade.prototype.clearTimer = function()
{
    if (highlight) 
    {
        clearInterval(highlight);
    }
    if (highlightFade) 
    {
        clearInterval(highlightFade);
    }
}

Fade.prototype.gradual = function(thisFade)
{ 
    if (thisFade.brows=="mozilla" && object.style.MozOpacity<1)
    {
        object.style.MozOpacity=parseFloat(object.style.MozOpacity) + inc/100;
    }
    else if (object.style.MozOpacity >= 1)
    {
        clearInterval(highlight);
    }            
    else if (thisFade.brows=="ie" && object.filters.alpha.opacity<100)
    {
        object.filters.alpha.opacity+=inc;
    }
    else if (thisFade.brows=="ie" && object.filters.alpha.opacity>=100)
    {
        clearInterval(highlight);
        object.style.filter = "";
    }    
    else if (highlight)
        clearInterval(highlight);
}

Fade.prototype.run = function()
{
    clearTimer();
    instant(0);    
    highlight=setInterval("Fade.prototype.gradual(this)",tim);
}

Fade.prototype.gradualFade = function(thisFade)
{
    if (thisFade.brows=="mozilla" && object.style.MozOpacity>0)
    {
        object.style.MozOpacity=parseFloat(object.style.MozOpacity) - inc/100;
    }
    else if (thisFade.brows=="mozilla" && object.style.MozOpacity <= 0)
    {
        clearInterval();
    }            
    else if (thisFade.brows=="ie" && object.filters.alpha.opacity>0)
    {
        object.filters.alpha.opacity-=inc;
    }    
    else if (thisFade.brows=="ie" && object.filters.alpha.opacity<=0)
    {
        clearInterval(highlightFade);
        clearTimeout(highlightFade);
    }    
    else if (highlightFade)
    {
        clearInterval(highlightFade);
    }
}

Fade.prototype.makeFade = function()
{
    clearTimer();
    instant(100);
 
    highlightFade=setInterval("Fade.prototype.gradualFade(this)",tim);
}    


