$(window).load(function () {


  $('.flexslider').flexslider({
    animation: "slide",
    animationSpeed: 2000
  });



  $('a[href*=\\#]').on('click', function(event){
    event.preventDefault();
    $('html,body').animate({scrollTop:$(this.hash).offset().top -200}, 1100);
});



  $(".frame-akkordeon > header").addClass("arrow-right");

  $( ".frame-layout-3 .mx-auto" ).appendTo( $(".frame-layout-3 .ce-row:first-child .ce-column:first-child a") );
  $(".owl-wrapper").each(function () {
    $(this).wrapInner("<div class='flex flex-wrap'></div>");
  })
    });

if ($(window).outerWidth() <= 1178) {
  $("#language_menu_wrapper a.pointer").click(function () {
    $("#language_menu").slideToggle();
    $("#language_menu_wrapper").toggleClass("subaktiv");
    $(this).children("span").toggleClass("arrow-up").toggleClass("arrow-down");

  });
}

if ($(window).outerWidth() >= 1179) {
  var trigger = 0;
  $(window).resize(function () {
    if (trigger === 0) {
      if ($(window).outerWidth() <= 1178) {
        $("#language_menu_wrapper a.pointer").click(function () {
          $("#language_menu").slideToggle();
          $("#language_menu_wrapper").toggleClass("subaktiv");
          $(this).children("span").toggleClass("arrow-up").toggleClass("arrow-down");

        });
        trigger = 1;
      }
    }
  });
}

$(window).resize(function () {
  $("img").unveil();
  if ($(window).outerWidth() >= 1179) {
    $("ul.level2:visible").attr("style","");
  }
});
$(".mobile").click(function () {
  $("#megamenu").slideToggle();
});
$(".toggler").click(function () {
  $("#megamenu").find("li").removeClass("active");
  $(this).siblings("ul").slideToggle();
  $(this).toggleClass("arrow-up").toggleClass("arrow-down");
});




$(".frame-akkordeon header").click(function () {
  if($(this).hasClass( "arrow-right")){
    $(".frame-akkordeon > header").removeClass("arrow-left").addClass("arrow-right");
    $(".frame-akkordeon > header").siblings().slideUp();
  }
  $(this).toggleClass("arrow-left").toggleClass("arrow-right");
  $(this).siblings().slideToggle();
});

/*
$(function () {
  if ($(window).outerWidth() >= 1178) {
    $("ul.level2 > li").mouseenter(function () {
      $(this).siblings().attr("style", "background-color:transparent");
      $(this).siblings().children(".level3").hide();
      $(this).attr("style", "background-color:white;");
      $(this).children(".level3").show();
    });

    $("ul.level2 > li").mouseleave(function () {
      $(this).siblings().removeAttr("style");
      $(this).siblings().children(".level3").removeAttr("style");
      $(this).removeAttr("style");
      $(this).children(".level3").removeAttr("style");
    });
  }

  $(window).resize(function () {
    if ($(window).outerWidth() >= 1178) {
      $("ul.level2 > li").mouseenter(function () {
        $(this).siblings().attr("style", "background-color:transparent");
        $(this).siblings().children(".level3").hide();
        $(this).attr("style", "background-color:white;");
        $(this).children(".level3").show();
      });

      $("ul.level2 > li").mouseleave(function () {
        $(this).siblings().removeAttr("style");
        $(this).siblings().children(".level3").removeAttr("style");
        $(this).removeAttr("style");
        $(this).children(".level3").removeAttr("style");
      });
    }
  })
    });
*/

$(function () {
  $(".frame-akkordeon h4").click(function () {

    var that = this;
    setTimeout(function () {
      if ( $(window).outerWidth() >= 1178 ) {
        var offset = $(that).offset().top - 200;
      } else {
        var offset = $(that).offset().top - 10;
      }
      $('html, body').animate({
        scrollTop: offset + 'px'
      }, 'fast');
      return this;
    }, 400);
  });

  $(".frame-akkordeon h3").click(function () {

    var that = this;
    setTimeout(function () {
      if ( $(window).outerWidth() >= 1178 ) {
        var offset = $(that).offset().top - 200;
      } else {
        var offset = $(that).offset().top - 10;
      }
      $('html, body').animate({
        scrollTop: offset + 'px'
      }, 'fast');
      return this;
    }, 400);

  });

  $(".frame-akkordeon h2").click(function () {

    var that = this;
    setTimeout(function () {

      if ( $(window).outerWidth() >= 1178 ) {
        var offset = $(that).offset().top - 200;
      } else {
        var offset = $(that).offset().top - 10;
      }
      $('html, body').animate({
        scrollTop: offset + 'px'
      }, 'fast');
      return this;
    }, 400);
  });

  $(".frame-akkordeon header").click(function () {

    var that = this;
    setTimeout(function () {
      if ( $(window).outerWidth() >= 1178 ) {
        var offset = $(that).offset().top - 200;
      } else {
        var offset = $(that).offset().top - 10;
      }
      $('html, body').animate({
        scrollTop: offset + 'px'
      }, 'fast');
      return this;
    }, 400);
  });

  if ($(window).outerWidth() >= 1177) {

    setTimeout(function () {

      $(".tx-owl-slider").each(function () {
        if ($(this).find(".owl-item").size() <= 4) {
          $(this).find(".owl-custom-nav").hide();
        } else {
          $(this).find(".owl-custom-nav").show();
        }
      });

    }, 400);
  }
});


$(function () {
  setTimeout(function () {
    $(".owl-wrapper").each(function () {
      var h = 0;
      $(this).find(".iteminner").each(function () {
        if ($(this).height() > h) {
          h = $(this).height();
        }
      });
      console.log(h);
      $(this).find(".iteminner").css("min-height", h + "px");
    });
  });
});

$(function () {
  setTimeout(function () {
    $(".news-messetermine").each(function () {
      var h = 0;
      $(this).find(".box-shadow").each(function () {
        if ($(this).height() > h) {
          h = $(this).height();
        }
      });
      console.log(h);
      $(this).find(".box-shadow").css("min-height", h + "px");
    });
  });
});

$(function () {
  setTimeout(function () {
    $(".produkt-wrapper").each(function () {
      var h = 0;
      $(this).find(".box-shadow").each(function () {
        if ($(this).height() > h) {
          h = $(this).height();
        }
      });
      console.log(h);
      $(this).find(".box-shadow").css("min-height", h + "px");
    });
  });
});

$(function() {
  $(".mfp-link").each(function() {

    //if ($(this).attr("href").indexOf(".mp4") !== undefined) {
    $(this).attr("data-link", $(this).attr("href"));
    $(this).attr("href","");
    //}
  })

    $(".mfp-link").click(function() {

      if ( $(this).attr("data-link").indexOf(".mp4") != -1 ) {
        var src = $(this).attr("data-link");
        var html = '<video class="mfp-iframe" controls=""><source src="' + src + '">Your browser does not support the video tag.</video>'
            $("iframe.mfp-iframe").after(html);
        $("iframe.mfp-iframe").remove();
      } else {
        var src = $(this).attr("data-link");
        var html = '<iframe width="560" height="315" src="'+ src +'" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
            $("iframe.mfp-iframe").after(html);
        $("iframe.mfp-iframe").remove();
      }
    })
      })


$(".level2 > li:has(ul.level3)").hover(function () {
  $(this).children("a").click(function () {
    return false;
    event.returnValue = false; 
  });
});

$( ".level2 > li:has(ul.level3) a").click(function() {
  $(this).next( ".level3" ).slideToggle( "slow", function() {
    $(this).parent().toggleClass('toggled');
  });
  if($(this).parent().hasClass("toggled")){

  }else{
    $(".toggled ul.level3").slideToggle( "slow", function() {
      $(this).parent().toggleClass('toggled');
    });
  }
});


$( ".level2 > li:has(ul.level3)" ).click(function() {
  if($(this).hasClass("toggled")){
  }else{
    $(".toggled ul.level3").slideToggle( "slow", function() {
      $(this).parent().toggleClass('toggled');
    });
  }
});


$( "ul.level1 > li.hassub" ).click(function() {
  if($(this).hasClass("active")){
    $(this).removeClass("active");
  } else {

    $(this).closest("ul.level1").find("li.hassub").removeClass("active");
    $(this).addClass("active");
  }
});

$(window).scroll(function() {
  var scroll = $(window).scrollTop();

  if (scroll >= 100) {
    $("body").addClass("smallheader");
  } else {
    $("body").removeClass("smallheader");
  }
});


$('html').click(function() {
  if($("ul.level1 > li.hassub").hasClass("active")){
    $("ul.level1 > li.hassub").removeClass("active");
  } else {
  }
});

$('#megamenu').click(function(event){
    event.stopPropagation();
});
