this.tooltip = function()
{	
	xOffset = -20;
	yOffset = 0;
	
	function updatePosition(e) {
		var x = (e.pageX + yOffset);
		if (x + $("#tooltip").width() > $('body').width())
			x = $('body').width() - $("#tooltip").width() - 10;

		var y = (e.pageY - xOffset);
		if (y + $("#tooltip").height() > $('body').height())
			y = $('body').height() - $("#tooltip").height() - 30;

		$("#tooltip").css( { 'top' : y + 'px', 'left' : x + 'px', 'display' : ''});
	}

	function hideTooltip(elt) {
		$("#tooltip").remove();
		var title = $(elt).attr("t");

		if(title != undefined)
			elt.title = title;
	}
	
	$("[tooltip]").hover(
	    function(e) //on hover
	    {
		    
		    $("body").append('<div id="tooltip" class="info" style="position: absolute; display: inline;">'+ $(this).attr("tooltip") +'</div>');
		    this.title = '';
		    
			updatePosition(e);
			$("#tooltip").css('display', '');
        },
	    function() { hideTooltip(this); } //on hover quit
    );
    
    $("[tooltip]").click( function() { hideTooltip(this); } );
	$("[tooltip]").mousemove(function(e){ updatePosition(e); } );
};

$(document).ready(function()
{
	tooltip();
});