jQuery.Engine.comments = function(options) {
	this.settings = jQuery.extend({}, jQuery.Engine.comments.defaults, options);
};
jQuery.extend(jQuery.Engine.comments, {
	defaults : {
		FORM_ID: '#post_resource_comment',
		POST_COMMENT_BUTTON: '#post_comment',
		COMMENT_FIELD_ID: '#comment',
		PROCESSING_PANEL_ID: '#submit_ajax',
		POST_REPLY_COMMENT_ID: '#id_reply_res_comment',
		POST_REPLY_COMMENT_PANEL: '#post_reply_panel',
		DELETE_ICON_DIR: 'http://www.celebsfreak.com/img/icons/Delete.png',
		ERROR_CLASS_NAME: 'error'
	},
	
	prototype: {
		initialize : function() {
			this.initProcess();
			this.initField();
			this.initReply();
		},
		
		initProcess : function() {
			var FORM_ID = this.settings.FORM_ID;
			var POST_COMMENT_BUTTON = this.settings.POST_COMMENT_BUTTON;
			var PROCESSING_PANEL_ID = this.settings.PROCESSING_PANEL_ID;
			
			$(FORM_ID).submit(function() {
				$(POST_COMMENT_BUTTON).hide();
				$(PROCESSING_PANEL_ID).show();
			});
		},
		
		initField : function() {
			var COMMENT_FIELD_ID = this.settings.COMMENT_FIELD_ID;
			var ERROR_CLASS_NAME = this.settings.ERROR_CLASS_NAME;
			
			$(COMMENT_FIELD_ID).focus(function() {
				$(this).removeClass(ERROR_CLASS_NAME);
			});
		},
		
		initReply : function() {
			var POST_REPLY_COMMENT_ID = this.settings.POST_REPLY_COMMENT_ID;
			var POST_REPLY_COMMENT_PANEL = this.settings.POST_REPLY_COMMENT_PANEL;
			var DELETE_ICON_DIR = this.settings.DELETE_ICON_DIR;
			
			$('a.post_reply').each(function(i) {
				$(this).click(function() {
					$(POST_REPLY_COMMENT_ID).val($(this).attr('postid'));
					
					var msg = $(this).parent().parent().find('.comment').html();
					var userPhoto = $(this).attr('userphoto');
					var username = $(this).attr('username');
					var postdate = $(this).attr('postdate');
					
					$(POST_REPLY_COMMENT_PANEL).html('<div class="post_reply_to"><h1>Reply</h1><a href="#comment" id="post_reply_to_close" class="removereply"><img src="'+DELETE_ICON_DIR+'" border="0"/></a><span><img src="'+userPhoto+'"/><cite>'+username+'</cite><small>'+postdate+'</small></span><p>'+msg+'</p></div>');

					$('#post_reply_to_close').click(function() {
						$(POST_REPLY_COMMENT_ID).val('');
						$(POST_REPLY_COMMENT_PANEL).html('');
					});
				});
			});
		}
	}
});

