
function loadComments(url , page){
	$.ajax({
		url:"ajax.comments.read.php?_LANG=" + $("html").attr("lang") + "&page=" + page,
		type:'post',
		data:'url=' + url ,
		success: function(msg){
			$('#comments-data').html(msg);
		}
	});
}

function reLoadComments(){
	loadComments($("#comments-data").attr("data-url") , 1);
}


$(document).ready(function() {

	if ($("#comments-data").length){
		//loadComments($("#comments-data").attr("data-url") , 1);
	}


	$(document).on(
		"click",
		".comment-reply",
		function(){	

			//remove all the replies from the replies
			$(".comments").find(".comment-new.reply").slideUp(function(){ 
				$(this).remove(); 
/*
				$(this).closest(".comment").after(
					"<div class=\"comment-new reply\">" + $(".comment-new.reply").html() + "</div>"
				);

				$(this).closest(".comment").next().slideDown("slow" , function() {

				});
*/				
			});

			var parent = $(this).closest(".comment");

			if ($(this).hasClass("opened"))	{

				$(this).removeClass("opened");

				parent.next().slideUp("slow" , function() {
					$(this).remove();
				});

			} else {
				$(this).addClass("opened");

				var replyform = $("<div class=\"comment-new reply\">" + $(".comment-new.reply").html() + "</div>");

				replyform.find("input[name=parent]").val(parent.attr('data-comment'));
				replyform.find(".reponsebox").empty();


				parent.after(
					replyform
				);

				parent.next().slideDown("slow" , function() {
					$(this).find("form-capcha-img").trigger("click");
				});
			}


			return false;
		}
	);
	
});