// Extend jQuery to add a function for implementing "Nice Inputs"
jQuery.fn.makeNiceInput = function(){

	// Setup the selected elements as nice inputs.
	jQuery(this).each(function(){

		if(jQuery('label[for='+jQuery(this).attr('id')+']').length > 0){

			var MNval = jQuery('label[for='+jQuery(this).attr('id')+']').hide().text();

			if(jQuery(this).val() == ''){
				jQuery(this).val(MNval);
			}

			$(this).addClass('isMNice');

		}

	});

	jQuery(this).bind('focus', function(){

		if(jQuery(this).hasClass('isMNice') && jQuery(this).val() == jQuery('label[for='+jQuery(this).attr('id')+']').text()){

			jQuery(this).val('');

		}

	});

	jQuery(this).bind('blur', function(){

		if(jQuery(this).hasClass('isMNice') && jQuery(this).val() == ''){

			jQuery(this).val(jQuery('label[for='+jQuery(this).attr('id')+']').text())

		}

	});

	jQuery('form').bind('submit', function(){

		jQuery(this).find('.isMNice').each(function(){

			if(jQuery(this).val() == jQuery('label[for='+jQuery(this).attr('id')+']').text()){

				jQuery(this).val('');

			}

		});

	});

}
