﻿//the last link to have a tooltip
var lastTooltipItem = null;
var mouseX = 0;
var mouseY = 0;
var offsetX = -28; //10 -28
var offsetY = -74; //20 -174
var tipWidth = -200;
var isIE = document.all?true:false;
var minSpace = -200; // 1 - Minimum space required at the bottom before it is placed above the mouse


// Shows the tooltip for the specified link
function showTooltip( linkItem )
{
	var tooltipItem = document.getElementById( linkItem.id + "_tooltip" );
	

	//Detect IE5.5+
	version=0
	if (navigator.appVersion.indexOf("MSIE")!=-1){
	temp=navigator.appVersion.split("MSIE")
	version=parseFloat(temp[1])
	}
	
	if (version!=5.5) //NON IE browser will return 0
	//alert("You're using IE5.5+")
	{
		if ( tooltipItem == null )
		return;
			
			tooltipItem.style.display = "block";
			
			placeTip( tooltipItem );
			// set the lastTooltipItem
			lastTooltipItem = tooltipItem;
	}
	else
	{
	if ( tooltipItem == null )
		return;
			
			tooltipItem.style.display = "none";
			
			placeTip( tooltipItem );
			// set the lastTooltipItem
			lastTooltipItem = tooltipItem;
}

	//if ( tooltipItem == null )
	//	return;
			
	//		tooltipItem.style.display = "block";
			
	//		placeTip( tooltipItem );
			// set the lastTooltipItem
	//		lastTooltipItem = tooltipItem;
}
// Hides the tooltip for the specified link
function hideTooltip( linkItem )
{
	var tooltipItem = document.getElementById( linkItem.id + "_tooltip" );

	if ( tooltipItem == null )
		return;

			tooltipItem.style.display = "none";
}

// gets the mouse position on mouse move
function getMousePosition(e)
{
	try
	{
		if (isIE)
		{	
			
			mouseX = event.x;
			//x
			//screenX
			//clientX
			//offsetX
			mouseY = event.y;
		}
		else
		{
			mouseX = e.pageX;
			mouseY = e.pageY;
		}
//alert(mouseX + "   " + mouseY);
		// set the last tooltip items position
		if ( lastTooltipItem != null && lastTooltipItem.style.display != "none" )
		{
			placeTip( lastTooltipItem );
			//lastTooltipItem = 0;
		}
	}
	catch ( ex )
	{	}

}

// Corrects the item so that it doesnt get cut off
function placeTip( tooltipItem )
{
	if ( tooltipItem == null )
		return;
	
	var newPos = mouseY;
	var newPos2 = mouseX;
	
	if ( isIE )
	{
		newPos += document.documentElement.scrollTop;
		newPos2 += document.documentElement.scrollLeft;
		
		if ( document.documentElement.clientWidth - tipWidth > mouseX )
		{
//			alert(mouseX + offsetX);
			tooltipItem.style.right = null;
			//tooltipItem.style.left = mouseX + offsetX;
 			tooltipItem.style.left = newPos2 + offsetX;
			
			//alert(mouseX + offsetX);
		} // if
		else
		{
			tooltipItem.style.left = null;
			//tooltipItem.style.right = (document.documentElement.clientWidth - mouseX) + offsetX;
			tooltipItem.style.right = offsetX;
			
			//alert((document.body.clientWidth - mouseX) + offsetX);
		} // else

		if ( document.documentElement.clientHeight - minSpace > mouseY )
		{
//			alert(newPos + "   " + offsetY);
			tooltipItem.style.bottom = null;
 			tooltipItem.style.top = newPos + offsetY;
			//alert(newPos + offsetY);
		} // if
		else
		{
			tooltipItem.style.top = null;
			tooltipItem.style.bottom = offsetY;
			//alert(offsetY);
		} // else
	} // if
	else
	{
		if ( self.innerWidth - (tipWidth + 10) > mouseX )
		{
//			alert(mouseX + offsetX);
			tooltipItem.style.right = null;
			tooltipItem.style.left = mouseX + offsetX + "px";
		} // if
		else
		{
			tooltipItem.style.left = null;
			tooltipItem.style.right = (window.outerWidth - mouseX) + offsetX + "px";
		} // else	
	
  		if ( self.innerHeight - minSpace > mouseY - self.pageYOffset )
		{
//			alert(newPos + "   " + offsetY);
			tooltipItem.style.bottom = null;
 			tooltipItem.style.top = newPos + offsetY + "px";
		} // if
		else
		{
			tooltipItem.style.top = null;
			//alert ( self.pageYOffset );
			tooltipItem.style.bottom = offsetY - self.pageYOffset + "px";
		} // else
	} // else
}

if ( isIE )
	document.onmousemove = getMousePosition;
else
{
	window.captureEvents( Event.MouseMove );
	window.onmousemove = getMousePosition;
}



