$(document).ready(function() {
  // -- For comments on a published article page
  
  $("a.reply_to_comment").click(function() {
    $("#parent_comment_author").text($(this).closest(".comment-info").find(".comment-author").text());
    $("#parent_comment_quote").html($(this).closest(".comment").find(".comment-body").html());
    var id = $(this).closest(".comment").attr("id").replace("comment-", "");
    $("#comment_parent_id").val(id);
    $("#comment_reply_to").show();
  });

  $("#undo_reply").click(function() {
    $("#comment_reply_to").hide();
    $("#comment_parent_id").val(null);
    return false;
  });

  // -- END

  // -- For posting comments anonymously

  $("#login-link").click(function() {
    $("#comment-poster").hide();
    $("#login-box").show();
    return false;
  });

  $("#cancel-login").click(function() {
    $("#login-box").hide();
    $("#comment-poster").show();
    return false;
  });

  var setup_login_form = function() {
    $("#new_user_session").ajaxForm(function(result, other) {
      if ($(result).is("form")) {
        $("#login-box").html(result);
        setup_login_form();
      }
      else {
        $("#login-box").hide();
        $("#comment-poster").html(result).show();
      }
    });
  };
  setup_login_form();

  // -- END
  
});
