/*-------------------------------------------------------------------------------
	A Better jQuery Tooltip
	Version 1.0
	By Jon Cazier
	jon@3nhanced.com
	01.22.08
-------------------------------------------------------------------------------*/

$.fn.betterTooltip = function(options){
	
	/* Setup the options for the tooltip that can be
	   accessed from outside the plugin              */
	var defaults = {
		speed: 200,
		delay: 300
	};

	var options = $.extend(defaults, options);

	/* Give each item with the class associated with
	   the plugin the ability to call the tooltip    */

	$(this).each(function(){

		var $this = $(this);
		var tip = $('.tooltip');

        var tipbox = $(this).attr("rel");
        var tTitle = $("#"+tipbox).html();

		/* Mouse over and out functions*/
		$this.hover(
			function() {
				tip.html(tTitle);
				setTip($(this));
				showTip();
			},
			function() {
				tip.hide();
			}
		);


		/* Position the tooltip relative to the class
		   associated with the tooltip                */
		setTip = function($this){

		var offset = $this.offset();
		var left = offset.left;
		var top = offset.top;

			var topOffset = tip.height();
			var xTip = (left-105+$this.width()/2)+"px";
			var yTip = (top-topOffset-20)+"px";
			tip.css({'top' : yTip, 'left' : xTip});
		}

		/* This function stops the timer and creates the
		   fade-in animation                          */
		showTip = function(){
			tip.animate({"opacity": "toggle"}, defaults.speed);
		}
	});
};
