jQuery.fn.prefill = (function($)
{
	var defaults = {
		"text" : "",
		"prefilledClass" : "prefilled"
	};

	function initialize(options)
	{
		var $this = $(this);
		
		$this
			.focus(on_focus)
			.blur(on_blur);

		$this.parents("form").submit(function()
		{
			if ($this.is("." + options["prefilledClass"]))
			{
				$this.val('');
			}
		});

		if ($this.val() == '')
		{
			$this.blur();
		}
			
		function on_focus()
		{
			var $this = $(this);

			if ($this.is("." + options["prefilledClass"]))
			{
				$this.val("");
			}

			$this.removeClass(options["prefilledClass"]);
		}
		
		function on_blur()
		{

			var $this = $(this);
			
			if ($this.val() == "")
			{
				$this
					.addClass(options["prefilledClass"])
					.val(options["text"]);
			}
		}
	}

	return function(options)
	{
		return this.each(function()
		{
			initialize.call(this, $.extend({}, defaults, options));
		});
	}
})(jQuery);