$(function () {
	// --- PAGETOP --- //
			$(document).ready(function(){
			     $(window).scroll(function () {
			            if ($(this).scrollTop() > 50) {
			                $('.pagetop-scroll').fadeIn();
			            } else {
			                $('.pagetop-scroll').fadeOut();
			            }
			        });
			        // scroll body to 0px on click
			        $('.pagetop-scroll').click(function () {
			            //$('.pagetop-scroll').tooltip('hide');
			            $('body,html').animate({
			                scrollTop: 0
			            }, 800);
			            return false;
			        });
			        //$('.pagetop-scroll').tooltip('show');
			});
			
			
			
	// --- STICKY-NAV-SCROLL --- //
			$(document).scroll(function () {
			    var $nav = $(".navbar");
			    $nav.toggleClass('scrolled', $(this).scrollTop() > $nav.height());
			});
			
			
			
	// --- STICKY --- //
			$(document).scroll(function () {
			    var $sticky = $(".sticky");
			    $sticky.toggleClass('scrolled', $(this).scrollTop() > $sticky.height());
			});
			
	// --- SCROLLING für irgendein Element mit der hinzugefügten Klasse '.scrolling' --- //
			 $(document).scroll(function () {
			    var $scrolling = $(".scrolling");
			    $scrolling.toggleClass('scrolled', $(this).scrollTop() > $scrolling.height());
			});	
        
        
    // Add class to body mit Class 'bodyscroll' when scrolling
			var targetDiv = $('.bodyscroll');
			$(window).scroll(function() {
				var windowpos = $(window).scrollTop();
				if( windowpos >= 50 ) {
			        targetDiv.addClass('scrolled');
			    	} 
			    else {
			        targetDiv.removeClass('scrolled');
			    	}
			});
	// Add class to body mit Class 'anchor-top' when scrolling
			var targetDiv = $('.anchor-top');
			$(window).scroll(function() {
				var windowpos = $(window).scrollTop();
				if( windowpos >= 50 ) {
			        targetDiv.addClass('scrolled');
			    	} 
			    else {
			        targetDiv.removeClass('scrolled');
			    	}
			});	
	// Add class to body when scrolling
			/*var targetDiv = $('body');
			$(window).scroll(function() {
				var windowpos = $(window).scrollTop();
				if( windowpos >= 50 ) {
			        targetDiv.addClass('scrolled');
			    	} 
			    else {
			        targetDiv.removeClass('scrolled');
			    	}
			});	 */  	
			
			
			
			
	
	
	// HIDE MENU ON SCROLL down
			var didScroll;
			var lastScrollTop = 100;
			var delta = 5;
			var navbarHeight = $('header').outerHeight();
			
			$(window).scroll(function(event){
			    didScroll = true;
			});
			setInterval(function() {
			    if (didScroll) {
			        hasScrolled();
			        didScroll = false;
			    }
			}, 100);
			
			function hasScrolled() {
			    var st = $(this).scrollTop();
			    // Make sure they scroll more than delta
			    if(Math.abs(lastScrollTop - st) <= delta)
			        return;
			     // If they scrolled down and are past the navbar, add class .hide-on-scroll-up.
			    // This is necessary so you never see what is "behind" the header.
			    if (st > lastScrollTop && st > navbarHeight){
			        // Scroll Down
			        $('header').removeClass('').addClass('scroll-disappear');
			    } else {
			        // Scroll Up
			        if(st + $(window).height() < $(document).height()) {
			        $('header').removeClass('scroll-disappear').addClass('scroll-top');
			        }
			    }
			    lastScrollTop = st;
			}
			$(window).scroll(function(){
			    if ($(this).scrollTop() > 0) {
			       $('header').addClass('scroll-show');
			    } else {
			       $('header').removeClass('scroll-show');
			    }
			});
						  
			        
});	



///////////////////////////////////////////////////////////////////////////////////////////////
// -------- Springt beim Scrollen zum Anchor, ohne unter der Sticky-Nav zu liegen --------- //
/////////////////////////////////////////////////////////////////////////////////////////////
/*
function scrollToAnchor(hash) {
	var target = $(hash),
        headerHeight = $(".navbar").height() + 120; // Sprunghöhe
        
    target = target.length ? target : $('[name=' + hash.slice(1) +']');

    if (target.length)
    {
        $('html,body').animate({
            scrollTop: target.offset().top - headerHeight
        }, 1000);
        return false;
    }
}


if(window.location.hash) {
	    scrollToAnchor(window.location.hash);
	}

$("a[href*=\\#]:not([href=\\#])").click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
        || location.hostname == this.hostname)
    {

        scrollToAnchor(this.hash);
    }
});
*/





///////////////////////////////////////////////////////////////////////////////////////////////
// -------- SEARCH --------- //
/////////////////////////////////////////////////////////////////////////////////////////////
$(document).ready(function() {
   $(".box-search > .form-control").click(function() {
        if ($(".box-search").hasClass("open")) {
            $(".box-search").removeClass("open"); 
        } else {
            $(".box-search").addClass("open"); 
        }
    });
});






///////////////////////////////////////////////////////////////////////////////////////////////
// -------- Accordion --------- //
/////////////////////////////////////////////////////////////////////////////////////////////
var acc = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < acc.length; i++) {
  acc[i].addEventListener("click", function() {
    this.classList.toggle("accordion-active");
    var panel = this.nextElementSibling;
    if (panel.style.maxHeight){
      panel.style.maxHeight = null;
    } 
    else {
      panel.style.maxHeight = panel.scrollHeight + "px";
    } 
  });
}