/*
JnWMedia (c)2006 Tooltip.
Please contact us before use. 
info@jnwmendia.nl
*/

tooltip = null
active = false;

checkTooltip = function()
{	
	found = false;	
	var tooltipcolection = document.getElementsByTagName("SPAN");

	for(i=0; i<tooltipcolection.length; i++)
	{
		node = tooltipcolection[i];
		if(node.className.indexOf("tooltip") != -1 && node.title != "")
		{
			node.tooltip = node.title;
			node.title = "";
			
			node.onmouseover=function() 
			{
				showTooltip(this.tooltip);
			}
						
			node.onmouseout=function() 
			{
				hideTooltip();				
			}		
			
			found = true;	
		}				
	}
	
	if(found)
	{				
		tooltip = document.createElement("div");		
		tooltip.setAttribute("id", "tooltip") 		
		document.getElementsByTagName("BODY")[0].appendChild(tooltip);						
	}
}

showTooltip = function(text)
{		
	tooltip.style.display = "block";
	active = true;
	
	if(document.all) positiontip();
	tooltip.innerHTML = text;
	
	document.onmousemove=positiontip;
}

hideTooltip = function()
{
	tooltip.style.display = "none";	
	active = false;
	
	tooltip.style.top = 0;
	tooltip.style.left = 0;
	tooltip.innerHTML = "";
	
	document.onmousemove=null;
}

positiontip = function(e)
{
	
	//position the tooltip		
	var currentSL = document.documentElement.scrollLeft;
	var currentW = document.body.clientWidth;
	
	var currentST = document.documentElement.scrollTop;
	var currentH = document.body.clientHeight;
	
	var currentY = (document.all ? event.clientY : e.pageY ) + 10;
	var currentX = (document.all ? event.clientX : e.pageX ) + 10;

//	window.status = ' X: ' + event.clientX + 
//					' Y: ' + event.clientY + 
//					' ClientWidth:' + document.body.clientWidth + 
//					' ClientHeight:' + document.body.clientHeight + 
//					' Scrolltop:' + document.body.scrollTop + 
//					' Scrolleft:' + document.body.scrollLeft;
						
	tooltip.style.top = (((currentY + currentST + tooltip.offsetHeight) >= (currentH + currentST - 2)) ? (currentH - tooltip.offsetHeight - 3 + (document.all ? 0 : currentST)) : (currentY)) + (document.all ? currentST : 0) + "px";
	tooltip.style.left =(((currentX + (document.all ? currentSL : 0) + tooltip.offsetWidth)  >= (currentW + currentSL - 2)) ? (currentW - tooltip.offsetWidth  - 3 + (document.all ? 0 : currentSL)) : (currentX)) + (document.all ? currentSL : 0) + "px";	
}

var oldonload = window.onload;
if (typeof oldonload != 'function')
{
	window.onload = checkTooltip;
}
else
{
	window.onload = function()
	{
		oldonload();
		checkTooltip();
	}
}


