/**
 * Simple tooltips by David Winter
 * 
 * david@fatbeehive.com
 */

jQuery.fn.tooltips = function(tooltipdiv) {
	// Create the tooltip div.
	$('body').prepend('<div id="'+tooltipdiv+'" style="display: none;"></div>');
	
	/**
	 * Because of IE, we need to go through all the DFN tags, store the title, 
	 * and then only if IE, remove the title attribute.
	 */
	$(this).each(function(){
		$(this).data('tooltip', $(this).attr('title'));
		if ($.browser.msie)
		{
			$(this).removeAttr('title');
		}
	});

	$(this).mouseover(function(e){
		// Place the tooltip into the tooltip div.
		$('#dfn_tooltip').html($(this).data('tooltip'));
		// Remove the title attribute to prevent the default showing.
		$(this).removeAttr('title');
		// Position the tooltip div.
		$('#dfn_tooltip').css('top', e.pageY+15).css('left', e.pageX+15);
		// Fade in div
		$('#dfn_tooltip').fadeIn(100);
	});
	
	/**
	 * If the brower is anything but IE, we can safely put the title attribute back.
	 */
	$(this).mouseout(function(e){
		$('#dfn_tooltip').fadeOut(100);
		if (!$.browser.msie) // dumb IE
		{ 
			$(this).attr('title', $(this).data('tooltip')); 
		}
	});
	
	return $(this);
};