/*
 * 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
 *
 */
 
(function($)
{
	//target needs to be an 'a' element
	
	$.fn.simpleTooltip = function(options)
	{
		var main_opts = $.extend({}, $.fn.simpleTooltip.defaults, options);
		
		return this.each(function(targetCounter)
		{
			var _$this = $(this);
			
			// build element specific options
			// if metadata plugin is present, extend main_opts, otherwise just use main_opts
      		var opts = $.meta ? $.extend({}, main_opts, $this.data()) : main_opts;
			
			//simplify the vars into regular globals
			var xOffset = opts._xOffset;
			var yOffset = opts._yOffset;
			
			_$this.hover(function(e)
			{											  
				this.t = this.title;
				this.title = "";
				$("body").append("<div id='tooltip'>"+ this.t +"</div>");
				$("#tooltip")
					.css("top",(e.pageY - xOffset) + "px")
					.css("left",(e.pageX + yOffset) + "px")
					.fadeIn("fast");		
			},
			function()
			{
				this.title = this.t;		
				$("#tooltip").remove();
			});	
			
			_$this.mousemove(function(e)
			{
				$("#tooltip")
					.css("top",(e.pageY - xOffset) + "px")
					.css("left",(e.pageX + yOffset) + "px");
			});
		});
	};
	
	//
	//plugin defaults
	//
	$.fn.simpleTooltip.defaults =
	{
		_xOffset: 10, // these 2 variable determine popup's distance from the cursor
		_yOffset: 20  // you might want to adjust to get the right result		
	};

})(jQuery);