var mouse_x = -1000;
var mouse_y = -1000;
var tooltip_div, tooltip_iframe;

function is_ie()
{
	var agt = navigator.userAgent.toLowerCase();
	return agt.indexOf("msie") != -1 && agt.indexOf("opera") == -1;
}

function onmousemove(e)
{
	var e = (e) ? e : event;
	
	if (e.pageX && e.pageY)
	{
		nx = e.pageX;
		ny = e.pageY;
	}
	else
	{
		nx = e.clientX+document.body.scrollLeft;
		ny = e.clientY+document.body.scrollTop;
	}
	if (mouse_x != nx || mouse_y != ny)
	{
		mouse_x = nx;
		mouse_y = ny;
		if (tooltip_div && tooltip_div.style.visibility == "visible")
			tooltip_place();
	}
}

document.onmousemove = onmousemove;

function tooltip_place()
{
	var div_style = tooltip_div.style;
	var iframe_style = tooltip_iframe.style;
	iframe_style.left = div_style.left = mouse_x+10;
	y = mouse_y+10;
	if (y+parseInt(tooltip_iframe.height) > window.innerHeight+document.body.scrollTop)
		y = window.innerHeight+document.body.scrollTop-tooltip_iframe.height;
	iframe_style.top = div_style.top = y;
}

function tooltip_show(caption, text)
{
	var div_style, iframe_style;
	width = 250;
	
	if (tooltip_div)
	{
		div_style = tooltip_div.style;
		iframe_style = tooltip_iframe.style;
	}
	else
	{
		tooltip_div = document.createElement("div");
		tooltip_div.id = "div_tooltip";
		var body = document.getElementsByTagName("body")[0]
		body.appendChild(tooltip_div);
		div_style = tooltip_div.style;
		div_style.position = "absolute";
		div_style.zIndex = 1000;
		div_style.visibility = "hidden";
		div_style.left = div_style.top = -1000;

		tooltip_iframe = document.createElement("iframe");
		tooltip_iframe.id = "iframe_tooltip";
		tooltip_iframe.frameBorder = 0;
		tooltip_iframe.width = width;
		body.appendChild(tooltip_iframe);
		iframe_style = tooltip_iframe.style;
		iframe_style.position = "absolute";
		iframe_style.zIndex = 999;
		iframe_style.visibility = "hidden";
		iframe_style.left = iframe_style.top = -1000;
	}
	if (div_style.visibility == "hidden")
	{
		tooltip_div.innerHTML = "<table width="+width+" class=tooltip>"+
			(caption = "" ? "" : "<tr class=tooltip_caption><td>"+caption+"</td></tr>")+
			(text = "" ? "" : "<tr class=tooltip_text><td>"+text+"</td></tr>")+
			"</table>";
		var table = tooltip_div.childNodes[0];
		tooltip_iframe.height = table.clientHeight;
		tooltip_place();
		if (is_ie())
			iframe_style.visibility = "visible";
		div_style.visibility = "visible";
	}
}

function tooltip_hide()
{
	if (tooltip_div)
	{
		var div_style = tooltip_div.style;
		var iframe_style = tooltip_iframe.style;
		iframe_style.visibility = div_style.visibility = "hidden";
		div_style.left = div_style.top = -1000;
		iframe_style.left = iframe_style.top = -1000;
	}
}
