function handlePostscriptForm() {
	if($("#postscriptForm").attr("action") != $(this).attr("href")) {
		$("#postscriptForm").show().attr("action",$(this).attr("href"));
		$("#postscriptForm a").attr("href",$(this).attr("href"));
		$("#postscriptForm textarea").focus();
	} else {
		$("#postscriptForm").attr("action","").hide();
		$("#postscriptForm a").attr("href","");
	}
	return false;
}
function submitPostcript() {
	$("#postscriptForm input").hide();
	$.ajax({
		type:		this.method,
		url:		this.action,
		data:		{message: $("#postscriptForm textarea").val()},
		dataType:	"json",
		success:	function(output) {
			$("#ajaxMessage").attr("class",output.status).text(output.message).show();
			setTimeout(function() { $("#ajaxMessage").hide(); },5000);
			$("#postscriptForm").attr("action","").hide();
			$("#postscriptForm textarea").val("");
			$("#postscriptForm input").show();
		},
		error:		function() {
			$("#ajaxMessage").attr("class","error").text("An error occured during ajax request.").show();
			setTimeout(function() { $("#ajaxMessage").hide(); },5000);
			$("#postscriptForm").attr("action","").hide();
			$("#postscriptForm textarea").val("");
			$("#postscriptForm input").show();
		}
	});
	return false;
}
$(document).ready(function() {
	var label	= $("a.postscript:first").attr("title");
	$("<div id=\"ajaxMessage\" style=\"display: none\" />").appendTo("body");
	$("<form />")
	.attr("id","postscriptForm")
	.attr("method","post")
	.append($("<a href=\"#\">X</a>").bind("click",handlePostscriptForm))
	.append("<textarea name=\"text\" />")
	.append("<input type=\"submit\" value=\""+label+"\" />")
	.css( "display", "none" )
	.bind("submit",submitPostcript)
	.appendTo("body");
	//$("body").append($("<form method"));
	$("a.postscript").bind("click",handlePostscriptForm);
});

