﻿// JScript File

var tooltipHideInterval, tooltipShowInterval;
var mouseOverToolTip = false;
var tooltipMessage;

function refreshMouseCoordinates(evt) {
    currentX = window.event.clientX;
    currentY = window.event.clientY;
}

function hideToolTip() {
    tooltipHideInterval = setInterval("__hideToolTip()", 1000);
    clearInterval(tooltipShowInterval);
}

function __hideToolTip() {
    var tooltipDiv;
    
    tooltipDiv = document.getElementById("ToolTipDiv");
    
    if (!mouseOverToolTip) {
        tooltipDiv.style.visibility = "hidden";
        clearInterval (tooltipHideInterval);
    }
}

function showToolTip(message) {  
    clearInterval(tooltipHideInterval);
    tooltipMessage = message;
    tooltipShowInterval = setInterval("__showToolTip()", 1000);
}

function __showToolTip() {
    var tooltipDiv;  
    var tooltipContents;
    
    var x, y;
    var toolTipWidth, toolTipHeight;
    var src;
    var flipX, flipY;
    var imgNum;
    
    clearInterval(tooltipHideInterval);
    clearInterval(tooltipShowInterval);
    
    tooltipDiv = document.getElementById("ToolTipDiv");
    tooltipContents = document.getElementById("ToolTipContents");
    x = currentX;
    y = currentY;        
    toolTipWidth = tooltipDiv.clientWidth;
    toolTipHeight = tooltipDiv.clientHeight;   
    
    
    if (x + toolTipWidth > document.body.clientWidth) {
        flipX = true;
        x = x - Math.floor(toolTipWidth / 2) - 35; 
    } else {
        flipX = false;
        x = x - Math.floor(toolTipWidth / 2) + 35; 
    }
    if (y < toolTipHeight) {
        flipY = true;
        tooltipContents.style.top = "45px";
    } else { 
        flipY = false;
        y -= toolTipHeight;
        tooltipContents.style.top = "15px";
    }
    
    if (flipY && flipX) { 
        imgNum = 4;
    }
    else if (flipY) {
        imgNum = 3;
    }
    else if (flipX) {
        imgNum = 2;
    }
    else {
        imgNum = 1;
    }
    
    src = "/lists/images/shadedTooltip" + imgNum + ".png";
    
    tooltipDiv.style.left = x;
    tooltipDiv.style.top = y;
    tooltipDiv.style.backgroundImage = "url(" + src + ")"; 
    tooltipDiv.style.visibility = "visible"; 
    
    tooltipContents.innerHTML = tooltipMessage;
}
