function ajaxComment(args) {
    var media = args.media;
    
    $('div.comment-error').remove();
    
    if (commentBusy) {
        $('#comments_form form').before('\
            <div class="comment-error">\
                Speichere Deinen Kommentar.\
            </div>\
        ');
        $('div.comment-error').fadeOut(2000);
        
        return false;
    }
    
    comment = $('#comments_form form').serialize();
   
    // Add a wait animation
    $('input.submit-post').after('\
        <img src="' + media + '/images/ajax-loading.gif" alt="Bitte warten..."\
            class="ajax-loader" />\
    ');
    
    // Indicate that the comment is being posted
    $('p.submit').after('\
        <div class="comment-waiting" style="display: none;">\
           Einen Augenblick bitte . . .\
        </div>\
    ');
    $('div.comment-waiting').fadeIn(1000);
    
    commentBusy = true;
    
    url = $('#comments_form form').attr('action');
    
    // Use AJAX to post the comment.
    $.ajax({
        type: 'POST',
        url: url,
        data: comment,
        cache: false,  
        dataType: 'json',
        success: function(data) {
            commentBusy = false;
        
            removeWaitAnimation()
        
            if (data.success == true) {
                commentSuccess(data);
            } else {
                commentFailure(data);
            }
        },
        error: function(xmlreq, textstatus, err) {
            commentBusy = false;
            
            removeWaitAnimation()
            //$('#comments_form form').unbind('submit');
            //$('#comments_form form').submit();
        }
    });
    
    return false;
}

function commentSuccess(data) {

    $('#comments_form form').toggle('slow');

    $('#comments_form').after('\
        <div class="comment-thanks">\
            Danke für Deinen Kommentar. Formi wird ihn in Kürze freischalten.\
        </div>\
    ');
}

function commentFailure(data) {
    $('#comments_form ul.errorlist').each(function() {
	    this.parentNode.removeChild(this);
        });

    for (var error in data.errors) {
        $('#id_' + error).parent().before(data.errors[error])
    }
}

function removeWaitAnimation() {
    // Remove the wait animation and message
    $('.ajax-loader').remove();
    $('div.comment-waiting').stop().remove();
}


  $(document).ready(function() {
    previewed = false;
    commentBusy = false;
  });