/*
	Author: The Bridge
	Copyright (c): 2011 The Bridge
	Created: 14-11-2011
	Last Modified: 15-11-2011
	Name: Textfield
	Description: Stylize form fields
*/

(function( $ ){
	$.fn.textfield = function( options ) {  
    	var settings = { 'height' :  26, 'text' : 'Please enter...', 'inlinehtml' : '', 'inlinestyle' : '' };

	    return this.each(function() {        
	      	if ( options ) { $.extend( settings, options ); }
	      	
			var $this = $(this);
	
			// Set the input value to be that of the (parsed) settings text
			$this.val(settings.text);
			
			// On foucs, check if text has changed.
			// If is hasn't, clear input, otherwise leave user input.
			$this.focus(function(){ 
				if ($(this).val() == settings.text){
					$(this).val('');
				}
			});
			
			// Opposite to focus
			$this.blur(function(){ 
				if ($(this).val() == ''){
					$(this).val(settings.text);
				}
			});
			
			// Wrap element in background image divs
			$this.wrap('<div class="form_field" style="height: ' + settings.height + 'px !important;"><div id="frm_field_content" class="form_field_content"'+settings.inlinestyle+'></div>'+settings.inlinehtml+'</div>');
			$('<div class="form_field_top"></div>').prependTo('.form_field');
			$('<div class="form_field_btm"></div>').appendTo('.form_field');
	    });
  	};
})( jQuery );

