Fields				=	{ 
	active       	: null,
	
	initialize		: function() {
		$$('input[type=text], textarea, input[type=password]').each(function(element){
			Fields.setup($(element));														  
		});
	},
	
	setup			: function(element) {
		// Manage field-pale elements
		if(element.hasClass('field-pale')) {
			element.setProperty('autocomplete', 'false').
			setValue(element.getProperty('title'));
			
			element._isPale	= true;
			element._value	= element.getValue();
			
			// Title must match
			if(element.getProperty('title') !== element._value) {
				element._value = null;
			}				
			
			// Since 1st time in here also set the event for the form.
			// FIXME: fix this
			if(element.form) {
				$(element.form).addEvent('submit', function(event) {							  
					if(element.getValue() == element._value || !$is(element._value)) {					
						element.setValue('');
						event.stop();
					}
				});
			}
		}
		
		element.addEvents({
			'focus' : Fields.focus.bind(element),
			'blur'  : Fields.blur.bind(element)
		});
		
		element.isSet = true;
	},
	
	focus         : function(element) {
		// Event is already set
		if(element && $typeOf(element) === 'element') {
			if(!element.isSet) {
				Fields.setup($(element));
			} else {
				return this;	
			}
		}
	
		
		if(document.activeElement === undefined || this._notSupportingActiveElement) {
			this._notSupportingActiveElement = true;
			document.activeElement = this;	
		}
		if(!this._isPale) {
			return this;
		}
					
		if(this.getValue() == this._value) {
			this.removeClass('field-pale');
			this.setValue('');
		}
					
		if (window.ie) {
			this.addClass('field-focus');
		}
		
		this.active = this;
	},
	
	blur          : function() {
		if(this._notSupportingActiveElement) {
			document.activeElement = null;	
		}
		var value = this.getValue();
		if (window.ie) {
			this.removeClass('field-focus');
		}

		if (!value && this._isPale) {
			this.addClass('field-pale');
			this.setValue(this._value) ;
		}
		this.setValue(this.getValue().trim());
		
		this.active = null;
	}
};

Event.add( window, 'DOMContentLoaded', function() {
	Fields.initialize();
});
