var timer=null;
var currentOpacity=0;
var selectedObj=null;
var cycled=0;
var maxCycle=0;
var currentInterval=0;

window.onresize=sizeFader;
window.onscroll=sizeFader;
    
/************************************************************\
*
\************************************************************/
function drawBlack()
{
    pasteRawHTML("<div id=\"blackBox\" style=\"visibility:visible;position:fixed;top:0;left:0;z-index:1;background-color:#94a0b3;padding:0px;margin:0px;top:0px;left:0px;width:100%;height:100%\">&nbsp;</div>",document.body);
}
/************************************************************\
*
\************************************************************/
function sizeFader()
{
    if (document.getElementById("blackBox")!=null)
    {
        var docHeight=(typeof document.height != 'undefined')?document.height:(document.compatMode && document.compatMode != 'BackCompat')?document.documentElement.scrollHeight:document.body.scrollHeight;
        var wh=getWindowHeight();
        if (docHeight<wh) docHeight=wh;
        obj=document.getElementById("blackBox");
        docHeight=document.getElementById("footer").offsetTop+document.getElementById("footer").offsetHeight;
        obj.style.height=docHeight+"px";
    }
    if (document.getElementById(centeredObjectId)!=null) {
        if (document.getElementById(centeredObjectId).offsetHeight<getWindowHeight()) {
            centerObject(document.getElementById(centeredObjectId));
        }
    }
}
/************************************************************\
*
\************************************************************/
function fader(obj,opacity)
{
    if (obj.style)
    {
        if (obj.style.MozOpacity!=null)
        {
            obj.style.MozOpacity = (opacity/100) - .001;
        }
        else if (obj.style.opacity!=null)
        {
            obj.style.opacity = (opacity/100) - .001;
        }
        else if (obj.style.filter!=null)
        {
            obj.style.filter = "alpha(opacity="+opacity+")";
        }
    }
}
/************************************************************\
*
\************************************************************/
function fadeUpTimer()
{
    obj=document.getElementById("blackBox");
    var desiredDarkness=80;
    currentOpacity+=10;
    if (currentOpacity>desiredDarkness)
    {
        currentOpacity=desiredDarkness;
    }
    fader(obj,currentOpacity);
    if (currentOpacity==desiredDarkness)
    {
        clearTimeout(timer);
    }
    else
    {
        timer = setTimeout("fadeUpTimer()",2);
    }
}
/************************************************************\
*
\************************************************************/
function fadeDownTimer()
{
    obj=document.getElementById("blackBox");
    currentOpacity-=10;
    if (currentOpacity<0)
    {
        currentOpacity=0;
    }
    fader(obj,currentOpacity);
    if (currentOpacity==0)
    {
        clearTimeout(timer);
        removeTheNode("blackBox");
        window.onresize=null;
    }
    else
    {
        timer = setTimeout("fadeDownTimer()",2);
    }
}
/************************************************************\
*
\************************************************************/
function startFadeUp()
{
    currentOpacity=0;
    if (document.getElementById("blackBox")==null)
    {
        drawBlack();
    }
    sizeFader();
    obj=document.getElementById("blackBox");
    fader(obj,0);
    //obj.style.height=document.body.clientHeight+"px";
    obj.style.visibility="visible";
    if (typeof timer != 'undefined') clearTimeout(timer);
    timer = setTimeout("fadeUpTimer()",2);
}
/************************************************************\
*
\************************************************************/
function startFadeDown()
{
    if (document.getElementById("blackBox")!=null)
    {
        obj=document.getElementById("blackBox");
        if (typeof timer != 'undefined') clearTimeout(timer);
        timer = setTimeout("fadeDownTimer()",2);
    }
}
/************************************************************\
*
\************************************************************/
function flashThisObject(obj,repeats,interval)
{
    selectedObj=obj;
    currentInterval=interval;
    maxCycle=repeats;
    cycled=0;
    selectedObj.style.visibility="hidden";
    //fader(obj,0);
    if (typeof timer != 'undefined') clearTimeout(timer);
    timer = setTimeout("flashUpObject()",interval);
}
/************************************************************\
*
\************************************************************/
function flashUpObject()
{
    selectedObj.style.visibility="visible";
    //fader(selectedObj,100);
    cycled++;
    if (cycled<maxCycle)
    {
        timer = setTimeout("flashDownObject()",currentInterval);
    }
}
/************************************************************\
*
\************************************************************/
function flashDownObject()
{
    selectedObj.style.visibility="hidden";
    //fader(selectedObj,0);
    timer = setTimeout("flashUpObject()",currentInterval);
}
/************************************************************\
*
\************************************************************/
function getWindowHeight()
{
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' )
    {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    }
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    }
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return myHeight;
}
/************************************************************\
*
\************************************************************/
function getWindowWidth()
{
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' )
    {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    }
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    }
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return myWidth;
} 