//----------------------------------------------------------------------------------
// Plugin for jQuery 1.2.x to allow setting default text for text form fields when
// not focused on the fields and no custom text has been entered
//
// Title text acts as default text for text form fields
// - To enable this feature for a text field, add the class "default-text"
//
// Neil Monroe (neil.monroe@gmail.com)
// v1.0 / 02.06.2009
//----------------------------------------------------------------------------------

(function($) {

	$.extend({
		defaultText: {
			defaults: {
				selector: "default-text",
				blurClass: "blur"
			},
			init: function() {
				$("." + this.defaults.selector)
					.focus(this.focusText)
					.blur(this.blurText)
					.trigger("focus")
					.trigger("blur"); // reset text boxes initially
			},
			focusText: function(e) {
				$(this).removeClass($.defaultText.defaults.blurClass);
				if (this.value == this.title) this.value = "";
			},
			blurText: function(e) {
				if (!this.value.match(/\S/g) || this.value == this.title) {
					$(this).addClass($.defaultText.defaults.blurClass);
					this.value = this.title;
				}
			}
		}
	});
	
	// Automatically initiallize this plugin when the DOM is ready
	$(function(){
		$.defaultText.init();
	});

})(jQuery);

