$().ready(function()
{

    $(".report_trigger").click(function () {
		var id = $(this).parent().parent().parent().parent().children(".comment_id").val();
        var resp = $.post(
            'comments/ajax-report',
            {
                comment_id: id
            },
            function(response) {
                if(response.message) {
//                	alert(id);
					$(".comentframe :input.comment_id[value="+id+"]").parent().children(".comments_info").html(response.message).show();
                }
            },
            'json'
        );

    	$(this).hide();
//    	$(this).parent().parent().parent().parent().children(".comments_info").html(msg);

		return false;
    });

    $(".delete_comment_trigger").click(function () {
		var id = $(this).parent().parent().parent().parent().children(".comment_id").val();
        var rm = 0;
        $.post(
            'comments/ajax-delete',
            {
                comment_id: id
            },
            function(response) {
                if(response.result == 1) {
                	$(".comentframe :input.comment_id[value="+id+"]").parent().children(".comments_info").html(response.message).show();
                	$(".comentframe :input.comment_id[value="+id+"]").parent().children(".comments_info").insertAfter($(".comentframe :input.comment_id[value="+id+"]").parent().next());
                	$(".comentframe :input.comment_id[value="+id+"]").parent().hide();
                }
                else {
                	$(".comentframe :input.comment_id[value="+id+"]").parent().children(".comments_info").html(response.message).show();
                }
            },
            'json'
        );

//        if (rm = 1) {
//        	$(this).parent().parent().parent().parent().hide(200);
//        }

		return false;
    });

    $(".add_trigger").click(function () {
		$("#new_comment").toggle(400);
		return false;
    });

    addCommentActions();
	
});


	function addCommentActions() {
    $(".Form_Comment li.submit_container").click(function(){

	        $.post(
	            'comments/ajax-add-comment',
	            $('#add_comment_form').serialize()
	            ,
	            function(response) {
	            	if (response.result == 1) {
	            		$('#new_comment').next().next().html(response.html).show();
	            		$('#new_comment').hide();
	            		$(".comentframe .add_trigger").parent().hide();
	
	            	}
	            	else {
	                    $('#new_comment').html(response.html);
	                    addCommentActions();
	            	}
	            },
	            'json'
	        );
	        return false;
    	}
    );
}
