var newResultId = 1;
$(document).ready(function() {
  $('#buttonSubmit').click(function(){
    $('#ajaxLoad').fadeIn();
    $.post("_ajax.php?do=addComment", {
      comment: $('#commentText').val(),
	  item_id: $('#itemId').val(),
	  name: $('#commentName').val()
    }, function(response){
	  if (response != 'fail') setTimeout("addComment('"+escape(response)+"')", 800);
	  else {
	    $('#commentError').show();
		$('#ajaxLoad').fadeOut();
	  }
    });
    return false;
  });
});

function addComment (data) {
    $('#commentError').hide();
	$('#newComments').prepend('<div class="comment" id="newComment'+newResultId+'" style="display:none">' + unescape(data) + '</div>');
	$('#newComment'+newResultId).slideDown();
	newResultId++;
    $('#commentText').val('');
	$('#ajaxLoad').fadeOut();
}
