// JavaScript Document
var hintPos = [15, 15];
var hintMargin = 20;
var hints = new Array();

function truebody()
{
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function addHint(id, text)
{
    hints[id] = escape(text);
}

function getHintBox()
{
    if (document.getElementById)
    return document.getElementById("mainHintDiv")
    else if (document.all)
    return document.all.mainHintDiv
    return false;
}
function createHintBox()
{
    var div = document.createElement('div');
    div.setAttribute('id', 'mainHintDiv');
    div.style.position = 'absolute';
    div.style.zIndex = '200';
    div.style.left = '-600px';
//    div.style.border = '1px solid red';
    div.style.display = 'none';
    document.getElementsByTagName('body')[0].appendChild(div);
}
function followMouse(evt)
{
    currentimageheight = 200;
    xPos = hintPos[0];
    yPos = hintPos[1];
    if (hintBox = getHintBox())
    {
        var docwidth = document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
        var docheight = document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

        boxWidth = hintBox.offsetWidth;
        boxHeight = hintBox.offsetHeight;
        currentimageheight = boxHeight;
/*        if (document.all){
            hintBox.innerHTML = 'oW = ' + hintBox.offsetWidth + '<br>oH = ' + hintBox.offsetHeight + '<br>A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
        } else {
            hintBox.innerHTML = 'oW = ' + hintBox.offsetWidth + '<br>oH = ' + hintBox.offsetHeight + '<br>pageX = ' + evt.pageX + '<br>pageY = ' + evt.pageY + '<br>C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
        }*/
        
        if (typeof evt != "undefined")
        {
            if ((docwidth - evt.pageX) < (boxWidth + hintMargin))
            {
                xPos = evt.pageX - xPos - boxWidth; // Move to the left side of the cursor
            }
            else
            {
                xPos += evt.pageX;
            }
            if (docheight - evt.pageY < (currentimageheight + hintMargin))
            {
                yPos += evt.pageY - Math.max(0,(hintMargin + currentimageheight + evt.pageY - docheight - truebody().scrollTop));
            }
            else
            {
                yPos += evt.pageY;
            }
        }
        else if (typeof window.event != "undefined")
        {
            if (docwidth - event.clientX < (boxWidth + hintMargin))
            {
                xPos = event.clientX + truebody().scrollLeft - xPos - boxWidth; // Move to the left side of the cursor
            }
            else
            {
                xPos += truebody().scrollLeft+event.clientX
            }
            if (docheight - event.clientY < (currentimageheight + hintMargin))
            {
                yPos += event.clientY + truebody().scrollTop - Math.max(0,(hintMargin + currentimageheight + event.clientY - docheight));
            }
            else
            {
                yPos += truebody().scrollTop + event.clientY;
            }
        }
        hintBox.style.left = xPos + 'px';
        hintBox.style.top = yPos + 'px';
    }
}
function showHint(hint, ta)
{
    if (!ta) ta = 'center';
    if (!getHintBox()) createHintBox();
    if (hintBox = getHintBox())
    {
        if (document.onmousemove != '')
        {
            func = document.onmousemove;
            if ( typeof (func) == 'function' ) func(true);
        }
        document.onmousemove = followMouse;
        var innerHTML = "<div style=\"padding: 5px; border: 1px solid #888; background-color: #fff; text-align: " + ta + "\">" + unescape(hint) + "</div>";
        hintBox.innerHTML = innerHTML;
        hintBox.style.display = 'inline';
//        alert (this.hintBox.style.width);
    }
}
function showHintA(hintID, ta)
{
    if (!ta) ta = 'center';
    if (!getHintBox()) createHintBox();
    if ((hintBox = getHintBox()) && hints[hintID])
    {
        if (document.onmousemove != '')
        {
            func = document.onmousemove;
            if ( typeof (func) == 'function' ) func(true);
        }
        document.onmousemove = followMouse;
        var innerHTML = "<div style=\"padding: 5px; border: 1px solid #888; background-color: #fff; text-align: " + ta + "\">" + unescape(hints[hintID]) + "</div>";
        hintBox.innerHTML = innerHTML;
        hintBox.style.display = 'inline';
//        alert (this.hintBox.style.width);
    }
}
function hideHint()
{
    if (hintBox = getHintBox())
    {
        hintBox.innerHTML = ' ';
        hintBox.style.display = 'none';
        document.onmousemove = '';
        hintBox.style.left = '-600px';
    }
}
