// ===========================================================================
//  tooltips.js
// ===========================================================================


/*

	To display tooltips, the page must contain this div somewhere on it:

		<div id="tooltipdiv" class="tooltip"></div>

*/


// ===========================================================================
//  showTooltip
// ===========================================================================
function showTooltip(
	inEvent,
	inElement,
	inPhrase,
	inWidth)
{
		// default to a width of 250 pixels
	inWidth = inWidth || 250;
		// give it a onmouseout handler to hide the tooltip when the mouse
		// moves off the element
	inElement.onmouseout = hideTooltip;

	var tooltip = null;

	if (document.layers && !document.getElementById) {
			// we don't offer tooltips in NN4.7 or before
		return;
/*
		tooltip = document.layers.tooltipdiv;

		tooltip.document.open();
		tooltip.document.write('<layer style="font-family: verdana, arial, helvetica, sans-serif; font-size: 11px; line-height: 14px; color: black; border: 1px solid #336699; background-color: #EEFAFF; padding: 5; layer-background-color: #EEFAFF; visibility: show;">');
		tooltip.document.write(inText + '</layer>');
//		tooltip.document.write('<html><head><link rel="stylesheet" href="styles.css" type="text/css"></head><body><div class="balloon" style="visibility: show;">' + inText + '</div></body></html>');
		tooltip.document.close();
		tooltip.document.visibility = "show";

		tooltip.left = inEvent.pageX + 10;
		tooltip.top = inEvent.pageY + 10;
		tooltip.width = inWidth; 

		tooltip.visibility = "show";
*/
	} else {
			// get the glossary phrase from inside the <a> element
		var phrase = ""; 

		if (document.all) {
				// this is IE.  anchors have an innerText attribute
			phrase = inElement.innerText;

			tooltip = document.all.tooltipdiv;

			if (!tooltip) {
				return;
			}

			tooltip.style.left = document.body.scrollLeft + inEvent.clientX + 20;
			tooltip.style.top = document.body.scrollTop + inEvent.clientY + 20;

			tooltip.style.width = inWidth;

				// if a phrase was passed in, use that to look up the tooltip text
				// in the glossary.  otherwise, use the text from inside the <a>.
			var tooltipPhrase = inPhrase || phrase || "";

				// phrases should be stored as all lower-case
			tooltipPhrase = tooltipPhrase.toLowerCase()

			if (typeof gGlossary[tooltipPhrase] == "undefined") {
					// we can't find a definition
				return;
			}

			tooltip.innerHTML = gGlossary[tooltipPhrase];

			tooltip.style.display = "block";
			tooltip.style.visibility = "visible";

				// make sure the tooltip stays on screen
			if (tooltip.style.pixelLeft + tooltip.offsetWidth > document.body.scrollLeft + document.body.offsetWidth - 50) {
//				tooltip.style.pixelLeft = document.body.scrollLeft + inEvent.clientX - tooltip.offsetWidth - 50;
				tooltip.style.pixelLeft = (document.body.scrollLeft + document.body.offsetWidth) - tooltip.offsetWidth - 50;
			}

			if (tooltip.style.pixelTop + tooltip.offsetHeight > document.body.scrollTop + document.body.offsetHeight - 30) {
				tooltip.style.pixelTop = document.body.scrollTop + inEvent.clientY - tooltip.offsetHeight - 30;
			}
		} else if (document.getElementById) {
				// this is NN6+.  anchors have a text attribute
			phrase = inElement.text;

			tooltip = document.getElementById("tooltipdiv");

			if (!tooltip) {
				return;
			}

			tooltip.style.left = window.pageXOffset + inEvent.clientX + 20;
			tooltip.style.top = window.pageYOffset + inEvent.clientY + 10; 

			tooltip.style.width = inWidth;

			tooltip.style.display = "block";
			tooltip.style.visibility = "visible";

				// if a phrase was passed in, use that to look up the tooltip text
				// in the glossary.  otherwise, use the text from inside the <a>.
			var tooltipPhrase = inPhrase || phrase || "";

				// phrases should be stored as all lower-case
			tooltipPhrase = tooltipPhrase.toLowerCase()

			if (typeof gGlossary[tooltipPhrase] == "undefined") {
					// we can't find a definition
				return;
			}

			tooltip.innerHTML = gGlossary[tooltipPhrase];
		}
	}
}


// ===========================================================================
// 	hideTooltip
// ===========================================================================
function hideTooltip()
{
	if (document.layers) {
		return;
/*
		tooltip = document.layers.tooltipdiv;
		tooltip.visibility = "hide";
*/
	} else {
		if (document.all) {
			tooltip = document.all.tooltipdiv;
		} else if (document.getElementById) {
			tooltip = document.getElementById("tooltipdiv");
		} 

		tooltip.style.visibility = "hidden";
	}
}


// ===========================================================================
// 	eventGetSource
// ===========================================================================
function eventGetSource(
	inEvent)
{
	if (typeof inEvent.srcElement != "undefined") {
		return inEvent.srcElement;
	} else if (typeof inEvent.target != "undefined") {
		return inEvent.target;
	} else {
		return null;
	}
}

/*
Text Link/Image Map Tooltip Script- 
© Dynamic Drive (www.dynamicdrive.com)
For full source code, and 100's more DHTML scripts
Visit http://www.dynamicdrive.com
*/
/*
if (!document.layers && !document.all && !document.getElementById) {
	event = "test"

}
function showtip(current,e,text){
	if (document.all || document.getElementById) {
		thetitle = text.split('<br>');

		if (thetitle.length > 1) {
			thetitles  =  '';

			for (i = 0; i < thetitle.length; i++) {
				thetitles += thetitle[i];
			}

			current.title = thetitles;
		} else {
			current.title = text;
		}
	} else if (document.layers) {
		document.tooltip.document.write('<layer bgColor = "white" style = "border:1px solid black;font-size:12px;">' + text + '</layer>')
		document.tooltip.document.close()
		document.tooltip.left = e.pageX + 5
		document.tooltip.top = e.pageY + 5
		document.tooltip.visibility = "show"
	}
}

function hidetip(){
if (document.layers)
document.tooltip.visibility = "hidden"
}
*/
//<div id = "tooltip" style = "position:absolute;visibility:hidden"></div>