<script>
  //TOC generation
    $('#toc').toc({
        'selectors': toclevel(), //elements to use as headings
        'container': 'main', //element to find all selectors in
        'smoothScrolling': true, //enable or disable smooth scrolling on click
        'prefix': 'toc', //prefix for anchor tags and class names
        'onHighlight': function(el) {}, //called when a new section is highlighted 
        'highlightOnScroll': false, //add class to heading that is currently in focus
        'highlightOffset': 100, //offset to trigger the next headline
        'anchorName': function(i, heading, prefix) { //custom function for anchor name
            return prefix+i;
        },
        'headerText': function(i, heading, $heading) { //custom function building the header-item text
            return $heading.text();
        },
    'itemClass': function(i, heading, $heading, prefix) { // custom function for item class
      return $heading[0].tagName.toLowerCase();
    }
    });

</script>

<script>

//TOC toggle animation

$('#toggle').on('click', function(){

if( $('nav').is(':visible') ) {
    $('nav').animate({ 'left': '-353px' }, 'slow', function(){
        $('nav').hide();
    });
    $('.container').animate({ 'padding-left': '31px' }, 'slow');
}
else {
    $('nav').show();
    $('nav').animate({ 'left': '0px' }, 'slow');
    $('.container').animate({ 'padding-left': '360px' }, 'slow');
}

}); </script>

<script>

  // Scroll to top button
  window.onscroll = function() {scrollFunction()};

  function scrollFunction() {
      if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
          document.getElementById("myBtn").style.display = "block";
      } else {
          document.getElementById("myBtn").style.display = "none";
      }
  }

  // When the user clicks on the button, scroll to the top of the document
  function topFunction() {
      document.body.scrollTop = 0;
      document.documentElement.scrollTop = 0;
  }
  </script>

<script>

/*

$(document).ready(function() {
        $('[id^=toc]').each(function ()
        {
           var currentToc = $(this);
     var url = window.location.href;
           currentToc.wrap("<a href='" + url + "#" + currentToc.attr("id") + "' </a>");
        });

}); */ </script>