var domcurPageX = 0;
var domcurPagey = 0;

var tipBox = "";

var domtipWidth = "";
var domtipWidthSub = "";
var domtipBorderSize = "";
// The next one is necessary to calculate size; same value as above only without
// "px"
var domtipBorderNumber = "";
var domtipBorderColor = "";
var domtipOpacity = "";

var domtipHeaderBgColor = "";
var domtipHeaderFontFamily = "";
var domtipHeaderFontSize = "";
var domtipHeaderFontColor = "";
var domtipHeaderAlign = "";
var domtipHeaderPadding = "";
var domtipHeaderOpacity = "";

var domtipBodyBgColor = "";
var domtipBodyFontFamily = "";
var domtipBodyFontSize = "";
var domtipBodyFontColor = "";
var domtipBodyAlign = "";
var domtipBodyPadding = "";
var domtipBodyOpacity = "";

window.document.onmousemove = trackMouse;

function trackMouse(e)
{
	var e = (e) ? e : ((event) ? event : null);

	// Functions do different things depending on whether or not a
	// doctype is present. Node type 10 is a doctype but IE reads
	// a doctype as Node type 8 - a comment.
	if (document.childNodes[0].nodeType == 10 || document.childNodes[0].nodeType == 8)
	{
		curPageX = e.clientX + document.documentElement.scrollLeft;
 		curPageY = e.clientY + document.documentElement.scrollTop;

 		scrollPageY = document.documentElement.scrollTop;

		viewPageX = e.clientX;
		viewPageY = e.clientY;

		viewScreenX = document.documentElement.clientWidth;
		viewScreenY = document.documentElement.clientHeight;

		totalScreenX = document.body.offsetWidth;
		totalScreenY = document.body.offsetHeight;
	} else {
		curPageX = e.clientX + document.body.scrollLeft;
 		curPageY = e.clientY + document.body.scrollTop;

 		scrollPageY = document.body.scrollTop;

		viewPageX = e.clientX;
		viewPageY = e.clientY;

		viewScreenX = document.body.clientWidth;
		viewScreenY = document.body.clientHeight;

		totalScreenX = document.documentElement.scrollWidth;
		totalScreenY = document.documentElement.scrollHeight;
	}

	if (tipBox != "" && tipBox.style.display == "block")
	{
		moveTip();
	}

	return true;
}

function domclearTip()
{
	while (tipBox.childNodes.length > 0)
	{
		tipBox.removeChild(tipBox.childNodes[0]);
	}

	tipBox.style.display = "none";
}

function domtoolText(headerText, tipText)
{
	if (tipBox == "")
	{
		tipBox = document.createElement("div");
		tipBox.id = "toolTipDiv";

		window.document.body.appendChild(tipBox);
	} else {
		domclearTip();
	}

	// make sure box settings are up to date
	tipBox.style.width = domtipWidth;
	tipBox.style.border = domtipBorderSize + " solid " + domtipBorderColor;
	tipBox.style.position = "absolute";
	tipBox.style.display = "none";

	// Build the tip header
	var tipHead = document.createElement("div");
	tipHead.style.backgroundColor = domtipHeaderBgColor;
	tipHead.style.fontFamily = domtipHeaderFontFamily;
	tipHead.style.fontSize = domtipHeaderFontSize;
	tipHead.style.color = domtipHeaderFontColor;
	tipHead.style.padding = domtipHeaderPadding;
	tipHead.style.textAlign = domtipHeaderAlign;
	tipHead.style.width = domtipWidthSub;
	tipHead.style.filter = "alpha(opacity=" + domtipHeaderOpacity + ")";
	tipHead.style.opacity = "." + domtipHeaderOpacity;
	tipHead.style.mozOpacity = "." + domtipHeaderOpacity;

	var tipHeadText = document.createTextNode(headerText);
	tipHead.appendChild(tipHeadText);

	tipBox.appendChild(tipHead);

	var tipBody = document.createElement("div");
	tipBody.style.backgroundColor = domtipBodyBgColor;
	tipBody.style.fontFamily = domtipBodyFontFamily;
	tipBody.style.fontSize = domtipBodyFontSize;
	tipBody.style.color = domtipBodyFontColor;
	tipBody.style.padding = domtipBodyPadding;
	tipBody.style.textAlign = domtipBodyAlign;
	tipBody.style.width = domtipWidthSub;
	tipBody.style.filter = "alpha(opacity=" + domtipBodyOpacity + ")";
	tipBody.style.opacity = "." + domtipBodyOpacity;
	tipBody.style.mozOpacity = "." + domtipBodyOpacity;

	tipBody.innerHTML = tipText;

	tipBox.appendChild(tipBody);

	tipBox.style.visibility = "hidden";
	tipBox.style.display = "block";

	tipHeight = tipBox.offsetHeight;

	moveTip();
	tipBox.style.visibility = "visible";
}

function moveTip()
{
	var tipXloc = curPageX + 10;
	var tipYloc = curPageY + 10;

	var tipHeight = tipBox.offsetHeight;
	var tipWidth = tipBox.offsetWidth;

	// If the tooltip extends off the side, pull it over
	if (viewPageX + 10 + tipWidth > viewScreenX)
	{
		tipXloc -= (tipWidth + 15);
	}

	// If the tooltip will extend off the bottom of the screen, pull it back up.
	if (viewPageY + 10 + tipHeight > viewScreenY)
	{
		var pageDiff = (viewPageY + 10 + tipHeight - viewScreenY);
		tipYloc -= pageDiff;
	}

	// If the tooltip extends off the bottom and the top, line up the top of
	// the tooltip with the top of the page
	if (tipHeight > viewScreenY)
	{
		tipYloc = scrollPageY + 5;
	}

	tipBox.style.left = tipXloc + "px";
	tipBox.style.top = tipYloc + "px";
}
