
var Comments = new Class({
	Implements: [Options, Events, Chain],
	
	initialize: function(options){
		this.setOptions(options);
		if(!$('comment')) return;
		
		this.form = $('comment_form');
		this.top = false;
		this.abs_bottom = $('comment').getCoordinates().bottom;
		this.form.setStyle('position', 'relative');
		this._fields();
		if(!Browser.Engine.presto) this._scroll();
	},

	_fields: function(){
		this.fields = this.form.getElements('input,textarea');
		this.fields.each(function(input){
			input.set('title', input.get('value'));
			input.addEvents({
				'focus': function(){
					if(input.get('value') == input.get('title')) input.set('value', '');
				},
				'blur': function(){
					if(input.get('value') == '') input.set('value', input.get('title'));
				}
			});
		}.bind(this));
	},

	_scroll: function(){
		if((this.form.getCoordinates().height.toInt()+20) >= window.getSize().y) return;
		
		window.addEvent('scroll', function(){
			if(!this.top) this.top = this.form.getCoordinates().top.toInt();
			var pos = window.getScroll().y.toInt() - this.top + 20;
			if(pos < 0) pos = (Browser.Engine.webkit?20:0);
			this.form.tween('top', pos);
		}.bind(this));
	}
});

window.addEvent('domready', function(){ new Comments(); });