(function($) {
if(typeof jQuery.fn.niceTitles == 'function') { return; }
jQuery.fn.niceTitles = function(args) {
var elements = $(this);

var options = $.extend({
'includeCSS': true,
'includeURL': true,
'cleanUpMailtos': true,
'delay': 1,
},args);


elements.each(function() {
var elem = $(this);
var title = elem.attr('title');
if(title != '') {
elem.removeAttr('title');
elem.attr({'oldTitle': title});
if(elem.css('position') == 'static') { elem.css({'position': 'relative'}); }
var tooltip = $(jQuery('<div class="nicetitles-tooltip"></div>'));
tooltip.append($(jQuery('<span class="nicetitles-name">' + title + '</span>')));
if(options.includeURL && elem.is('[href]')) {
tooltip.append($(jQuery('<span class="nicetitles-url">' + (options.cleanUpMailtos ? elem.attr('href').replace(/^mailto:/i,'Email: ') : elem.attr('href')) + '</span>')));
}
tooltip.hide().appendTo(elem);

var isHovered = false;
elem.hover(function() {
isHovered = true;
setTimeout(function() {
if(isHovered) {
tooltip.fadeIn('fast');
}
},(options.delay * 1000));
}, function() {
isHovered = false;
tooltip.fadeOut('fast');
});
tooltip.hover(function() {
isHovered = false;
tooltip.fadeOut('fast');
}, function() {
// Do nothing
});

elem.click(function() {
tooltip.fadeOut('fast');
});
}
});

return elements;
}
})(jQuery);

