/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery

 Modified by Andrew Tay (www.andrewtay.com):
 - now positions tooltip from its bottom instead of top by subtracting tooltip height from css top: attribute
 - now checks to see if title attribute is empty, and only creates tooltip if not
 - tooltip is now a div with internal spans for graphic rounded corners on bubble
 - minor changes to offset variables (more conventional now)

 Feb 2009
 
 *
 */

 
this.tooltip = function(){	
	/* CONFIG */		
		var xOffset = -3;		
		var yOffset = -5;
	/* END CONFIG */		
	
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";					
		if (this.t !== ""){							// NEW! check if title is not empty 
			$("body").append("<div id='tooltip'><span class='tiptop'></span><p>"+ this.t +"</p><span class='tipbottom'></span></div>");
			$("#tooltip")
				.css("top",(e.pageY - $("#tooltip").height() + yOffset) + "px")	// NEW!! offset by tooltip height
				.css("left",(e.pageX + xOffset) + "px")
				.fadeIn("normal");
			}
		},
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
   	});	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - $("#tooltip").height() + yOffset) + "px")		// NEW!! offset by tooltip height
			.css("left",(e.pageX + xOffset) + "px");
		});			
	};


// Starting the script on page load

$(document).ready(function(){
	tooltip();
});
