/*	tooltipLink jQuery Plug-in v1.2
	Copyright (c) 2009 Andrei Pfeiffer [www.upsidedown.ro]
	Based on the script written by Alen Grakalic [http://cssglobe.com] [http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery]
	
	ATTRIBUTES:
	- xOffset: 10 - sets the Left offset of the tooltip (it adds to the current position of the mouse). Increasing the value will move it to the right.
	- yOffset: 10 - sets the Top offset of the tooltip (it substracts from the current position of the mouse). Increasing the value will move it up.
	
	HISTORY:
	- v1.0 (january 2010)
		- stable version
		- only made a plug-in from the script provided by Alen Grakalic, that can be called for specific elements, with specific parameters
	
	USAGE:
	- this was created to display a tooltip when hovering links with the text taken from the title="" attribute
	
	- default:
		$(document).ready(function(){
			$("a.tooltip").tooltipLink();
		});
	
	- or, customizabile:
		$(document).ready(function(){
			$("a.tooltip").tooltipLink({
				xOffset: 20,
				xOffset: 15
			});
		});
	
*/

(function($){  
	$.fn.tooltipLink = function(options) {  
		
		var defaults = {  
			xOffset: 10,
			yOffset: 20
		};  
		var options = $.extend(defaults, options); 
		
		var allElements = $(this);
		
		return this.each(function() {
			tooltipElement = $(this);
			
			// HOVER event
			$(tooltipElement).hover(
				function(e) {
					this.t = this.title;
					this.title = "";									  
					$("body").append("<p id='tooltip'>"+ this.t +"</p>");
					$("#tooltip")
						.css("left",(e.pageX + parseInt(options.xOffset)) + "px")
						.css("top",(e.pageY - parseInt(options.yOffset)) + "px")
						.show();		
				},
				function(e) {
					this.title = this.t;		
					$("#tooltip").remove();
				}
			);
			
			// MOUSEMOVE event
			$(tooltipElement).mousemove(
				function(e) {
					$("#tooltip")
						.css("left",(e.pageX + parseInt(options.xOffset)) + "px")
						.css("top",(e.pageY - parseInt(options.yOffset)) + "px");
				}
			);
			
		});
		
	};  
})(jQuery);
