/**
* jQuery Tool Tip Plug-In
* This plugin displays the provided element, and repositions it to follow the mouse, whenever a user mouses over
* the tool tip enabled element.
* 
* @params {String} toolTipEl The CSS locator to the element that needs a tool tip.
* @params {Object} config Optional. An object containing properties to configure the displaying of the tool tip element
* @cfg {Integer} xOffset The amount of pixels to offset the Tool Tip element from the mouse on the X-axis
* @cfg {Integer} yOffset The amount of pixels to offset the Tool Tip element from the mouse on the Y-axis
* 
* Usage:
*   $('#element').toolTip('#elementToShow');
*   $('.elements').toolTip('#toolTip', { xOffset: 50, yOffset: 60 });
*/
jQuery.fn.tooltip = function() {
	return function(toolTipEl, config) {
		config = config || {};

		if(!toolTipEl) {
			throw 'No Tool Tip element specified';
			return;
		}
		if(!jQuery(toolTipEl).length) {
			throw 'Tool Tip element (' + toolTipEl + ') not found!';
			return;
		}

		jQuery(toolTipEl).css('position', 'absolute');

		return this.each(function(index, el) {
			jQuery(el).hover(function(e) {
				jQuery(toolTipEl)
					.css('top',  (e.pageY - (config.xOffset || 10) + 'px'))
					.css('left', (e.pageX + (config.yOffset || 20) + 'px'))
					.fadeIn('fast');
			}, function(e) {
				jQuery(toolTipEl).hide();
			});
			jQuery(el).mousemove(function(e) {
				jQuery(toolTipEl)
					.css('top',  (e.pageY - (config.xOffset || 10) + 'px'))
					.css('left', (e.pageX + (config.yOffset || 20) + 'px'));
			});
		});
	}
}();
