var jump=function(e)
{
       //prevent the "normal" behaviour which would be a "hard" jump
       e.preventDefault();
       //Get the target
       var target = $(this).attr("href");
       //perform animated scrolling
       $('html,body').animate(
       {
               //get top-position of target-element and set it as scroll target
               scrollTop: $(target).offset().top
       //scrolldelay: 2 seconds
       },2000,function()
       {
               //attach the hash (#jumptarget) to the pageurl
               location.hash = target;
               if(target != '#table'){
                 // Remove any previously applied styles/content
                 $(".m_articlecont p, .m_articlecont ol, .m_articlecont ul").removeClass('rc').css({ 'background-color': 'transparent', 'margin-left': '0px', 'margin-right': '0px'});
                 $(".m_returnbar").fadeOut("fast").remove();
                 if($(target).is('h1, h2, h3, h4, h5, h6') || $(target).hasClass('skip-hi')){
                   // Check if the target's next element has a skip class - if true, skip over that class item to the next element
                   if($(target).next("p, ul, ol").hasClass('skip-hi')){
                     $(target).next(".skip-hi").next("p, ul, ol").after('<div class="m_returnbar" style="display: none"><a class="ss" href="#table" title="return to the table of contents">Return to Helpful Topics</a></div>');
                     $(".m_returnbar").fadeIn("slow");
                     $(target).next(".skip-hi").next("p, ul, ol").addClass('rc').animate({ backgroundColor: "#fcf3e0", marginLeft: "10px", marginRight: "10px" }, "slow");
                   } else {
                     $(target).next("p, ul, ol").after('<div class="m_returnbar" style="display: none"><a class="ss" href="#table" title="return to the table of contents">Return to Helpful Topics</a></div>');
                     $(".m_returnbar").fadeIn("slow");
                     $(target).next("p, ul, ol").addClass('rc').animate({ backgroundColor: "#fcf3e0", marginLeft: "10px", marginRight: "10px" }, "slow");
                   }
                 // No class, target the nearest element
                 } else {
                   $(target).after('<div class="m_returnbar" style="display: none"><a class="ss" href="#table" title="return to the table of contents">Return to Helpful Topics</a></div>');
                   $(".m_returnbar").fadeIn("slow");
                   $(target).addClass('rc').animate({ backgroundColor: "#fcf3e0", marginLeft: "10px", marginRight: "10px" }, "slow");
                 }
                 $('a.ss').bind("click", jump);
               }
       });

}

$(document).ready(function()
{
       $('a.ss').bind("click", jump);
       return false;
});

