var body;
var tooltip;
var tooltip_mX;
var tooltip_mY;
var tooltip_show;

var tooltip_show_static;
var tooltip_timeout;

function tooltipInit()
{
    //body = document.getElementsByTagName('body')[0];
    body = document.lastChild;
//    if((body == NULL) || (body.scrollLeft == NULL))
//      body = document.documentElement.lastChild;
    tooltip = document.getElementById('tooltip');
    document.onmousemove = tooltipMoveHandler;
}

function tooltipMoveHandler(e)
{
        if(document.all) e = event;

	tooltip_mX = e.clientX + body.scrollLeft + 10 + "px";
        tooltip_mY = e.clientY + body.scrollTop + 5 + "px";
        //tooltip_mX = e.pageX + 0 + "px";
        //tooltip_mY = e.pageY + 0 + "px";

    if(tooltip_show)
    {
        tooltipMove();
    }
    return true;
}

function tooltipMove()
{
    tooltip.style.left = tooltip_mX;// + 10 + "px";
    tooltip.style.top = tooltip_mY;// + 5 + "px";
}

function tooltipShow(obj,tekst)
{
    tooltip_show = true;
    tooltipMove();
    tooltip.innerHTML = tekst;
    tooltip.style.visibility = "visible";
}

function tooltipHide(obj)
{
    tooltip_show = false;
    tooltip.style.visibility = "hidden";
    tooltip.style.left = 0 + "px";
    tooltip.style.top = -200 + "px";
}

////////Tooltip nieruchomy/////////////////////////////

function tooltipShowStatic(e,tekst)
{
    tooltip_timeout = false;
    
    if(!tooltip_show_static)
    {
    tooltip_show_static = true;
    tooltip.innerHTML = tekst;
    
        if(document.all) e = event;

        tooltip_mX = e.clientX + body.scrollLeft + 5;
        tooltip_mY = e.clientY + body.scrollTop + 10;
        if(tooltip.firstChild)
        if(tooltip.firstChild.style)
        if(tooltip.firstChild.style.width)
        {
            tooltip_width = parseWidth(tooltip.firstChild.style.width)
            if(tooltip_width + tooltip_mX > body.clientWidth)
                tooltip_mX = body.clientWidth - tooltip_width - 20;
        }
        
        tooltip.style.top = tooltip_mY + "px";
        tooltip.style.left = tooltip_mX + "px";
    
    tooltip.style.visibility = "visible";
    
    }
}

function tooltipHideStatic()
{
    tooltip_show_static = false; 
    tooltip.style.visibility = "hidden"; 
    tooltip.style.left = 0 + "px"; 
    tooltip.style.top =  -200 + "px";
}

function tooltipSetTimeout()
{
    tooltip_timeout = true;
    window.setTimeout('if(tooltip_timeout) { tooltipHideStatic(); window.clearTimeout(); tooltip_timeout = false; }',200);
}
