/*
 * 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
 *
 */
 

/* this piece of code made the transition too slow and lag
this.tooltip = function(){		
		xOffset = 20;
		yOffset = 10;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result	
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px");
	});			
};
*/

//http://www.learningjquery.com/2009/12/simple-tooltip-for-huge-number-of-elements
this.tooltip = function(){	
	xOffset = 20;
	yOffset = 10;	

	$('<div id="tooltip"></div>').hide().appendTo('body');
	var tipTitle = '';
	$('a.tooltip').bind('mouseover', function(event) {
		var $link = $(event.target).closest('a');
		if ($link.length) {
			var link = $link[0];
			tipTitle = link.title;
			link.title = '';
			$('#tooltip')
 				.css({
					top: event.pageY - yOffset,
					left: event.pageX + xOffset
					})
				.fadeIn("fast")
 				.html('<div>' + tipTitle + '</div>')
          		.show();
     }
     }).bind('mouseout', function(event) {
        	var $link = $(event.target).closest('a');
        	if ($link.length) {
          		$link.attr('title', tipTitle);
          		$('#tooltip').hide();
        	}
     });
}


// starting the script on page load
$(document).ready(function(){
	tooltip();
});
