jQuery.tooltip = function(options)
{   
	var settings = {
    	tooltipSuffix: '_tooltip',
    	classe: "tooltip"
    };
    
    if(options) {
    	jQuery.extend(settings, options);
    }

    // on récupère toutes les divs dont l'id se termine par '_tooltip'
    $("div[id]").each(function(i) {
    
    	var tooltipSuffixLength = settings['tooltipSuffix'].length;
    	var id = $(this).attr('id');
    	var idLength = id.length;
    	var start = idLength - tooltipSuffixLength;
    	var end = start + tooltipSuffixLength;
    	var idSuffix = id.substr(start, end);
    	
    	if(idSuffix == settings['tooltipSuffix'])
    	{
    		var idLength = id.length - tooltipSuffixLength;
    		var id = id.substr(0, idLength);
    		
    		$(this).addClass(settings['classe']);
    		
    		$('#' + id).bind("mouseenter", function(e) 
    			{
    				pos = $(this).findPos();
    				var width  = $(this).width();
    				var height = $(this).height();
					$('#' + id + settings['tooltipSuffix']).css(
						{
							'visibility': "visible", 
							'z-index': "1001", 
							'left': pos.x - 150 + width / 2,
							'top' : pos.y + height + 5
						});
    			})
    			
    		$('#' + id).bind("mouseout", function() 
    			{
    				$('#' + id + settings['tooltipSuffix']).css('visibility', 'hidden');
    			});
    	}
    });
}

jQuery.title = function(options)
{   
	var settings = {
    	selectionClass: "",
    	styleClass: 'tooltip_title'
    };
    
    if(options) {
    	jQuery.extend(settings, options);
    }

    // on r�cup�re toutes les balise poss�dant une classe 'class' et pourvues de l'attribut title
    $("[class=" + settings['selectionClass'] + "][title]").each(function(i) {
    
    	
    	
    	/*var offsetBottom  = $(this).offsetBottom;
    	var offsetLeft = $(this).offsetLeft;
    	var width = $(this).width;
    	
    	tooltipTop = offsetBottom + 100;*/
    	
    	$(this).mouseenter(function() 
    		{
    			var title = $(this).attr('title');
    	
    			$(this).attr('title', '');
    			$(this).after("<span id='c" + i + "' class='" + settings['styleClass'] + "'>" + title + "</span>");
    			$('#c' + i).hide();
    			$('#c' + i).css({position: "absolute", "z-index": "1000"}).show();
    		});
    	
    	$(this).mouseleave(function() 
    		{
    			$('#c' + i).hide();
    		});
    });
}

jQuery.fn.extend(
{
   findPos : function() 
   {
       obj = jQuery(this).get(0);
       var curleft = obj.offsetLeft || 0;
       var curtop = obj.offsetTop || 0;
       while (obj = obj.offsetParent) 
       {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
       }
       return {x:curleft,y:curtop};
   }
});