/* 
========================================================================================================= CREDITS
Copyright 	: Copyright (c) 2009 JPL & Pinnacle Health. All Rights Reserved.
Author(s) 	: Larry Daughenbaugh - ldaugh@jplcreative.com
			: Based off of script from Dynamic Drive DHTML code library [ www.dynamicdrive.com ]
Date      	: 3/16/2009
Notes     	: JavaScript file for handling tool tips.
========================================================================================================= CHANGE LOG
Date		Name			Desc
---			---				---
========================================================================================================= BEGIN JAVASCRIPT
*/
/* ====================================================================================================== TOOLTIP */

var tip_offsetX = -200;
var tip_offsetY = 15;
var ie = document.all;
var ns6 = document.getElementById && !document.all;
var enabletip = false;

function ietruebody() {
  return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function showTip(tipObj,tipText) {
	if (ns6||ie) {
		tipObj.innerHTML = tipText;
		return false;
	}
}

function positiontip(e) {
	if (enabletip) {
		var tipObj = document.getElementById("tooltip");
		var curX = (ns6) ? e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY = (ns6) ? e.pageY : event.clientY+ietruebody().scrollTop;
		
		// Find out how close the mouse is to the corner of the window
		var rightedge = ie &&!window.opera? ietruebody().clientWidth-event.clientX-tip_offsetX : window.innerWidth-e.clientX-tip_offsetX-20;
		var bottomedge = ie &&!window.opera? ietruebody().clientHeight-event.clientY-tip_offsetY : window.innerHeight-e.clientY-tip_offsetY-20;
		var leftedge = (tip_offsetX<0)? tip_offsetX*(-1) : -1000;
		
		// If the horizontal distance isn't enough for the width of the menu
		if (rightedge < tipObj.offsetWidth) {
			tipObj.style.left = ie ? ietruebody().scrollLeft+event.clientX-tipObj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipObj.offsetWidth+"px";
		} else if (curX < leftedge) {
			tipObj.style.left = "5px";
		} else {
			tipObj.style.left = curX + tip_offsetX + "px"; // horizontal location is that of the mouse location
		}
		
		if (bottomedge < tipObj.offsetHeight) {
			tipObj.style.top=ie? ietruebody().scrollTop+event.clientY-tipObj.offsetHeight-tip_offsetY+"px" : window.pageYOffset+e.clientY-tipObj.offsetHeight-tip_offsetY+"px";
		} else {
			tipObj.style.top= curY + tip_offsetY + "px";
		}
		tipObj.style.visibility="visible";
	}
}
document.onmousemove = positiontip;