var $j = jQuery.noConflict();

$j(document).ready(function() {
 
    //Select all anchor tag with rel set to tooltip
    $j('a[rel=tooltip]').mouseover(function(e) {
         
        //Grab the title attribute's value and assign it to a variable
        var tip = $j(this).attr('title');   
         
        //Remove the title attribute's to avoid the native tooltip from the browser
        $j(this).attr('title','');
         
        //Append the tooltip template and its value
        $j(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');    
         
        //Set the X and Y axis of the tooltip
        $j('#tooltip').css('top', e.pageY + 20 );
        $j('#tooltip').css('left', e.pageX + 5 );
         
        //Show the tooltip with fadeIn effect
        $j('#tooltip').fadeIn('slow');
        $j('#tooltip').fadeTo('10',0.9);
         
    }).mousemove(function(e) {
     
        //Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
        $j('#tooltip').css('top', e.pageY + 20 );
        $j('#tooltip').css('left', e.pageX + 5 );
         
    }).mouseout(function() {
     
        //Put back the title attribute's value
        $j(this).attr('title',$j('.tipBody').html());
     
        //Remove the appended tooltip template
        $j(this).children('div#tooltip').remove();
         
    });
 
});
