(function($) {
    $.fn.aToolTip = function(options) {
    
    	// setup default settings
    	var defaults = {
    		clickIt: false,
    		closeTipBtn: 'aToolTipCloseBtn',
    		fixed: false,
    		inSpeed: 500,
    		outSpeed: 100,
    		tipContent: '',
    		toolTipClass: 'aToolTip',
    		xOffset: 5,
    		yOffset: 5
    	},
    
    	// This makes it so the users custom options overrides the default ones
    	settings = $.extend({}, defaults, options);
    
		return this.each(function() {
			var obj = $(this);
			// Decide weather to use a title attr as the tooltip content
			if(obj.attr('title')){
				// set the tooltip content/text to be the obj title attribute
				var tipContent = obj.attr('title');	 
			} else {
				// if no title attribute set it to the tipContent option in settings
				var tipContent = settings.tipContent;
			}		    
		    
		    // check if click feature is enabled
		    if(tipContent && settings.clickIt){
				// Activate on click
				
				obj.click(function(el){
					 $('.' + settings.toolTipClass).fadeOut(5000, function(){$(this).remove();});
					obj.attr({title: ''});						  
					$('body').append("<div class='"+ settings.toolTipClass +"'><p class='aToolTipContent'>"+ tipContent +"</p></div>");
					$('.' + settings.toolTipClass).css({
						position: 'absolute',
						display: 'none',
						zIndex: '50000',
						top: (obj.offset().top - 15) + 'px',
						left: (obj.offset().left - 55) + 'px'
					})
					.fadeIn(settings.inSpeed);	
					// Click to close tooltip
					$(this).mouseout(function(){
			
			setTimeout(function() { $('.' + settings.toolTipClass).fadeOut(500, function(){$(this).remove();}); }, 5000);
			
						return false;
					});	
			 
							
			    });
		    }
		  
		}); // END: return this
		
		// returns the jQuery object to allow for chainability.  
        return this;
    };
})(jQuery);
