
var toolTip = null;
var offsetxpoint = 10; //Customize x offset of tooltip
var offsetypoint = 10; //Customize y offset of tooltip
document.onmousemove = updateToolTip;
function updateToolTip(e) {
	
	// current mouse position
    x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
    y = (document.all) ? window.event.y + scrollHeight() : e.pageY;
    
	//Find out how close the mouse is to the corner of the window
    var rightedge = windowWidth()+scrollWidth() - (x + offsetxpoint);
    var bottomedge = windowHeight()+scrollHeight() - (y + offsetypoint);
    var leftedge = (offsetxpoint < 0) ? offsetxpoint * (-1) : offsetxpoint;
    
    if (toolTip != null) {
				
		//if the horizontal distance isn't enough to accomodate the width of the context menu
        if (rightedge < toolTip.offsetWidth) {
	  		//move the horizontal position of the menu to the left by it's width
            toolTip.style.left = (x - toolTip.offsetWidth - offsetxpoint) + "px";
		//move the horizontal position of the menu to the left to fit in
	  		//toolTip.style.left=(((document.all) ? document.body.scrollLeft : window.pageXOffset)+x-(toolTip.offsetWidth-rightedge)+"px";
        } else if (x < leftedge) {
                toolTip.style.left = "5px";
        } else {
			//position the horizontal position of the menu where the mouse is positioned
                toolTip.style.left = (x + offsetxpoint) + "px";
        }
        
	
		//same concept with the vertical position ((document.all) ? document.body.scrollTop : window.pageYOffset)
        if (bottomedge < toolTip.offsetHeight) {
            toolTip.style.top = (y - toolTip.offsetHeight - offsetypoint) + "px";
        } else {
            toolTip.style.top = (y + offsetypoint) + "px";
        }
    }
}
function showToolTip(id) {
    toolTip = document.getElementById(id);
    toolTip.style.display = "block";
}
function hideToolTip() {
    toolTip.style.display = "none";
}
function windowWidth() {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (document.body && document.body.offsetWidth) {
            return document.body.offsetWidth;
    } else if (document.documentElement && document.documentElement.offsetWidth) {
                return document.documentElement.offsetWidth;
    } else {
                return 0;
    }
}

function windowHeight() {
    if (window.innerHeight) {
        return window.innerHeight;
    } else if (document.body && document.body.offsetHeight) {
            return document.body.offsetHeight;
    } else if (document.documentElement && document.documentElement.offsetHeight) {
                return document.documentElement.offsetHeight;
    } else {
            return 0;
    }
}
function scrollHeight() {
    if (window.pageYOffset) {
        return window.pageYOffset;
    } else if (document.body && document.body.scrollTop) {
            return document.body.scrollTop;
    } else if (document.documentElement && document.documentElement.scrollTop) {
                return document.documentElement.scrollTop;
    } else {
            return 0;
    }
}
function scrollWidth() {
    if (window.pageXOffset) {
        return window.pageXOffset;
    } else if (document.body && document.body.scrollLeft) {
            return document.body.scrollLeft;
    } else if (document.documentElement && document.documentElement.scrollLeft) {
                return document.documentElement.scrollLeft;
    } else {
            return 0;
    }
}

