var ajaxedComments = new Array();
var shownComments = new Array();

function ajaxShowComments(postid, throbberurl, commentpageurl) {
	$("#show-inline-comments-" + postid).css("display", "none");
	$("#hide-inline-comments-" + postid).css("display", "inline");
	
	if(ajaxedComments[postid] != undefined && (shownComments[postid] == undefined && shownComments[postid] == false)){
		$("#ajax-comments-" + postid).show("slow");
	}else{
		$("#ajax-comments-" + postid).hide();
		$("#ajax-comments-notification-" + postid).append('<div style="text-align:center"><img src="' + throbberurl + '" alt="loading" /></div>');
		$.post(commentpageurl, {id: postid}, function(data){ 
			ajaxedComments[postid] = data;
			$("#ajax-comments-notification-" + postid).hide();
			$("#ajax-comments-" + postid).append(data).show("slow");
			shownComments[postid] = true;
			});
	}
}

function ajaxHideComments(postid) {
	$("#show-inline-comments-" + postid).css("display", "inline");
	$("#hide-inline-comments-" + postid).css("display", "none");
	$("#ajax-comments-" + postid).hide("slow");
	shownComments[postid] = false;
}

function openAjaxCommentDiv(postid){
	$("#ajax_add_comment_div-" + postid).css("display", "block").fadeIn("slow");
}

function submitAjaxComment(throbberurl, url, postid, appendComment){
	var author = document.getElementById('author-' + postid).value;
	var email = document.getElementById('email-' + postid).value;
	var webseite = document.getElementById('url-' + postid).value;
	var comment = document.getElementById('comment-content-' + postid).value;
	
	//alert("postId: " + postid + "\nurl: " + url + "\nauthor: " + author + "\nemail: " + email + "\nwebseite: " + webseite + "\ncomment: " + comment);
	
	$("#ajax-comments-notification-" + postid).append('<div style="text-align:center"><img src="' + throbberurl + '" alt="loading" /></div>');
	$.post(url, {comment_post_ID: postid, author: author, email: email, url: webseite, comment: comment}, function(data){ 
			$("#ajax-comments-notification-" + postid).hide();
			$("#ajax-comments-" + postid).append(data).show("slow");
			shownComments[postid] = true;
			});
}