// Initial state Menu hide & appear at scroll
//var lastScrollTop = 0;

// The resize function
function resizeContentCarousel() {
  var vheight = $(window).height();
  var vwidth = $(window).width();
  $('#fullscreenTeaser').css({
    'height': vheight,
    'width': vwidth 
  });
  $('#fullscreenTeaser .carousel-inner .item-image').css({
    'height': vheight,
    'width': vwidth 
  });
  //alert(vheight);
};

// detect TocuhDevice
var isTouchDevice = 'ontouchstart' in document.documentElement;

/*
var urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('cookieconsent_status')) {
   console.log('test');
   document.cookie = "cookieconsent_status=allow";    
} else {
} */

// Do stuff when document is ready
$(document).ready(function(){
	
  // Video 1
  $('#videoModal-1').on('shown.bs.modal', function (event) {
    $('#videoModal-1 video')[0].play();
  });
  $('#videoModal-1').on('hidden.bs.modal', function (event) {
    $('#videoModal-1 video')[0].pause();
  });	
	
// Contactbox in-out	
if (document.getElementById("focus-Mobile-ContactBoxEdge")){
	
	$('#focus-Mobile-ContactBoxEdge').click(function(){
      $('#ContactBoxEdge').toggleClass("focused");
      $('#focus-Mobile-ContactBoxEdge').toggleClass("active");
	  $('#ContactBoxEdge.focused > #hidden-item').removeClass("margin-r");
      $('.navbar-collapse').removeClass("in");
  });
	if( isTouchDevice ) {
    $('#focus-ContactBoxEdge').click(function(){
      $('#ContactBoxEdge').toggleClass("focused");
    });
    
  } else {
    $('#ContactBoxEdge').click(function(){
      $('#ContactBoxEdge').toggleClass("focused");
	  $('#focus-ContactBoxEdge').toggleClass("focused");
    });
  }
} 

enquire.register('screen and (min-width: 992px)', {
      match : function() {
		  
		  $(window).scroll(function(){
					if ($(this).scrollTop() > 600) {
						$('#focus-ContactBoxEdge').fadeIn();
						$('#ContactBoxEdge.focused > #hidden-item').removeClass("margin-r");
						
					} else {
						$('#focus-ContactBoxEdge').fadeOut();
                        $('#ContactBoxEdge.focused > #hidden-item').addClass("margin-r");
					}
		  });
      }
});
	
	
		
// Teasernavigation ausblenden, wenn nur ein Bild ausgegeben wird  
$('.carousel ol.carousel-indicators').each(function() {
  var $this = $(this);
  if ($this.find('li').length == 1) { 
      $this.find('li').css("display", "none");
  }
}); 
$('.carousel').each(function() {
  var $this = $(this);
  if ($this.find('.carousel-item').length == 1) { 
      $this.find('.carousel-control-prev').css("display", "none");
	  $this.find('.carousel-control-next').css("display", "none");
      // $this.find('.carousel-navigation').css("display", "none");
      $this.find('.carousel-indicators').css("display", "none");
  }
});	

  /*Navbar on scroll*/
  $(window).scroll(function(event){
        var st = $(this).scrollTop();
        if ($(this).scrollTop() >= 10) {
          if (!$('#header').hasClass('scroll-down')) {
            $('#header').addClass('scroll-down');
            $('#navbarSupportedContent1').removeClass("show");                
          }
         } 
      
         //lastScrollTop = st;
      
         if ($(this).scrollTop() <= 0) {
           $('#header').removeClass('scroll-down');
           $('#header').removeClass("header-with-backgound");
         };
  });
  
  if( isTouchDevice ) {  
      $("body").addClass("isTouchDevice"); 
      //alert('isTouchDevice');   
  }
  
  
  // Scroll to Top
  $(window).scroll(function(){
            if ($(this).scrollTop() > 600) {
                $('#scrollToTop').fadeIn();
            } else {
                $('#scrollToTop').fadeOut();
            }
  });
  $('#scrollToTop').click(function(){
            $("html, body").animate({ scrollTop: 0 }, 600);
            return false;
  });
  
   // anchor link - scroll down
   /**/ if ($(window).width() > 974){ 
      $('a[href*="#"]').on('click',function(e) {
        if ( $( this ).hasClass( "accordeon-header" ) || $( this ).hasClass( "carousel-control" ) || $( this ).hasClass( "carousel-control-prev" ) || $( this ).hasClass( "carousel-control-next" ) ) {
        
        } else {
         var target = this.hash;
         var $target = $(target);
         $('html, body').animate({ scrollTop: $(target).offset().top - $('#header').outerHeight()  - 20 }, 900);
         e.preventDefault();
	 
       }
      }); 
      $(function(){
         if(location.hash){
           $('html, body').animate({ scrollTop: ( $(location.hash).offset().top - $('#header').outerHeight()  - 20 )}, 900);
 
         }
      }); 
  } else {
      $('a[href*="#"]').on('click',function(e) {
        if ( $( this ).hasClass( "accordeon-header" ) || $( this ).hasClass( "carousel-control" )  || $( this ).hasClass( "carousel-control-prev" ) || $( this ).hasClass( "carousel-control-next" ) ) {
          
          } else {
           var target = this.hash;
           var $target = $(target);
           
           $('html, body').animate({ scrollTop: $(target).offset().top - $('#header').outerHeight()  - 20 }, 900);
           e.preventDefault();

        }
      }); 
      $(function(){
         if(location.hash){
           $('html, body').animate({ scrollTop: ( $(location.hash).offset().top - $('#header').outerHeight()  - 20 )}, 900);
		   
         }
      }); 
  }
  

 if (window.matchMedia('(min-width: 992px)').matches) {
    // Resize Container Function
    resizeContentCarousel();
 }

$( ".dropdown" ).click(function() {
       $(".productNav").addClass("closed"); 
}); 

$(".navbar-toggler").click(function() {
        $("body").toggleClass("prevent-scroll");
}); 

if (window.matchMedia('(max-width: 992px)').matches) { 
        $(".navbar-toggler").click(function() {
                $("#header").toggleClass("mobileview fullheight");
        });
        $('#focus-Mobile-ContactBoxEdge').click(function(){
            $('#navbarContent').removeClass("show");
            $("#header").removeClass("mobileview fullheight");
            $(".navbar-toggler.nav-close").attr( 'aria-expanded', 'false');
            $(".navbar-toggler.nav-bars").attr( 'aria-expanded', 'false');
        });
}     

/*Akkordion - Tabelle Abstand raus*/
$( ".accordion-item .card-body table" ).parent().css( "padding", "0" );

});




// Resize Container on window resize
$(window).resize(function(){
    if (window.matchMedia('(min-width: 992px)').matches) { 
        resizeContentCarousel(); 
    } 
});