jQuery(document).ready(function($) {
  $(".articlePage:not(:first)").hide(); //hide all but first page on load
    $('ul#pagerControls a:first').attr('class', 'selected'); //apply selected class to first page link

  // If specific page requested, display it
  var url = window.location.href;
  if(url.indexOf('#') != -1) {
    $('ul#pagerControls a.selected').removeAttr('class'); //remove the selected class after setting it above ^^
    $('.articlePage:visible').fadeOut('fast'); // hide all visible pages
    var page = url.substring(url.indexOf('#') + 1, url.length);
    $('#' + page).slideDown(); // show requested page
    $('ul#pagerControls a[@href$="#' + page + '"]').attr('class', 'selected'); //apply selected class to current page
  }

  $('ul#pagerControls a').click(function() { // on navigation click
    $('ul#pagerControls a.selected').removeAttr('class'); //remove the selected class
    $('.articlePage:visible').fadeOut('fast'); // hide current page
    var requestedURL = $(this).attr('href');
    $('#' + requestedURL.substring(requestedURL.indexOf('#') + 1, requestedURL.length)).slideDown(); // show the page with the id of the selected anchor
    $(this).attr('class', 'selected'); //apply selected class to clicked link
    //$('html,body').animate({scrollTop: '0'}, 1000); //scroll page to the top
    //return false;
  });
});