2     function scrollToAnchor(anchor) {
 
   4             var anchor_name = anchor.slice(1);
 
   5             var element = $('a[name="' + anchor_name + '"]');
 
   6             if (element.length > 0) {
 
   7                 $.scrollTo(element, 500, {offset: {top: -50, left: 0}});
 
   8                 foot_elem = $('#footnotes a[name="' + anchor_name + '"]');
 
   9                 if (foot_elem.length > 0) {
 
  10                     $(element).parent().highlightFade('yellow');
 
  12                 window.location.hash = anchor;
 
  17     $.highlightFade.defaults.speed = 3000;
 
  19     if ($('#toc li').length == 0) {
 
  20         $('#menu li a[href="#toc"]').remove();
 
  22     if ($('#themes li').length == 0) {
 
  23         $('#menu li a[href="#themes"]').remove();
 
  25     if ($('#nota_red').length == 0) {
 
  26         $('#menu li a[href="#nota_red"]').remove();
 
  29     // On page load, scroll to anchor
 
  30     scrollToAnchor(window.location.hash)
 
  32     $('#toc, #themes, #book-text').delegate('click', 'a', function(event) {
 
  33         event.preventDefault();
 
  34         $('#menu li a.selected').click();
 
  35         scrollToAnchor($(this).attr('href'));
 
  38     $('#menu li a.menu').toggle(function() {
 
  39         $('#menu li a.selected').click();
 
  40         $(this).addClass('selected');
 
  41         $($(this).attr('href')).slideDown('fast');
 
  43         $(this).removeClass('selected');
 
  44         $($(this).attr('href')).slideUp('fast');
 
  48     if (window.getSelection) {
 
  49         $('.theme-begin').click(function() {
 
  50             var selection = window.getSelection();
 
  51             selection.removeAllRanges();
 
  52             var range = document.createRange();
 
  54             var e = $(".theme-end[fid='" + $(this).attr('fid') + "']")[0];
 
  57                 range.setStartAfter(this);
 
  58                 range.setEndBefore(e);
 
  59                 selection.addRange(range);