$(function() {
  if (!$('.toc').size())
    return;

  var notesItem = $('<li><a href="#commentWidgetTitle">' +
                    'User Notes</a> <span class="commentCount">' +
                    '</span></li>').hide().appendTo($('.toc ol'));

  window.setInterval(function() {
    if ($('#commentWidgetTitle').size()) {
      var count = $('#commentwidget .commentHeader').size();
      $('.commentCount', notesItem).text(count ? ('(' + count + ')')
                                               : '');
      notesItem.show();
    }
  }, 500);
});
