/**
 * jQuery Plugin Input field default value
 *
 * @version
 * 
 * @author Erkki-Ilmari Rajakoski [erkki dot rajakoski at creanor dot com]
 * @copyright	Creanor (c) 2010. All rights reserved.
 * @license     http://www.opensource.org/licenses/gpl-license.php
 *
 * @package     jQuery Plugins
 *
 */
 
(function(jQuery) {

	jQuery.fn.defaultValueInputField = function(options) {
		return this.each(function() {
			new jQuery.defaultValueInputField(this, options);
		});
	};

	jQuery.defaultValueInputField = function(element, options) {
		this.options = jQuery.extend({
			defaultValueColor 	: null,
			valueColor			: null,
			defaultValue		: ''
		}, options);
		this.element = $(element);
		this.initialize();
	}
	
	jQuery.defaultValueInputField.prototype.initialize = function() {
		var self = this;
		
		this.element.bind('click', function() {
			var str = $(this).val();
			if (str == self.options.defaultValue) {
				$(this).val('');
			}
			if (self.options.valueColor !== null) {
				$(this).css('color', self.options.valueColor);
			}
		});
		this.element.bind('blur', function() {
			var str = $(this).val();
			if (str == '' || str == self.options.defaultValue) {
				self.element.val(self.options.defaultValue);
				if (self.options.defaultValueColor !== null) {
					$(this).css('color', self.options.defaultValueColor);
				}
			}
		});
		this.element.val(this.options.defaultValue);
		if (this.options.defaultValueColor !== null) {
			this.element.css('color', self.options.defaultValueColor);
		}
	};
})(jQuery);
