/*
 * jQuery.tooltip
 * Copyright (c) 2009 Michal SImonfy
 */

(function($){
	$.fn.tooltip = function(options){
 	var	defaults = {
      background: '#c8dc3c',color: '#009345',rounded: true,opaque: true
	 	 },
	settings = $.extend({},defaults,options); 
 	this.each(function(){
 		$('#tooltip').each(function(){$(this).remove()});
		var $this = $(this);
	 	var title=this.title;
 		//if ($this.is('a') && $this.attr('title') != '') {
 		if ($this.attr('title') != '') {
			this.title = '';
 			$this.hover(function(e){
				$('<div id="tooltip" />')
				.appendTo('body')
				.hide()
				.text(title)
				.css({
					backgroundColor: settings.background,
					color: settings.color,
					top: e.pageY + 15,
					left: e.pageX + 15
				})
				.fadeIn(100);
 				if (settings.rounded) {
					$('#tooltip').addClass('tooltip-rounded');
				}
				if (settings.opaque) {
					$('#tooltip').addClass('tooltip-opaque');
				}
			},
 			function() {
 				// mouseout
 				//$('#tooltip').remove();
 				$('#tooltip').each(function(){$(this).remove()});
 			});
	 	}
 		$this.mousemove(function(e){
 			$('#tooltip').css({
 				top: e.pageY + 15,
 				left: e.pageX + 15
 			})
		});
	});
	return this;
 	}
})(jQuery);
