/**
 * Make Nice Input (http://http://www.adrianpalmer.me/projects/jquery/mNI)
 * 
 * Version 1.0b
 * November 21, 2008
 *
 * Copyright (c) 2008 Adrian Palmer (http://www.adrianpalmer.me) Developed whilst under tenure at Revium (http://revium.com.au)
 * Licensed under the GPL licenses.
 * http://www.gnu.org/licenses/gpl.txt
 **/

jQuery.fn.makeNiceInput = function(value){
	
	if(typeof(value) == 'undefined') var mNI_value = false;
	else var mNI_value = value;
	
	this.each(function(){

		name = $(this).attr('name');
		
		if(mNI_value == false) value = $('label[for='+name+']').hide().text();
		else {
			
			value = mNI_value;
			
			// Needed so we know what value to reinstate if required.
			$(this).addClass('mNI');
			
		}

		$(this).val(value);
		
		$(this).focus(function(){
			
			if($(this).val() == $('label[for='+$(this).attr('name')+']').text() || ($(this).hasClass('mNI') && $(this).val() == mNI_value)){
			
				$(this).val('');
				$(this).addClass('current');
				
			};
			
		});
		
		$(this).blur(function(){
			
			if($(this).val() != '') return;
				
			if(mNI_value == false) $(this).val($('label[for='+$(this).attr('name')+']').text());
			else $(this).val(mNI_value);
			
			$(this).removeClass('current');
				
		});

  	});
	
};
