(function ($) {
  Drupal.behaviors.calebdelnay = {
    attach: function (context, settings) {
      var loadingTimer = null;
      
      $('.comment-reply a', context).click(function () {
        var $a = $(this);
        var $loading = $('<div class="comment-form-loading">Loading reply form.</div>');
        $a.closest('ul').after($loading);
        
        loadingTimer = setInterval(function () { $loading.text($loading.text() + '.'); }, 500);
        
        $.ajax({
          url: $(this).attr('href'),
          success: function (dom) {
            $('#comment-form-reply').remove();
            clearTimeout(loadingTimer);
            var $replyForm = $('#comment-form', dom).attr('id', 'comment-form-reply');
            $replyForm.find('input[type=submit][value=Save]').after($('<input type="button" value="Cancel" />').click(function () { $replyForm.remove(); return false; }));
            $loading.replaceWith($replyForm);
          }
        });
        
        return false;
      });
    }
  };
}(jQuery));;

