window.i = 0
$.fn.Tooltip = 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 */
	getTip = function() {
       var tTip =
            "<div class='help'>" +
                "<div class='help-top png'><!-- --></div>" +
                "<div class='help-text png'></div>" +
                "<div class='help-bottom png'><!-- --></div>" +
            "</div>";
       
		return tTip;
	}
	$("body").prepend(getTip());
	$('.help').hide();

	/* Give each item with the class associated with 
	   the plugin the ability to call the tooltip    */
	$(this).each(function(){
		
		var $this = $(this);

        var tip = $('.help');
		var tipInner = $('.help-text');

        //var tTitle = '«'+trim($this.text())+ '» - ' + $this.attr('title');
		var tTitle = $this.attr('title');
		this.title = "";
		
		var timer = 0
		
		/* Mouse over and out functions */
		$this.hover(
			function() {
				// get checkbox position
				var offset = $(this).offset();
				var tLeft = Math.round(offset.left);
				var tTop = Math.round(offset.top);
				// tooltip text
				tipInner.html(tTitle);
				// set tooltip position
				setTip(tTop, tLeft);
				// show
				timer = setTimeout('showTip()', 500);
			}, 
			function() {
				clearTimeout(timer)
				tip.hide();
			}
		);
		
		/* This function creates the
		   fade-in animation */
		showTip = function() {
			tip.show();
		}
		
		/* Position the tooltip relative to the class 
		   associated with the tooltip */
		setTip = function(top, left) {
			var topOffset = tip.height();
			var xTip = (left-180)+"px";
			var yTip = (top - topOffset)+"px";
			tip.css({'top' : yTip, 'left' : xTip});
		}

	});
};
