/* Tooltip (c) Doberman 2007 */

// anykey will hide tooltip
registerAnyKey("ht()");

$tooltip = false;
$lasttext = '';
function tt(text, element, static)
{
	if(!$tooltip || $lasttext != text)
	{
		$lasttext = text;
		$tooltip = true;
		$('#tooltipContent').html(text);
		$('#tooltip').show();
		if( element )
		{
			// position of clicked element
			var pos = rect(element);
			var left = Math.round(pos.left) - ($('#tooltip').width() / 2) ;
			var top = Math.round(pos.top) - $('#tooltip').height();
			$('#tooltip').css('position', 'absolute');
			$('#tooltip').css('left', Math.round(left) + 'px');
			$('#tooltip').css('top', Math.round(top) + 'px');
		}
		else
		{
			$winW = $(window).width();
			$winH = $(window).height();
			$leftcenter = $('#tooltip').width() / 2;
			$topcenter = $('#tooltip').height();
			$(document).bind('mousemove', updatett);
		}
	}
}

function updatett(event)
{
	var x = event.pageX - $leftcenter - 5;
	var y = event.pageY - $topcenter - 10;
	$('#tooltip').css('left', x + 'px').css('top', y + 'px');
}

function ht()
{
	$tooltip = false;
	$(document).unbind('mousemove', updatett);
	$('#tooltip').hide();
}
