/* 
	autofill Inputs with labels 
	takes input and adds class "hasValue" if it has a value on blur.
	everything else happens in CSS - label has to be positionized behind the input (absolute)
*/

var InputHasValueClass = Class.create({
	initialize: function(selector, options) {
		this.options = Object.extend({
			hasValueClass: 'hasValue'
		}, options);
		this.selector = selector || 'input';
		$$(this.selector).each(function(input) {
			// checking value at load, maybe page was reloaded..
			if(input.value) input.addClassName(this.options.hasValueClass);
			input.observe('blur', this.checkValue.bind(this));
		}.bind(this));
	},
	add: function() {
		var input = arguments[0];
		input.observe('blur', this.checkValue.bind(this));
	},
	checkValue: function(event) {
		var input = event.findElement();
		if(input.value) input.addClassName(this.options.hasValueClass);
		else input.removeClassName(this.options.hasValueClass);
	}
});

