var CommentCounter = Class.create();
CommentCounter.prototype = {
	initialize  : function(input, countElement, options) {
		this.options = Object.extend({
			maxLength: 100,
			frequency: 0.5
		}, options || {});
		this.input = $(input);
		this.countElement = $(countElement);
		this.preText = '';
		this.startCount();
	},
	setCount: function() {
		var str = this.input.value;
		if (str == this.preText) return;
		this.preText = str;
		this.countElement.innerHTML = str.length + '/' + this.options.maxLength;
		if (str.length > this.options.maxLength) {
			this.countElement.style.color = 'red';
		} else {
			this.countElement.style.color = '';
		}
	},
	startCount: function() {
		this.countTimer = new PeriodicalExecuter(this.setCount.bind(this), this.options.frequency);
	},
	stopCount: function() {
		this.countTimer.stop();
	}
};
