$.fn.defaultvalue = function(options) {
	var _options = jQuery.extend({
		defaultValueClass : "with-default-value",
		defaultValueInputType : 'text',
		inputType : 'text'
	}, options);
	
	var _matchedElements = this;
	
	// Actions for matched elements:
	_matchedElements.each(function() {
		// Set the class for the default value:
		if($(this).val() == _getDef($(this))) {
			$(this).addClass(_options.defaultValueClass);
			_setInputType($(this), _options.defaultValueInputType);
		}
		
		// Set event listeners:
		// - Remove default value, when the field is focussed:
		$(this).focus(function() {
			$(this).removeClass(_options.defaultValueClass);
			if($(this).val() == _getDef($(this))) {
				$(this).val('');
				_setInputType($(this), _options.inputType);
			}
		});
		
		// - Restore default value, if blurred and left empty:
		$(this).blur(function() {
			if(jQuery.trim($(this).val()) == '') {
				$(this).val(_getDef($(this)));
				$(this).addClass(_options.defaultValueClass);
				_setInputType($(this), _options.defaultValueInputType);
			}
		});
	});
	
	// Function to get default value
	function _getDef($input) {
		return document.getElementById($input.attr('id')).defaultValue;
	}
	
	// Function to change type of input field:
	function _setInputType($input, inputType) {
		document.getElementById($input.attr('id')).type = inputType;
	}
}
