var timer=null;
var currentOpacity=0;
var selectedObj=null;
var cycled=0;
var maxCycle=0;
var currentInterval=0;
var desiredDarkness=80;
var fadeInOutObj=null;
var fadeInOutOpacity=0;
/************************************************************\
*
\************************************************************/
function drawBlack()
{

    pasteRawHTML("<div id=\"blackBox\" style=\"visibility:visible;position:absolute;z-index:51;background-color:#000000;padding:0px;margin:0px;top:0px;left:0px;width:100%;height:100%\" onmouseover=\"removeTheNode('shortlist')\">&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");
        obj.style.height=docHeight+"px";
    }
    if (document.getElementById("dialogBox")!=null) centerObject(document.getElementById("dialogBox"));
}
/************************************************************\
*
\************************************************************/
function fader(obj,opacity)
{
    boxObj=null;
    var fullscaleopacity=opacity*(100/desiredDarkness);
    if (document.getElementById("dialogBox")!=null) boxObj=document.getElementById("dialogBox");
    if (obj.style)
    {
        if (obj.style.MozOpacity!=null)
        {
            obj.style.MozOpacity = (opacity/100) - .001;
            if (boxObj!=null) boxObj.style.MozOpacity = (fullscaleopacity/100) - .001;
        }
        else if (obj.style.opacity!=null)
        {
            obj.style.opacity = (opacity/100) - .001;
            if (boxObj!=null) boxObj.style.opacity = (fullscaleopacity/100) - .001;
        }
        else if (obj.style.filter!=null)
        {
            obj.style.filter = "alpha(opacity="+opacity+")";
            if (boxObj!=null) boxObj.style.filter = "alpha(opacity="+fullscaleopacity+")";
        }
    }
}
/************************************************************\
*
\************************************************************/
function fadeUpTimer()
{
    obj=document.getElementById("blackBox");
    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");
        removeTheNode("dialogBox");
        window.onresize=null;
        window.onscroll=null;
    }
    else
    {
        timer = setTimeout("fadeDownTimer()",2);
    }
}
/************************************************************\
*
\************************************************************/
function startFadeUp()
{
    window.onresize=sizeFader;
    window.onscroll=sizeFader;
    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 myHeight = ( typeof( window.innerWidth ) == 'number' )?window.innerHeight:( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )?document.documentElement.clientHeight: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;
} 
/************************************************************\
*
\************************************************************/
function startFadeIn(srcObj)
{
    fadeInOutObj=srcObj;
    fadeInOutOpacity=0;
    fader(fadeInOutObj,fadeInOutOpacity);
    fadeInOutObj.style.visibility="visible";
    if (typeof timer != 'undefined') clearTimeout(timer);
    timer = setTimeout("fadeInTimer()",2);
}
function fadeInTimer()
{
    fadeInOutOpacity+=10;
    fader(fadeInOutObj,fadeInOutOpacity);
    if (fadeInOutOpacity==100)
    {
        clearTimeout(timer);
    }
    else
    {
        timer = setTimeout("fadeInTimer()",2);
    }
}
function startFadeOut(srcObj)
{
    if (fadeInOutObj!==srcObj) {
        fadeInOutObj=srcObj;
        fadeInOutOpacity=100;
    }
    fader(fadeInOutObj,fadeInOutOpacity);
    if (typeof timer != 'undefined') clearTimeout(timer);
    timer = setTimeout("fadeOutTimer()",2);
}
function fadeOutTimer()
{
    fadeInOutOpacity-=10;
    fader(fadeInOutObj,fadeInOutOpacity);
    if (fadeInOutOpacity<10)
    {
        clearTimeout(timer);
        removeTheNode(fadeInOutObj.id);
        fadeInOutObj=null;
        fadeInOutOpacity=0;
    }
    else
    {
        timer = setTimeout("fadeOutTimer()",2);
    }
}
