$(document).ready(function(){
	$("body").append("<div id='ToolTipDiv'></div>");
	$("[tooltip]").each(function(){
		$(this).css({'cursor' : 'help'});
		$(this).hover(function(e){
			$(this).mousemove(function(e){
				var tipY = e.pageY + 16;
				var tipX = e.pageX + 16;
				$("#ToolTipDiv").css({'top': tipY, 'left': tipX});
			});
			var next = $(this).next();
			var ck = $(next).html();
			var doLoad = $(this).attr('load');
			var title = $(this).attr('title');
			if(ck == ''){
				ck = '<img src="images/loading.gif" alt="loading" width="16" height="16" />';
			}
			$("#ToolTipDiv")
				.html(ck)
				.stop(true,true)
				.fadeIn("fast");
			$(this).removeAttr('title');
			
			if(doLoad == undefined){
				$('#ToolTipDiv').html(title);
			}else{
				var load = $(this).attr('load');
				var what = $(this).attr('what');
				
				$.ajax({
					type: 'POST',
					url: 'php/ajax/update.php',
					data: 'ID='+load+'&what='+what,
					success: function(msg){
						$("#ToolTipDiv")
						.html(msg)
						.stop(true,true);
						$(next).html(msg);
						$(next).attr('load', 'false');
					},
					dataType: 'html'
				});
			}
		}, function(){
			$("#ToolTipDiv")
				.stop(true,true)
				.fadeOut("fast");
			$(this).attr('title', $("#ToolTipDiv").html());
		});
	});
});
