/**
	Filename    : MldTooltip.js
	Project     : MLDesigner v2.7.r00
	Copyright   : 2007 MLDesign Technologies, Inc.

	Description : Generates a dynamic, context-sensitive mouseover
	              tooltips inside Model-Imagemaps.
*/

function init()
{
    sTooltip  = null;             // global
    sMousePos = {x :  0, y :  0}; // global
    sOffset   = {x : 15, y : 15}; // global
    sIsIE     = (navigator.appName.indexOf('Explorer') != -1);
    document.body.onmousemove=trackMousePos;
};
function trackMousePos(pEvent)
{
    sMousePos.x=sIsIE?window.event.x:pEvent.pageX;
    sMousePos.y=sIsIE?window.event.y*1+document.body.scrollTop:pEvent.pageY;
    updatePosition(sTooltip)
};
function updatePosition(pTarget)
{
    if (pTarget != null)
    {
        //popup to the left if mousepos > pageWidth/2
        if ( (sMousePos.x*1 - window.scrollX*1) > window.innerWidth/2)
        {
            pTarget.style.left =
              sMousePos.x - pTarget.offsetWidth  - sOffset.x + 'px';
            pTarget.style.top  =
              pTarget.style.top =sMousePos.y*1 + sOffset.y*1 + 'px';
        }
        else
        {
            pTarget.style.left=sMousePos.x*1 + sOffset.x*1 + 'px';
            pTarget.style.top =sMousePos.y*1 + sOffset.y*1 + 'px';
        };
    }
};
function showTooltip()
{
    if(sTooltip!=null) return;
    var tSrc = document.getElementById(arguments[0]);
    if (tSrc == null) return;
    var tCC = tSrc.cloneNode(true);
    tCC.className = 'description';
    var tImage = document.createElement('img');
    tImage.setAttribute('src',tCC.getAttribute('icon'));                                  // instance icon
    var tNameTxt = document.createTextNode(' ' + tCC.getAttribute('name'));               // instance name
    var tLabelTxt  = document.createTextNode(tCC.getAttribute('label'));                  // instance label
    if (tLabelTxt.nodeValue != '') tLabelTxt.nodeValue = ' (' + tLabelTxt.nodeValue + ')';
    var tType   = document.createTextNode(' ' + tCC.getAttribute('tid') + ' ');           // instance type
    var tHeader = document.createElement('DIV');
    tHeader.className = 'header';
    tHeader.appendChild(tImage);
    tHeader.appendChild(tType);
    tHeader.appendChild(tNameTxt);
    tHeader.appendChild(tLabelTxt);
    sTooltip=document.createElement('DIV');
    sTooltip.className='mld-tooltip';
    sTooltip.style.maxWidth='600px';
    sTooltip.style.position='absolute';
    updatePosition(sTooltip);
    sTooltip.style.opacity=0.0;
    sTooltip.appendChild(tHeader);
    sTooltip.appendChild(tCC);
    document.body.appendChild(sTooltip);
    fade(0);
};
function hideTooltip(pEvent)
{
    if(sTooltip!=null)
    {
        sTooltip.parentNode.removeChild(sTooltip);
        sTooltip = null;
    };
};
function fade(pOpacity)
{
    var pContainer = sTooltip;
    if (pContainer!=null)
    {
        if (pOpacity<=97)
        {
            if (pContainer.style.MozOpacity!=null)
                pContainer.style.MozOpacity=(pOpacity/100)-.001;
            else if (pContainer.style.opacity!=null)
                pContainer.style.opacity=(pOpacity/100)-.001;
            else if (pContainer.style.filter!=null)
                pContainer.style.filter="alpha(opacity="+pOpacity+")";
            pOpacity+=6;
            window.setTimeout("fade("+pOpacity+")",20);
        }
    }
};

