(function($) {
	$.fn.formHelp = function(options)
	{
		var options = $.extend({
			helpers: []
			}, options);

		function showBubble()
		{
			$(this).data('bubble').fadeIn();
			$(this).siblings('div.error').hide();
		}

		function hideBubble()
		{
			$(this).data('bubble').fadeOut();
		}

		function setPosition($input, $bubble)
		{
			var pos = $input.position(),
				bubbleHeight = $bubble.outerHeight(),
				w = $input.outerWidth(),
				h = $input.outerHeight();

			$bubble.css({
				left: pos.left + w + 2,
				top: (pos.top + (h/2)) - (bubbleHeight/2)
			});

			$bubble.find('p').css({
				backgroundPosition: '-10px ' + (($bubble.height() / 2)) - 5 + 'px'
			});
		}

		return this.each(function()
		{
			if ($(this)[0].nodeName.toLowerCase() === 'form') {
				for (var i = 0, max = options.helpers.length; i < max; i++)
				{
					var helper = options.helpers[i],
						$bubble = $('<div class="bubble"></div>').html('<p class="description">' + helper.message + '</p>'),
						$input = $(this).find('#' + helper.id);

					$bubble.appendTo($input.parent());

					// bad/unknown id
					if (!$input.length)
						continue;

					setPosition($input, $bubble);

					$input.blur(hideBubble).focus(showBubble).data({bubble: $bubble});
				}
			}
		});
	}	// /formHelp 
})(jQuery);
