/* initialize every <a> tag on the page with class="tooltip" */
this.tooltip = function(){  
    /* CONFIG */
        xOffset = 00;
        yOffset = 20;
        // these 2 variable determine popup's distance from the cursor
        // you might want to adjust to get the right result
    /* END CONFIG */

	//$('a.tooltip').live('hover', function(e) {

    jQuery("a.tooltip").hover(function(e){
        this.t = this.title;
        this.title = "";
        jQuery("body").append("<p id='tooltip'>"+ this.t +"</p>");
        jQuery("#tooltip")
            .css("top",(e.pageY + yOffset) + "px")
            .css("left",(e.pageX + xOffset) + "px")
            .fadeIn("fast");
    },
    function(){
        this.title = this.t;
        jQuery("#tooltip").remove();
    }); 
    jQuery("a.tooltip").mousemove(function(e){
        jQuery("#tooltip").css("top",(e.pageY + yOffset) + "px").css("left",(e.pageX + xOffset) + "px");
    });
};


/* Put class="tooltip" and title="TooltipText" on a <input> and it will show right to the box when focused */

this.tooltip2 = function(){  

	$('input.tooltip, textarea.tooltip, select.tooltip').each(function() {

		$(this).focus(function(){

			if (this.title == "") {				
				this.title = this.t;
			}
			//alert(this.title);
			$("#tooltipa").remove();

			if (this.title != "" && this.title != "undefined"){
				var pos = $(this).offset();  
				var width = $(this).width();
				this.t = this.title;
				this.title = "";
	    		$("body").append("<div id='tooltipa'>"+ this.t +"</div>");
				$("#tooltipa")
					.css("position","absolute")
	        		.css("top",(pos.top) + "px")
	        		.css("left",(pos.left + width + 19) + "px")
	        		.fadeIn(200);				
			} 
		});

		$(this).blur(function(e){
			this.title = this.t;
			$('#tooltipa').fadeOut(200).remove();
	    });


//        $(this).change(function (e) {
//            this.title = this.t;
//            $('#tooltipa').fadeOut(200);
//        });

		$(this).hover(function(){
			if (this.title != "") {
				this.t = this.title;
				this.title = '';
				//alert(this.t);
			}
		});

	});

};

// starting the script on page load
jQuery(document).ready(function(){
    tooltip();
	tooltip2();
});
