/* 
========================================================================================================= CREDITS
Copyright 	: Copyright (c) 2009 JPL & Learntobehealthy.org. 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/11/2009 
Notes     	: JavaScript file for handling tool tips.
========================================================================================================= CHANGE LOG
Date		Name			Desc
---			---				---
========================================================================================================= BEGIN JAVASCRIPT
*/
/* ====================================================================================================== TOOLTIP */

var tip_offsetX = -175;
var tip_offsetY = 20;
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;
}


/* ====================================================================================================== SHOW TOOLTIP */
function showTooltip(txt) {
	var tipObj = document.getElementById("tooltip");
	var browser = getBrowser();
	if (tipObj != null) {
        enabletip = true;

	    showTip(tipObj, txt);
		if (browser == "Internet Explorer") {
		    var tooltip_hide = document.getElementById("tooltip_hide");
		    if (tooltip_hide != null) tooltip_hide.style.visibility = "hidden";
		}
    }
}

/* ====================================================================================================== HIDE TOOLTIP */
function hideTooltip() {
	var tipObj = document.getElementById("tooltip");
	var browser = getBrowser();

	if (tipObj != null) {
	    enabletip = false;
	    tipObj.style.display = "none";
	    tipObj.style.left = "-9999px";

		if (browser == "Internet Explorer") {
		    var tooltip_hide = document.getElementById("tooltip_hide");
		    if (tooltip_hide != null) tooltip_hide.style.visibility = "visible";
		}
	}
}

function showTip(tipObj,tipText) {
	if (ns6||ie) {
		tipObj.innerHTML = tipText;
		return false;
	}
}

function positiontip(e) {
	if (enabletip) {
		var tipObj = document.getElementById("tooltip");
		tipObj.style.display = "block";
		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.display = "block";
	}
}
document.onmousemove = positiontip;