newjax.comments = function() {

	return {

		name: 'comments',


		update_total: function(item, type) {


			var total_container = 'comments_total_div_'+item;

			newjax.update(
				total_container,
				newjax.actions_page,
				{ newjax_action:'count_comments', item:item, type:type },
				function(t) {
					//if ($(form_container).style.display == 'block') newjax.expand(form_container);
					//if ($(comments_container).style.display != 'block') newjax.expand(comments_container);
				}
			);

		},


		post: function(item, type) {


			var form = type+'_comment_form_'+item;
			var form_container = 'post_comment_div_'+item;
			var comments_container = type+'_comments_div_'+item;

		
			var data = $(form).serialize();
			if (data) data += '&newjax_action=post_comment';

			

			newjax.update(
				comments_container,
				newjax.actions_page,
				data,
				function(t) {

					$(form).reset();

					newjax.comments.update_total(item, type);

					if ($(form_container).style.display == 'block') newjax.expand(form_container);
					if ($(comments_container).style.display != 'block') newjax.expand(comments_container);
					
				}
			);

		},


		delete: function(id, item, type) {


			var comments_container = type+'_comments_div_'+item;


			newjax.update(
				comments_container,
				newjax.actions_page,
				{ newjax_action:'delete_comment', id:id, item:item, type:type },
				function(t) {

					newjax.comments.update_total(item, type);

					//if ($(form_container).style.display == 'block') newjax.expand(form_container);
					//if ($(comments_container).style.display != 'block') newjax.expand(comments_container);

				}
			);

		}


	} //return

}();


Event.observe(window, 'load', function() {

	/* AFTER LOADING */
	
});