
//the last link to have a tooltip
var lastTooltipItem = null;
var mouseX = 0;
var mouseY = 0;
var offsetX = 10;
var offsetY = 20;
var tipWidth = 200;
var isIE = document.all?true:false;
var minSpace = 200; // 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" );

	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;
			mouseY = event.y;
		}
		else
		{
			mouseX = e.pageX;
			mouseY = e.pageY;
		}

		// set the last tooltip items position
		if ( lastTooltipItem != null && lastTooltipItem.style.display != "none" )
		{
			placeTip( lastTooltipItem );
		}
	}
	catch ( ex )
	{
	}

}

// Corrects the item so that it doesnt get cut off
function placeTip( tooltipItem )
{
	if ( tooltipItem == null )
		return;
	
	var newPos = mouseY;
	
	if ( isIE )
	{
		newPos += document.body.scrollTop;
		
		if ( document.body.clientWidth - tipWidth > mouseX )
		{
			tooltipItem.style.right = null;
			tooltipItem.style.left = mouseX + offsetX;
		} // if
		else
		{
			tooltipItem.style.left = null;
			tooltipItem.style.right = (document.body.clientWidth - mouseX) + offsetX;
		} // else

		if ( document.body.clientHeight - minSpace > mouseY )
		{
			tooltipItem.style.bottom = null;
 			tooltipItem.style.top = newPos + offsetY;
		} // if
		else
		{
			tooltipItem.style.top = null;
			tooltipItem.style.bottom = offsetY;
		} // else
	} // if
	else
	{
		if ( self.innerWidth - (tipWidth + 10) > mouseX )
		{
			tooltipItem.style.right = null;
			tooltipItem.style.left = mouseX + offsetX;
		} // if
		else
		{
			tooltipItem.style.left = null;
			tooltipItem.style.right = (window.outerWidth - mouseX) + offsetX;
		} // else	
	
  		if ( self.innerHeight - minSpace > mouseY - self.pageYOffset )
		{
			tooltipItem.style.bottom = null;
 			tooltipItem.style.top = newPos + offsetY;
		} // if
		else
		{
			tooltipItem.style.top = null;
			//alert ( self.pageYOffset );
			tooltipItem.style.bottom = offsetY - self.pageYOffset;
		} // else
	} // else
}


// setup the events
if ( isIE )
	document.onmousemove = getMousePosition;
else
{
	window.captureEvents( Event.MouseMove );
	window.onmousemove = getMousePosition;
}