window.blog = window.blog || {};
blog = {
    id : null,
    getCommentDialogue : function()
    {
        $.get(wwwUrl + "/ajax/comment/get-form?blogId=" + this.id, function(html) {
            $(".lightbox").html(html);
        });
        lightbox.open();
    },
    addComment : function()
    {    
        $.post(wwwUrl + "/ajax/comment/add", { 
            name: $("#name").val(), 
            email: $("#email").val(), 
            website: $("#website").val(), 
            comment: $("#comment").val(), 
            blogId: $("#blogId").val()}, function(response) {
            if (response == 'error') {
                $(".error").html('a required field is missing!');
                return;
            }
            $(".lightbox").html(response);
            blog.getComments();
            setTimeout("lightbox.close()",1000);
        });
    },
    getComments : function()
    {
        var timestamp = new Date().getTime();
        $.get(wwwUrl + "/ajax/blog/get-comments?blogId=" + this.id + "&timestamp=" + timestamp, function(html) {
            $("#comments").html(html);
        });
    }
}

$(document).ready(function() {
    $(".addComment").click(function() {
        blog.id = $(this).attr("id").split('_').pop();
        blog.getCommentDialogue();
        return false;
    });
});