$(document).ready(function() {	
	$('div#comment_form form').attach(CommentForm);
});

CommentForm = $.klass(Remote.Form, {
	initialize: function($super, options) {		
		this.submit_button = $(".submit_button", this.element);
		this.submit_text = this.submit_button.text();
		
		this.spinner = $(".spinner", this.element);
		this.textarea = $("textarea", this.element);
		
		$super();
	},
	
	beforeSend: function() {
		if (this.textarea.val() == '') return false;
		this.spinner.show();
		this.disable();
	},
	
	complete: function() {
		this.spinner.hide();
		this.enable();
	},
	
	success: function(response, result) {
		$("#comments .comments-nav").after(response);
		this.textarea.val('');
	},
	
	error: function() {
	},
	
	disable: function() {
		this.submit_button.attr('disabled', 'disabled').val('Submitting comment ...');
	},
	
	enable: function() {
		this.submit_button.removeAttr('disabled').val(this.submit_text);
	}
});
