/**
 * This function will be applied to all specified objects to
 * clear the value attribute when it's in focus and then restore
 * the value when it's out of focus.
 *
 * @param string focus_color The font colour used when the object is in focus
 * @param string blur_color The font colour used when the object has left focus
 */
jQuery.fn.clearValue = function(options) {
	// Set optional parameters
	var settings = jQuery.extend({
		focus_color: '#252525',
		blur_color: '#999999',
		defaultValue: ''
	}, options);
	
	// Apply the function to all objects
	return this.each(function() {
		if ($(this).val()=='') {
			$(this).attr('defaultValue', settings.defaultValue);
			$(this).val(settings.defaultValue);
		}
		else {
			var saveVal=$(this).val();
			$(this).attr('defaultValue', settings.defaultValue);
			$(this).val(saveVal);
		}
		
		// Only clear fields with a default value
		if($(this).attr('defaultValue') != '') {
			// Make sure the field value stays in focus when the page is refreshed
			if($(this).val() != $(this).attr('defaultValue') && !$(this).hasClass('error')) $(this).css('color',settings.focus_color);
			else if($(this).val() == $(this).attr('defaultValue') && !$(this).hasClass('error')) $(this).css('color',settings.blur_color);
			
			// Apply an onfocus event to the current object
			$(this).focus(function() {
				// Clear field if value is the default value
				if($(this).val() == $(this).attr('defaultValue')) {
					// Clear the field
					$(this).val('');
				}
				
				// Set the font colour of the field
				$(this).css('color',settings.focus_color);
			});
			
			// Apply an onblur event to the current object
			$(this).blur(function() {
				// Restore field if value is empty
				if($(this).val() == '') {
					// Restore the field
					$(this).val($(this).attr('defaultValue'));
					
					// Set the font colour of the field
					$(this).css('color',settings.blur_color);
				}
			});
		}
		else {
			// Apply an onfocus event to the current object
			$(this).focus(function() {
				// Set the font colour of the field
				$(this).css('color',settings.focus_color);
			});
		}
	});
}
