// browser identifiers
var msie = false, nn4 = false, w3c = false;
var incompatible = false;

function getBrowser()
{
	// identify the viewer's browser
	if (document.all && !window.opera)
		msie = true;
	else if (document.layers)
		nn4 = true;
	else if (document.getElementById)
		w3c = true;
	else
		incompatible = true;
}

getBrowser();       // get the viewer's browser
var currTip = null; // current visible tip layer

var ua = navigator.userAgent.toLowerCase();
var version = msie ? parseFloat(ua.substr(ua.indexOf("msie") + 5, 3)) : 0;

// transition properties
var transition = "";
if (msie && version >= 5.5)
	transition = "progid:DXImageTransform.Microsoft.Fade(Duration=1)";
else if (msie && version >= 5)
	transition = "blendTrans(duration=1)";

// set up event handling
if (msie)
	document.attachEvent("onmousemove", moveToolTip);
else if (nn4)
{
	document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = moveToolTip;
}
else if (w3c)
	document.addEventListener("mousemove", moveToolTip, true);

function getScrollPosition()
{
	// get the current scroll position on the page
	var xScroll = 0, yScroll = 0;
	if (window.pageXOffset != null)
	{
		// most browsers
		xScroll = window.pageXOffset;
		yScroll = window.pageYOffset;
	}
	else if (document.documentElement != null && document.documentElement.scrollLeft != null)
	{
		// Internet Explorer Strict Mode
		xScroll = document.documentElement.scrollLeft;
		yScroll = document.documentElement.scrollTop;
	}
	else
	{
		// Internet Explorer Quirks Mode
		xScroll = document.body.scrollLeft;
		yScroll = document.body.scrollTop;
	}
	return [xScroll, yScroll];
}

function showToolTip(what, evt)
{
	var pageScroll = getScrollPosition();
	
	// initialize the active tooltip
	if (msie || w3c)
	{
		if (msie)
		{
			what = document.all[what];
			evt = event;
		}
		else
			what = document.getElementById(what);

		what.style.left = (evt.clientX + 10 + pageScroll[0]) + "px";
		what.style.top = (evt.clientY + pageScroll[1]) + "px";
		
		if (msie && version >= 5 && transition != "")
		{
			what.style.filter = transition;
			what.filters[0].apply();
		}
		
		what.style.visibility = "visible";
		if (msie && version >= 5 && transition != "") what.filters[0].play();
		currTip = what;
	}
	else if (nn4)
	{
		what = document.layers[what];
		what.left = evt.pageX + 10 + pageScroll[0];
		what.top = evt.pageY + pageScroll[1];
		what.visibility = "visible";
		currTip = what;
	}
	else
	{
		// don't do anything in a non-compliant browser
		alert("Your browser can't run this script.");
		return;
	}
}

function moveToolTip(evt)
{
	var pageScroll = getScrollPosition();
	
	if (currTip)
	{
		// update the tooltip's position
		if (msie || w3c)
		{
			if (msie) evt = event;
			currTip.style.left = (evt.clientX + 10 + pageScroll[0]) + "px";
			currTip.style.top = (evt.clientY + pageScroll[1]) + "px";
		}
		else if (nn4)
		{
			currTip.left = evt.pageX + 10 + pageScroll[0];
			currTip.top = evt.pageY + pageScroll[1];
		}
	}
}

function hideToolTip()
{
	// don't do anything in a non-compliant browser
	if (incompatible)
	{
		alert("Your browser can't run this script.");
		return;
	}

	// "deactivate" the active tooltip
	currTip.style.visibility = "hidden";
	currTip = null;
}