/*-------------------------------------------------------------------------------
	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);
	
	/* Create a function that builds the tooltip 
	   markup. Then, prepend the tooltip to the body */
	
	var tTip = 
			"<div class='tip'>" +
				"<div class='tipMid'>"	+
				"</div>" +
				"<div class='tipBtm'></div>" +
			"</div>";
	
	if( $('.tip').length == 0){
	$("body").prepend(tTip);
	}
	
	var tip = $('.tip');
	var tipInner = $('.tip .tipMid');
	/* Give each item with the class associated with 
	   the plugin the ability to call the tooltip    */
	$(this).each(function(){
		
		var $this = $(this);
		this.title = "";
		
		
		var tWidth = $this.width();
		var tHeight = $this.height();
		
		/* Mouse over and out functions*/
		$this.hover(
			function() {  
			
				tTitle = $(this).find('.bb_rule span').html();
				tTitle = $.trim(tTitle);
				
				
				if (tTitle.match(/\d.*puntos/i) != null){
					var points= "<span class='pink_bold'>"+ tTitle.match(/(\d.*puntos)/i)[1] +"</span>";
					tTitle = tTitle.replace(/\d.*puntos/i,points)
				}
				
				
				if (tTitle != ""){
				
				tipInner.html(tTitle);
				var offset = $(this).offset();
				var tLeft = offset.left;
				var tTop = offset.top;
				
				setTip(tTop, tLeft);
				tip.show();
				
				}
			}, 
			function() {s
				tip.hide();
			}
		);		   
		/* Position the tooltip relative to the class 
		   associated with the tooltip                */
		setTip = function(top, left){
			
			var topOffset = parseInt(tip.css('height'));
			var xTip = (left-110)+"px";
			var yTip = (top-topOffset-25)+"px";
			tip.css({'top' : yTip, 'left' : xTip});
						
		}
	});
};
