(function($) {

	$.fn.prompt = function(textContainer, labelContainer) {
		return $(this).each(function() {
		
			var root = $(this);
			var input = root.find(textContainer);
			var label = root.find(labelContainer);
			var prompt =
                $("<span />")
                 .addClass("prompt")
                 .insertAfter(label);
			label.show().appendTo(prompt);
			
			var pos = input.position();
			prompt.css('left', pos.left).css('top', pos.top);
			input.bind('click focus', function() {
				prompt.hide();
				if ($(this).val() == label.text()) $(this).val('');

			}).bind('blur', function() {
				if ($(this).val() == label.text() || $(this).val() == '') {
					prompt.show();
					$(this).val('');
				}
			});
			prompt.click(function() {
				$(this).hide();
				input.focus();
			});

			$(function() {
				if (input.val() != '') prompt.hide();
			});

		});
	};
	
})(jQuery);
