/* Javascript functions for invoking timed tooltips */

   var currenttooltip=0;
   var tt_hasmoved=new Date();
   var tt_showing=0;
   var divshim=0;
   var isOpera = (navigator.userAgent.indexOf("Opera") != -1);
   var isIE = navigator.userAgent.indexOf("MSIE") > 1 && !isOpera;

   document.onmousemove = updateMouseMove;

function updateMouseMove(e)
{
    var x=0;
    var y=0;
    if(!document.all)
    {
	x = e.pageX;
	y = e.pageY;
    }
    else 
    {
	x = window.event.x;
	y = window.event.y;
	if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
        {
    	    x = x + document.body.scrollLeft;
    	    y = y + document.body.scrollTop;
        } 
        else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
        {
       	    //IE6 standards compliant mode
    	    x = x + document.documentElement.scrollLeft;
    	    y = y + document.documentElement.scrollTop;
	}
    }

    if (currenttooltip) 
    {
	offsetx = x + 10;
	offsety = y + 10;
        currenttooltip.style.left = offsetx + "px";
        currenttooltip.style.top = offsety + "px";
        if(divshim)
        {
            divshim.style.left = offsetx + "px";
            divshim.style.top = offsety + "px";
            divshim.style.width = currenttooltip.offsetWidth;
            divshim.style.height = currenttooltip.offsetHeight;
        }
        if(tt_showing == 0)
        {
            showTooltip2(); 
        }
	else
	{
	    /* hide the tooltip immediately */
	    hideTooltip();
	}
    }
    tt_hasmoved=new Date();
}

function showTooltip(elid)
{
    el = findObject(elid);
    if(el && tt_showing==0)
    {
	currenttooltip=el;
        showTooltip2();
    }    
}

function showTooltip2()
{
    window.setTimeout(showTooltip3,1000);
}

function showTooltip3()
{
    var date=new Date();
    if(currenttooltip && tt_hasmoved && tt_showing==0 && (date - tt_hasmoved > 900))
    {
        if(! divshim && isIE)
        {
            divshim = findObject('DivShim',0);
        }
        currenttooltip.style.display = "block";
	var totalwidth = 0;
	var totalheight = 0;
	if(document.all)
	{
	    totalwidth = document.body.clientWidth + document.body.scrollLeft;
	    totalheight = document.body.clientHeight + document.body.scrollTop;
	}
	else
	{
	    totalwidth = window.innerWidth + window.pageXOffset;
	    totalheight = window.innerHeight + window.pageYOffset;
	}
	if((parseInt(currenttooltip.style.left) + parseInt(currenttooltip.offsetWidth)+10) > totalwidth)
	{
	    currenttooltip.style.left = (totalwidth - parseInt(currenttooltip.offsetWidth) - 10) + "px";
	}
	if((parseInt(currenttooltip.style.top) + parseInt(currenttooltip.offsetHeight)+10) > totalheight)
	{
	    currenttooltip.style.top = (totalheight - parseInt(currenttooltip.offsetHeight) - 10) + "px";
	}
        currenttooltip.style.zIndex = 999999;
        if(divshim)
        {
            divshim.style.display = "block";
            divshim.style.left = currenttooltip.style.left;
            divshim.style.top = currenttooltip.style.top;
            divshim.style.width = currenttooltip.offsetWidth;
            divshim.style.height = currenttooltip.offsetHeight;
            divshim.style.zIndex = currenttooltip.style.zIndex - 1;
        }
        tt_showing=1;
	hideTooltip2();
    }
}

function hideTooltip2()
{
    window.setTimeout(hideTooltip3,5000);
}

function hideTooltip3()
{
    /* only hide the tooltip after X time if we are still showing the 
     * same tooltip. For that, check the tt_hasmoved variable to see
     * if this is actually a timeout 
     */
    var date=new Date();
    if(currenttooltip && tt_hasmoved && tt_showing==1 && (date - tt_hasmoved > 4990))
    {
	hideTooltip();
    }
}

function hideTooltip()
{
    if(currenttooltip)
    {
        currenttooltip.style.display = "none";
        if(divshim)
        {
            divshim.style.display = "none";
        }
        currenttooltip=0;
        tt_showing=0;
    }
}


