/*
 * @author     Andrei Eftimie
 * @email      andrei.eftimie@netlogiq.ro
 * @copyright  (c) Netlogiq 
 * @web        http://www.netlogiq.ro
 *             http://www.netlogiq.com
 * 
 * Required Markup
 * ---------------
 * <div class="div">                  //or any other wrapper
 *   <label>Field Name</label>        //will be used as the input value
 *   <input type="text" />            //text input
 * </div>
 * 
 * Calling
 * -------
 * $('.div').emptyOnFocus();          //It doesn't have any options at this time
 * 
 */

(function($){
	$.fn.emptyOnFocus = function(options) {
	
		var defaults = {
			//no options at this time
		};
		
		var options = $.extend(defaults, options);
		
	    return this.each(function() {
	
			wrapper = $(this);  
			var label = $('label',wrapper);
			var input = $('input[type=text]',wrapper);
			var text = label.text();
			
			//We hide the label
			label.hide();
			
			input
				//We populate the input with the label value
				.val(text)
				//Setting the focus and blur events
				.focus(
					function(){
						if ($(this).val() == text) {
							$(this).val('');
						}
					}
				)
				.blur(
					function(){
						if ($(this).val() == '') {
							$(this).val(text);
						}
					}
				);
			
			
		})
	};
})(jQuery);