<script>

  //TOC generation
    $('#toc').toc({
        'selectors': 'h1,h2:not(.TermNum)', //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': true, //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();
    });
    $('body').animate({ 'margin-left': '0' }, 'slow');
}
else {
    $('nav').show();
    $('nav').animate({ 'left': '0px' }, 'slow');
    $('body').animate({ 'margin-left': '298px' }, '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>

<script>

// jQuery Inline Footnotes v1.0.3 // Copyright © 2011 Vesa Vänskä, released under the MIT License.

// Generated by CoffeeScript 1.6.1 (function() {

(function($) {
  $.inlineFootnote = function(el, options) {
    var _this = this;
    this.el = $(el);
    this.el.data("inlineFootnote", this);
    this.initialize = function() {
      this.options = $.extend({}, $.inlineFootnote.defaultOptions, options);
      this.footnoteId = this.el.attr("href").match(/#(.*)/)[1];
      if (this.footnoteId) {
        this.el.mouseenter(this.openBox);
        return $("body").mousemove(this.closeBox);
      }
    };
    this.openBox = function(event) {
      var footnoteContent, linkOffset;
      if (!_this.box) {
        footnoteContent = $("[id='" + _this.footnoteId + "']").children().filter(":not('" + _this.options.hideFromContent + "')");
        linkOffset = _this.el.offset();
        _this.box = $("<div />", {
          id: _this.options.boxId,
          html: footnoteContent.clone().find(_this.options.hideFromContent).remove().end(),
          css: {
            position: "absolute",
            top: linkOffset.top,
            left: linkOffset.left + _this.el.outerWidth()
          }
        }).appendTo("body");
        return _this.positionBox();
      }
    };
    this.closeBox = function(event) {
      if (_this.box) {
        if (_this.isHoveringFootnote(event)) {
          clearTimeout(_this.closeTimeout);
          return _this.closeTimeout = null;
        } else {
          if (!_this.closeTimeout) {
            return _this.closeTimeout = setTimeout((function() {
              _this.box.remove();
              return _this.box = null;
            }), _this.options.hideDelay);
          }
        }
      }
    };
    this.isHoveringFootnote = function(event) {
      return this.box.is(event.target) || $(event.target).closest(this.box).length > 0 || event.target === this.el[0];
    };
    this.positionBox = function() {
      var boxHorizontalPadding, boxLeft, boxWidth, linkLeftOffset, windowWidth;
      boxHorizontalPadding = parseInt(this.box.css("padding-left")) + parseInt(this.box.css("padding-right"));
      linkLeftOffset = this.el.offset().left;
      windowWidth = $(window).width();
      if ((windowWidth / 2) > linkLeftOffset) {
        boxLeft = linkLeftOffset + 20;
        boxWidth = windowWidth - boxLeft - boxHorizontalPadding - this.options.boxMargin * 2;
        if (boxWidth > this.options.maximumBoxWidth) {
          boxWidth = this.options.maximumBoxWidth;
        }
      } else {
        boxWidth = linkLeftOffset - boxHorizontalPadding - this.options.boxMargin * 2;
        if (boxWidth > this.options.maximumBoxWidth) {
          boxWidth = this.options.maximumBoxWidth;
        }
        boxLeft = linkLeftOffset - boxWidth - this.options.boxMargin * 2;
      }
      return this.box.css({
        width: boxWidth,
        left: boxLeft
      });
    };
    return this.initialize();
  };
  $.inlineFootnote.defaultOptions = {
    boxMargin: 20,
    hideDelay: 200,
    hideFromContent: "[rel=footnote]",
    maximumBoxWidth: 500,
    boxId: "footnote_box"
  };
  return $.fn.inlineFootnote = function(options) {
    return this.each(function() {
      return new $.inlineFootnote(this, options);
    });
  };
})(jQuery);

}).call(this); </script>

<script>

$(function() {
  $("[rel=footnote]").inlineFootnote();
  });

</script>