(function($){
	$.fn.tooltip = function(options) {
		
		var
		  defaults = {
		  	background: '#e3e3e3',
			color: 'black',
			moreText: ' - more info',
			rounded: false
		  },
		  settings = $.extend({}, defaults, options);
		  
		  this.each(function() {
		  	var $this = $(this);
			var title = this.title;
			
			//disable ie trigger default tooltip
			$this.find('img').attr('alt','');

			if($this.is('a') && $this.attr('title') != '') {
				this.title = '';
				
				$this.hover(function(e) {
					// mouse over
							
					$('<div id="tooltip" />')
					  .appendTo('body')
					  .text(title)
					  
					  .append(settings.moreText)
					  .wrapInner('<div id="tooltipTop"><div id="tooltipBottom"><div id="tooltipBody"></div></div></div>')
					  .hide()
					  .css({
					  	backgroundColor: settings.background,
						color: settings.color,
						top: e.pageY + 30,
						left: e.pageX - 75
					  })
					  .fadeIn(50);

				  if(settings.rounded) {
				  	//$('#tooltip').addClass('rounded');
					$('#tooltip').css({	'-moz-border-radius': '7px', '-webkit-border-radius' : '7px'});
				  }
				}, function() {
					// mouse out
					$('#tooltip').remove();
				});	
			}
			
			$this.mousemove(function(e) {
				$('#tooltip').css({
					top: e.pageY + 30,
					left: e.pageX - 75
			     });
			});
			
		  });
		  // returns the jQuery object to allow for chainability.
		  return this;
	}
})(jQuery);

