var gbInputLength = new Class({
	
	Implements: Options,
    options: {
		inputAr			: [['input100', 45, 'count100']],
		txt				: ' Zeichen'
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.checkInput();
	},
	
	checkInput: function(){
		this.bound = {};
		for (i=0; i<this.options.inputAr.length; i++){
			this.setCounter(this.options.inputAr[i][2], this.options.inputAr[i][1] + this.options.txt);
			$$('.'+this.options.inputAr[i][0]).each(function(node) {
				this.bound.onKeyPress = this.onKeyPress.bindWithEvent(this,i);
				node.addEvent('keyup', this.bound.onKeyPress);
			}.bind(this));
		}
	},
	
	onKeyPress: function (event,i){
		el = $(event.target);
		maxlength = this.options.inputAr[i][1];
		el.setProperty('value',el.getProperty('value').substr(0,maxlength));
		this.setCounter(this.options.inputAr[i][2], (maxlength - el.getProperty('value').length) + this.options.txt);
		if (el.getProperty('value').length >= maxlength){
			el.blur();
		}
	},
	
	setCounter: function (el, count){
		if ($(el)){
			$(el).innerHTML = count;
		}
	}
});
gbInputLength.implement(new Options);

window.addEvent('domready', function(){
	if (typeof gbInputLengthopt == 'undefined'){
		gbInputLengthopt = {}; 
	}
	gbInputLength = new gbInputLength(gbInputLengthopt);
});
