Comment = Class.create({
	initialize: function(element) {
		this.initializeElement(element);
	},
	
	initializeElement: function(element) {
		this.element = $(element);
		if (this.element)
		{
			this.url	= this.element.readAttribute("url");
			this.video	= this.element.readAttribute("video");
			this.resultDisplayer = $("commentResultDisplayer");
			$("sendButton").observe("click", this.sendListener.bindAsEventListener(this));
		}
	},
	
	sendListener: function(e) 
	{
		this.send();
	},
	
	send: function ()
	{
		var commentVal	= $F('commentText');
		var captchaVal	= $F('commentCaptcha');
	
		new Ajax.Request(this.url, {
			method		: 'get',
			parameters	: {
				video		: this.video,
				comment		: commentVal,
				captcha		: captchaVal}, 
			onComplete 	: this.sendResponse.bind(this)
		});
		
		this.resultDisplayer.update("Sending your comment. Please wait...");			
	},
	
	sendResponse: function(transport)
	{
		var response 	= transport.responseText.evalJSON();
		if(response.status && response.status == 'success') 
		{
			this.resultDisplayer.update("Your comment sent succesfully and is waiting for approval.");
		}
		else
		{
			this.resultDisplayer.update(response.message);		
		}
		displayer.show();
	}
});

function windowLoadedComment()
{
	new Comment("commentTable");
}

(function() {
	Event.observe(window, "load", windowLoadedComment);
})();

