// jQuery tooltip plugin

( function( $ ) {
	
	$.fn.tooltip = function( options ) {
		var defaults = {
			color: 'black',
			background: '#e3e3e3',
			rounded: false
		};
		
		var settings = $.extend( {}, defaults, options );
		
		this.each( function() {
			var $this = $( this );
			var title = this.title;
			
			if( $this.is( 'a' ) && $this.attr( 'title' ) != '' ) {
				this.title = '';
				
				$this.hover(
					function( e ) {
						$( '<div id="tooltip" />' )
						.text( title )
						.css({
							backgroundColor: settings.background,
							color: settings.color,
							top: e.pageY + 10,
							left: e.pageX + 20
						})
						.appendTo( 'body' )
						.hide()
						.fadeIn( 400 );
						
						if( settings.rounded )
							$( '#tooltip' ).addClass( 'rounded' );
					},
					
					function( e ) {
						$( '#tooltip' ).remove();
					}
				
				); //end hover
				
				$this.mousemove( function( e ) {
					$( '#tooltip' ).css({
						top: e.pageY + 15,
						left: e.pageX + 12
					});
				});
				
			} // end if
			
		});
		
	} //end tooltip function
	
})(jQuery);