$(document).ready(function(){
    $('#commentform').ajaxForm({
        url: 'http://gohave1.com/wp/wp-content/plugins/ajax-comments/ajax-comments.php?submit',
        success: function(data, status) {
            /*
            if ($('ul.comments.rest').get(0)) {
                $('ul.comments.rest').append(data);
                Comments.show(function() {
                    $('ul.comments.rest li.comment:last-child').fadeIn();
                    window.location.hash = $('ul.comments.rest li.comment:last').attr('id');
                });
            }
            else {
                $('ul.comments').append(data);
                $('ul.comments li.comment:last-child').fadeIn();
                window.location.hash = $('ul.comments li.comment:last').attr('id');
            }
            */
            
            $('#commentPreview').empty();
            $('#comment, #author, #url').clearFields();

            if (!$('#commentform div.popup-success').get(0)) {
                $('#commentform').append('\
                    <div class="popup popup-post popup-success">\
                        <a href="#" class="close">Close</a>\
                        <h3>Thank You.</h3>\
                        <div class="content">\
                            <p>We appreciate your comments, thank you.</p>\
                            <p>They will be reviewed by our site host and posted\
                            within 24 hours.</p>\
                            <p><a href="#" class="popup-guidelines">Posting Guidelines</a></p>\
                        </div>\
                    </div>\
                ');
                
                $('#commentform div.popup-success a.close').click(function() {
                    $('#commentform div.popup-success').fadeOut();
                    return false;
                });
                
                $('#commentform div.popup-success a.popup-guidelines').click(function() {
                    $('#commentform a.guidelines').trigger('click');
                    return false;
                });
            }
            
            $('#commentform div.popup-success')
                .hide()
                .fadeIn();
        },
        error: function(http, err, ex) {
            if (http.status != 406) {
                var error_msg = 'Comment Error ' + http.status + ': ' + http.statusText;
            }
            else {
                var error_msg = http.responseText;
            }
            
            if (!$('#commentform div.popup-error').get(0)) {
                $('#commentform').append('\
                    <div class="popup popup-post popup-error">\
                        <a href="#" class="close">Close</a>\
                        <h3>Oops!</h3>\
                        <div class="content">\
                        </div>\
                    </div>\
                ');
                
                $('#commentform div.popup-error a.close').click(function() {
                    $('#commentform div.popup-error').fadeOut();
                    return false;
                });
            }
            
            $('#commentform div.popup-error div.content').html('\
                <p>' + error_msg + '</p>\
            ');
            
            $('#commentform div.popup-error')
                .hide()
                .fadeIn();
        }
    });
});
