var ua = navigator.userAgent.toLowerCase();
var ieVersion = parseFloat(ua.substr(ua.indexOf("msie") + 5, 3));

var tt_currTip = null, tt_fadeTimer = null;
var tt_hasEvent = false;
var tt_fadeAmt = 10, tt_fadeDelay = 1;

function tt_show(evt, tipID)
{
	if (evt == null) evt = event;
	if (tt_currTip != null)
	{
		tt_currTip.style.visibility = "hidden";
		clearTimeout(tt_fadeTimer);
	}
	
	tt_currTip = tt_find(tipID);
	if (tt_currTip == null) return;
	tt_move(evt);
	tt_fade(tt_fadeAmt, tt_fadeDelay, true, false);
	
	if (!tt_hasEvent)
	{
		if (document.attachEvent != null)
			document.attachEvent("onmousemove", tt_move);
		else if (document.addEventListener != null)
			document.addEventListener("mousemove", tt_move, true);
		else
		{
			var currHandler = typeof(document.onmousemove) == "function" ? document.body.onmousemove : null;
			if (document.layers != null) document.captureEvents(Event.MOUSEMOVE);
			document.onmousemove = function(evt)
			{
				if (currHandler != null) currHandler(evt);
				tt_move(evt);
			};
		}
		tt_hasEvent = true;
	}
}

function tt_find(id)
{
	if (document.getElementById)
		return document.getElementById(id);
	else if (document.all)
		return document.all[id];
	else if (document.layers)
		return { style: document.layers[id] };
	else
		return null;
}

function tt_fade(amt, delay, toggle, hasRunOnce)
{
	if (toggle && !hasRunOnce) tt_currTip.style.visibility = "visible";
	if (tt_currTip.filters != null)
	{
		if (!hasRunOnce) tt_currTip.style.filter = (ieVersion >= 5.5 ? "progid:DXImageTransform.Microsoft.Alpha(Opacity=" : "alpha(opacity=") + (toggle ? 0 : 100) + ")";
		tt_currTip.filters[0].opacity += toggle ? amt : -amt;
		
		var fadeCompare = toggle ? (tt_currTip.filters[0].opacity < 100) : (tt_currTip.filters[0].opacity > 0);
		if (fadeCompare) tt_fadeTimer = setTimeout("tt_fade(" + amt + ", " + delay + ", " + toggle + ", true)", delay);
		
		if (!fadeCompare && !toggle)
		{
			tt_currTip.style.visibility = "hidden";
			tt_currTip = null;
		}
	}
	else if (tt_currTip.style.MozOpacity != null)
	{
		if (!hasRunOnce) tt_currTip.style.MozOpacity = toggle ? 0 : 1;
		tt_currTip.style.MozOpacity = opacity = (Math.round(parseFloat(tt_currTip.style.MozOpacity) * 100) + (toggle ? amt : -amt)) / 100;
		
		var fadeCompare = toggle ? (opacity < 100) : (opacity > 0);
		if (fadeCompare) tt_fadeTimer = setTimeout("tt_fade(" + amt + ", " + delay + ", " + toggle + ", true)", delay);
		
		if (!fadeCompare && !toggle)
		{
			tt_currTip.style.visibility = "hidden";
			tt_currTip = null;
		}
	}
	else if (!toggle)
	{
		tt_currTip.style.visibility = "hidden";
		tt_currTip = null;
	}
}

function tt_getScroll()
{
	// 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
  {
    // Internet Explorer
    var pageBody = document.compatMode == "CSS1Compat" ? document.documentElement : document.body;
    xScroll = pageBody.scrollLeft;
    yScroll = pageBody.scrollTop;
  }
	return [xScroll, yScroll];
}

function tt_move(evt)
{
	if (evt == null) evt = event;
	if (tt_currTip != null)
	{
		var scrollPosition = tt_getScroll();
		tt_currTip.style.left = (document.layers != null ? evt.pageX + scrollPosition[0] + 10 : (evt.clientX + scrollPosition[0] + 10) + "px");
		tt_currTip.style.top = (document.layers != null ? evt.pageY + scrollPosition[1] + 10 : (evt.clientY + scrollPosition[1] + 10) + "px");
	}
}

function tt_hide()
{
	if (tt_currTip != null)
	{
		clearTimeout(tt_fadeTimer);
		tt_fade(tt_fadeAmt, tt_fadeDelay, false, false);
	}
}

