(function($) {
	$.fn.tooltip = function (options) {
		
		var defaults = {
			background: '#3e3e3e',
			color: 'black',
			fade: 500,
			rounded: false
		},
		settings = $.extend({}, defaults, options);
		
		this.each(function() {
						   
			var $this = $(this);
			var title = this.title;

			if($this.is('img') && $this.attr('title') != '') {
				this.title = '';				
			};
			
			if($this.is('a') && $this.attr('title') != '') {
				this.title = '';
				$this.hover(function(e) {
					// mouse over
					$('<div id="tooltip" />')
					.appendTo('body')
					.animate({opacity: 0.70}, "show")
					.text(title)
					.hide()
					.css({
						background: settings.background,
						color: settings.color,
						top: e.pageY + 10,
						left: e.pageX + 20
					})
					.fadeIn(settings.fade);
					
					if(settings.rounded) {
						$("#tooltip").addClass('rounded');	
					}
				}, function () {
					// mouse out
					$("#tooltip").remove();
				});
			}
			
			$this.mousemove(function(e) {
				$("#tooltip").css({
					top: e.pageY + 10,
					left: e.pageX + 20				  
				});					   
			});
			
		});
	}
})(jQuery);


