

/**
 * jQuery help tip
 * 
 * @author mh
 */
(function($) {
	var offsets = [];
	
	$.fn.tip = function(){
		return this.each(function(){
			var el = $(this);
			var tip = $('<div class="helpTipText">').html(el.html()).appendTo('body');
			el.empty().addClass('helpTip');
			var shown = false;
			
			el.hover(function(){
				if (!shown) {
					$.fn.tip.show(el, tip);
					shown = true;
				}
			}, function(){
				$.fn.tip.hide(el, tip);
				shown = false;
			})
			
			el.prev('input, textarea').focus(function(){
				if (!shown) {
					$.fn.tip.show(el, tip);
					shown = true;
				}				
			});
			
			el.prev('input, textarea').blur(function(){
				$.fn.tip.hide(el, tip);
				shown = false;
			});			
		});
	};
	
	$.fn.tip.show = function(el, tip){
		var o = el.offset();
		tip.css({left: o.left + 20, top: o.top - 7, opacity: 0, display: 'block'});
		tip.animate({opacity: 1, top: o.top - 2}, {duration: 'fast', queue: false});
	}
	
	$.fn.tip.hide = function(el, tip){
		var o = el.offset();
		tip.animate({opacity: 0, top: o.top + 3}, {duration: 'fast', queue: false});
	}
})(jQuery);

