$.inputPreset = function() {};
$.inputPresetByLabel = function() {};

(function($) {
	$.fn.inputPreset = function(preset)
	{
		var $obj = $(this);
		$obj.bind("click", function(){
			clear($obj, preset);
		})
		.bind("focus", function(){
			clear($obj, preset);
		})
		.bind("blur", function(){
			setTimeout(function(){
				$obj.inputPreset(preset);
			},100);
		});
		$obj.parents('form').submit(function(){
			clear($obj, preset);
		});
		if($obj.val() == ''){
			$obj.val(preset);
		}
	};

	function clear($obj,preset)
	{
		if($obj.val() == preset){
			$obj.val('');
		}
	};

	$.fn.inputPresetByLabel = function(hide)
	{
		$(this).each(function(){
		    var $obj = $(this);
			var id = $obj.attr('for');
			var $field = $('#'+id);
			if(id && $field.length == 1){
				if(typeof hide == 'undefined' || hide != false){
					$obj.hide();
				}
				$field.inputPreset($obj.text());
			}
		});
	};
})(jQuery);