var comment_answer = function () {
	var _this = $(this);

	$("div.comments div.comment-form:first").remove();
	$("div.comments a.comment-answer:hidden:first").show();

	var answer = $("div.comment-form:first").clone().appendTo(_this.parent());

	$("form:first", answer).attr({ action: this.href });

	$(this).hide();
	return false;
};

$(window).load(function () {
	$("span.ajax-container a.ajax-powered").click(function () {
		_this = $(this);
		var container = _this.parent("span.ajax-container").get(0);

		$(container).load(_this.attr("href"));

		return false;
	});

	$("div.comment-body").each(function () {
		$("a.comment-answer:first", this).click(comment_answer);
	});
});

function submit_comment(form) {
	var _form = $(form);

	$.post(_form.attr("action"), _form.serialize(), function (data) {
		var _parent = _form.parent().parent().parent();
		data = $(data);

		if(_parent.hasClass("comment")) {
			$("a.comment-answer:first", data).click(comment_answer);

			_parent.append(data);
			$("div.comments a.comment-answer:hidden:first").show();
			$("div.comments div.comment-form:first").remove();
		} else {
			$("a.comment-answer:first", data).click(comment_answer);
			$("div.comments:first").append(data);
			$("div.comment-form:first textarea:first").val("");
		}
	});

	return false;
}
