jQuery(function($) {
  $(document).ready(function() {
    // Wenn Content Element Referenzen oder Referenten größer 0 ist
    if ($('#c263').length > 0 || $('#c2947').length > 0) {
      // START SectionScroll //
      $('<div id="scroller"><ul><li id="totop">top</li><li id="prev">prev</li><li id="next">next</li><li id="tobottom">bottom</li></ul></div>').appendTo("body"); //append the Next arrow div to the bottom of the document
      
      // Scroller ein und ausblenden
      $(window).scroll(function () {
        if ($(window).scrollTop() > 100) {
          $('#scroller').fadeIn();
        } else {
      $('#scroller').fadeOut();
        }
      });
      
      // Ganz nach oben scrollen
      $('#totop').click(function(e){
        e.preventDefault();
        $.scrollTo($('.outerwrap'), 1000, 'easeInOutQuart');
      });
      
      // Ganz nach unten scrollen
      $('#tobottom').click(function(e){
        e.preventDefault();
        $.scrollTo( $('.content').height(), 1000, 'easeInOutQuart');
      });
      
      // Scrolle zur nächsten section
      $('#next').click(function(e){
        e.preventDefault();
        scrollTop = $(window).scrollTop();
        $('.content > div > nav > ul > .odd').each(function(i, div){ // loop through article headings
          divtop = $(div).offset().top; // get article heading top
          if (scrollTop < divtop - 39 - $(this).css('marginTop').replace("px", "") ) { // compare if document is below heading
            newScroll = divtop - 39 - $(this).css('marginTop').replace("px", "");
            $.scrollTo(newScroll, 1000, 'easeInOutQuart'); // scroll to in .8 of a second
            return false; // exit function
          }
        });
      });
      
      // Scrolle zur vorherigen section
      jQuery.fn.reverse = function() {
        return this.pushStack(this.get().reverse(), arguments);
      };
      
      $('#prev').click(function(e){
        e.preventDefault();
        scrollTop = $(window).scrollTop();
        $('.content > div > nav > ul > .odd').reverse().each(function(i, div){ // loop through article headings
          divtop = $(div).offset().top; // get article heading top
          if (scrollTop > divtop + 40 ) { // compare if document is below heading
            newScroll = divtop - 39 - $(this).css('marginTop').replace("px", "");
            $.scrollTo(newScroll, 1000, 'easeInOutQuart'); // scroll to in .8 of a second
            return false; // exit function
          }
        });
      });
      
    }
    // ENDE SectionScroll //
    
  });
});
                    
