/* 
* Watermark Input (v0.1)
* by Jonathan Chao
* June 25, 2009
* 
* Inspiration comes from Mike Enriquez's implementation located at 
*   http://theezpzway.com
*
* NOTE: This script requires jQuery to work. Developed with jQuery v1.3.2
* 
* Licensed under the Attribution-Noncommercial 3.0 Creative Commons License
* http://creativecommons.org/licenses/by-nc/3.0/
*/

(function($) {
	$.fn.watermark = function(o) {	
		return this.each(function() {
			var $text = $(this);
			
			var $watermark = $('<input type="text" />').attr({
				className:	$text.attr('class'),
				size:		$text.attr('size')
			}).insertBefore($text);

			$watermark.addClass('watermarkInput');
			$watermark.val($text.attr('title'));

			$watermark.attr('autocomplete', 'off');
			$text.attr('autocomplete', 'off');
			
			$watermark.focus(function() {
				$text.show().focus().unbind('blur').blur(function() {
					if ($text.val() == "") {
						$text.hide();
						$watermark.show();
					}
				});
				$watermark.hide();
			});
			
			if ($text.val() != '') {
				$watermark.focus();
			};

			$('form').submit(function() { $('.watermarkInput').remove(); });
			
			$text.hide();
			$watermark.show();
		});
		
	};
})(jQuery);