
// tooltips
var visibleTip = new Array();

function tipDetails(tipId, message)
{
	this.tipId = tipId;
	this.message = message;
}

function init()
{
	var nodes = document.getElementsByTagName("span");
	var len = nodes.length;
	var num = 0;
	var i = 0;
	while (num < len)
	{
		if (nodes[num].nodeType == 1 && nodes[num].title != "")
		{
			visibleTip[i] = new tipDetails(nodes[num].id, nodes[num].title);
			nodes[num].onmousemove = function (event) {toolTip(this,event)};
			nodes[num].onmouseout = function () {hideToolTip()};
			nodes[num].removeAttribute("title");
			i++;
		}
		num ++;
	}
}

function toolTip(obj,ev)
{
	var box = document.getElementById("tooltip");
	var x = ev.pageX-25;
	var y = ev.pageY+5;
	var text = "";
	for (var i = 0;i < visibleTip.length;i++)
	{
		if (visibleTip[i].tipId == obj.id)
		{
			text = visibleTip[i].message;
		}
	}
	box.innerHTML = '<div style="margin-top:30px;padding-top:20px;padding-left:40px;padding-right:40px;padding-bottom:20px;text-align:left;">'+text+'</div>';
	box.style.display = "block";
	boxWidth = parseFloat(box.offsetWidth);
	boxHeight = parseFloat(box.offsetHeight);
	box.style.background = "url(images/rhbubble.png)";
	if ( x+boxWidth > window.innerWidth )
	{
		box.style.background = "url(images/lhbubble.png)";
		x = x - 165;
	}
	
	if (y + boxHeight > window.innerHeight)
	{
		box.style.background = "url(images/lhinvbubble.png)";
		y = y - boxHeight- 15;		
	}
	
	box.style.left = x+"px";
	box.style.top = y+"px";
	return false;
}

function hideToolTip()
{
	document.getElementById("tooltip").style.display = "none";
}

function switchToolTip()
{
	hideToolTip();
	var tipSwitch = document.getElementById("switch");
	
	for (var i = 0;i < visibleTip.length;i++)
	{
		if (tipSwitch.checked)
		{
			document.getElementById(visibleTip[i].tipId).onmousemove = function (event) {toolTip(this,event)};
			document.getElementById(visibleTip[i].tipId).onmouseout = function () {hideToolTip()};
		}
		else
		{
			document.getElementById(visibleTip[i].tipId).onmousemove = null;
			document.getElementById(visibleTip[i].tipId).onmouseout = null;
		}
	}
}

