var tooltip_dx = 0;
var tooltip_dy = 0;
var tooltip_el = null;

function tooltip_show(text, width, dx, dy) {
	if (!document.body) return;
	dx = dx || 10;
	dy = dy || 0;
	if (tooltip_el == null) {
		tooltip_el = $('tooltip');
		if (tooltip_el == null) {
			tooltip_el = document.createElement('div');
			tooltip_el.id = 'tooltip';
			document.body.appendChild(tooltip_el);
		}
	}
	tooltip_el.innerHTML = text;
	tooltip_el.style.width = width + 'px';
	tooltip_dx = dx;
	tooltip_dy = dy;
	tooltip_el.style.visibility = 'visible';
	tooltip_move({});
}

function tooltip_hide() {
	if (tooltip_el) tooltip_el.style.visibility = 'hidden';
}

if (window.evt) evt.add(document, 'mousemove', tooltip_move)
else document.onmousemove = tooltip_move;

function tooltip_move(e) {
	if (!document.body) return;
	var mouse_x = tooltip_el && tooltip_move._x ? tooltip_move._x : 0;
	var mouse_y = tooltip_el && tooltip_move._y ? tooltip_move._y : 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		mouse_x = e.pageX;
		mouse_y = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		mouse_x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		mouse_y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}

	var x = mouse_x + tooltip_dx, y = mouse_y + tooltip_dy;
	if (tooltip_el && tooltip_el.style.visibility == 'visible') {
		tooltip_el.style.left = x + 'px';
		tooltip_el.style.top = y + 'px';
	}
	else {
		tooltip_move._x = x;
		tooltip_move._y = y;
	}
}
