(function($) {
	$.fn.hovertext = function(options) {
	var opts = $.extend({}, $.fn.hovertext.defaults, options);
	
		return this.each(function() {
			$this = $(this);
			
			var hideDelayTimer = null;

			var beingShown = false;
			var shown = false;
			var trigger = $('a', this);					
			var info = $('p', this);
			
			trigger.mouseover(function () {
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				if (beingShown || shown) {
					// don't trigger the animation again
					return;
				} else {

					// reset position of info box
					beingShown = true;
					
					info.fadeIn(opts.time, function() {
						beingshown = false;
						shown = true;
					});

				}

				return false;
			}).mouseout(function () {
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				hideDelayTimer = setTimeout(function () {
					hideDelayTimer = null;
				
				info.fadeOut(opts.time, function() {
					shown = false;
					beingShown = false;
					info.css('display', 'none');
				});												
				}, opts.hideDelay);

				return false;
			});
		});
	};

	$.fn.hovertext.defaults = {
		time: 250,
		background: 500
	};
})(jQuery);