(function($) {
	$.fn.defaultValue = function(defaultValue, options) {
		var el = this;
		settings = jQuery.extend({
			defaultColor: '#999',
			color: null,
			allowBlankSubmit: true
		}, options);

		function toDefault() {
			if (el.val() == defaultValue || el.val() == '') {
				el.css('color', settings.defaultColor);
				if (el.val() == '') {
					el.val(defaultValue);
				}
			} else {
				el.css('color', settings.color);
			}
		}
		
		function toNormal() {
			if (el.val() == defaultValue) {
				el.val('');
				el.css('color', settings.color);
			}
		}
		
		this.focus(toNormal);
		this.blur(toDefault);
		
		var form = this.parent('form');
		form.submit(toNormal);
		if (!settings.allowBlankSubmit) {
			form.submit(function (){
				if (!el.val()) {
					toDefault();
					return false;
				}
			});
		}
		
		toDefault(this);
	}
})(jQuery);
