/*
	forb jQuery plugin version 1.1
	
	Author: Jonas Skovmand 
	Website: http://satf.se
	
	Description:
		A simple jQuery plugin that removes the initial value of an input on focus,
		and adds it back again on blur if the input is blank.
		The name is stupid and has little to do with the usage (well, 'fo' is hinting for a form,
		and 'rb' is 'really bugging' for those without javascript), but screw the name, it's the
		contents that is important, sort of.
	
	Usage:
		$("#input").forb(); // uses #input default value
		
		$("#input").val("Search...").forb(); // a way to define the initial value
		
		$("#input").forb ({
			initClass: "init-input",
			initValue: "Search..."
		});
		
		There are two options; initClass and initValue - both optional.
		 * initValue enables you to choose the initial value of the input, instead of what's in
		   the inputs value-attribute (originalValue from here on).
		 * initClass enables you to add a class to the init-/originalValue to customize its look
		   through CSS.
	
	Changelog:
		1.1 - (09/12 2008)
			Options initValue and initClass added, code refined
		
		1.0 - (08/12 2008)
			Plugin created by Jonas Skovmand
*/
;( function ( $ ) {
	$.forb = {
		defaults: {
			initClass: false, // change the class for the initiate value, like make it grey or something.
			initValue: false
		}
	};
	$.fn.extend({
		forb: function ( options ){
			return this.each ( function ( ) {
				
				var $obj = $(this), initValue, s = $.extend ( {}, $.forb.defaults, options );
				
				if ( s.initValue ) { initValue = s.initValue; $obj.val( initValue ) }
				else if ( ( df = $obj.val() ) != '' ) initValue = df;
				
				if ( s.initClass ) $obj.addClass ( s.initClass );
				
				$obj
					.focus ( function ( ) {
						if ( $obj.val() == initValue ) $obj.val ( '' );
						if ( s.initClass && $obj.hasClass ( s.initClass ) ) $obj.removeClass ( s.initClass );
					})
					.blur ( function ( ) {
						if ( $obj.val() == '' ) $obj.val ( initValue );
						if ( s.initClass && $obj.val() == initValue ) $obj.val(initValue).addClass ( s.initClass );				
					})
				;
				
			});
		}
	});
})(jQuery);
