jQuery(document).ready(function ($) {
  //detect webkit
//   if (!$.browser.webkit) {
//     $('.wrapper').html('<p>Sorry! Non webkit users. :(</p>');
// }
// function getOffsetHeight(el) {
//     var hh = 0;
//     if (el) {
//       hh = el.clientHeight;
//       if (el.style.paddingTop != "") {
//         hh += parseInt(el.style.paddingTop);
//       }
//       if (el.style.paddingBottom != "") {
//         hh += parseInt(el.style.paddingBottom);
//       }
//     }
//     return hh;
//   }


// var $innerWidth = window.innerWidth;
// var $innerHeight = window.innerHeight;
// var $galleryHeight = document.getElementById('galeria');



// console.log($innerWidth + 'x' + $innerHeight);
// console.log('wysokość galerii: ' + getOffsetHeight($galleryHeight));
ScrollTrigger.defaults({
    // Defaults are used by all ScrollTriggers
    toggleActions: "restart pause resume pause", // Scoll effect Forward, Leave, Back, Back Leave
    markers: false // Easaly remove markers for production 
  });
  function removeHash() { 
    var scrollV, scrollH, loc = window.location;
    if ("pushState" in history)
        history.pushState("", document.title, loc.pathname + loc.search);
    else {
        scrollV = document.body.scrollTop;
        scrollH = document.body.scrollLeft;
        loc.hash = "";
        document.body.scrollTop = scrollV;
        document.body.scrollLeft = scrollH;
    }
  }


  window.smoothScrollTo = function(target, distance, distanceMobile) {
    var $width = $('body').outerWidth();
    if($width < 760) {
      distance = distanceMobile;
    }
      $('.menu-js, .overlay-js').removeClass('active');
      $('.hamburger-js').removeClass('is-active');
    //   console.log('smoothScrollTo');

      if (target.length) {
          window.scroll({ top: target.offset().top - distance, left: 0, behavior: 'smooth'});
          removeHash();
      }
  }

  window.findIdElement = function(ele){
      target = ele.split('#');
      target = target[1];
      return $('#sekcja-' + target);
  }
  window.findElement = function(ele){
    target = ele.split('#');
    target = target[1];
    return $('#' + target);
}
  $('a').click(function(e) {
      if($(this).attr('href') == '#'){
          e.preventDefault();
      }
  });
  $('a[href*=\\#]:not([href=\\#])').click(function(e) {
      if (location.pathname.replace(/^\//,'').replace(/\/$/, '') == this.pathname.replace(/^\//,'').replace(/\/$/, '') 
          && location.hostname == this.hostname){
          e.preventDefault();
          tempHash = this.hash;
        //   console.log('scroll');
          smoothScrollTo(findElement(tempHash), 100, 100);
      }
  });

// funkcja wywoła się jeśli zmieni się # w linku
function scrollToSectionWithChangePageJQ() {
    let hash = window.location.hash;

    if(!hash) {
        return false;
    }
    // console.log('scrollChange');

    window.location.hash = "";
    setTimeout(function() {
        if (hash !== '') {
            let scrollTo = $(hash).offset().top - 80;
            $('html, body').animate({
                scrollTop: scrollTo
            }, 2000, 'swing', () => {
                let locationHash = window.location.pathname + window.location.search + hash;
                history.pushState(null, null, locationHash);
            });
        }
    }, 600);
    }
    // export { scrollToSectionWithChangePageJQ };


    scrollToSectionWithChangePageJQ(); 


  $(document).on('click', '.menu-js .nav .open', function(e){
      e.preventDefault();
      $(this).closest('li').toggleClass('active');
  })

  
      // var swiper = new Swiper(".swiperNav", {
      //   spaceBetween: 10,
      //   slidesPerView: 6,
      //   freeMode: true,
      //   watchSlidesProgress: true,
      // });
      // var swiper2 = new Swiper(".swiperContainer", {
      //   spaceBetween: 10,
      //   watchSlidesProgress: true,
      //   effect: "flip",
      //   grabCursor: true,
      //   navigation: {
      //     nextEl: ".swiper-button-next",
      //     prevEl: ".swiper-button-prev",
      //   },
      //   thumbs: {
      //     swiper: swiper,
      //   },
      // });

      // if (typeof Chocolat == 'function') { 

      // }



    //   function selectItemAfterEnteringText(formElement, event) {
    //     // console.log(formElement);
    //     //zdarzenie uruchamia się po wpisaniu w polu input/textarea tekstu i nad inputem pojawia się ukryty label 
    //     function setActiveElement(element, formElementLabel){
    //       let activeLabel = element.querySelector(formElementLabel);
    //           // console.log(activeLabel);
    //           if(activeLabel) {
    //             if(element.querySelector('.formItem').value){  
    //               activeLabel.classList.add('active');
    //             } else {
    //                 activeLabel.classList.remove('active');
    //             }
    //           }
    //     }
        
    //     let arrayElements = document.querySelectorAll(formElement);
    //     if(!arrayElements.length) {
    //       return false;   
    //     }
    //     for (let i = 0; i < arrayElements.length; i++) {
    //         arrayElements[i].addEventListener(event, function() {
    //           setActiveElement(this, '.label');
    //         });
    //     }
    //   }
      
    //   // export { selectItemAfterEnteringText };
      
    //   selectItemAfterEnteringText('.formElement', 'keyup'); 

    // /*KONIEC TEST*/



    // AOS.init();

if($('.content__lead').length) {
	document.querySelector('.content__lead').addEventListener("mouseover", openCookies);
	function openCookies() {
        document.querySelector('.content__hiddeninfo').classList.add('open');
        document.querySelector('.cookieInfo').classList.add('open');
        setTimeout(() => {
            document.querySelector('.cookieInfo').classList.add('activeCloseButton');
            
        }, 1000);
	}
}



    function scrollScrollbar() {
        var $emelent = $('.mobileScroll .b-imageFull__content div.image');
        var $image = $emelent.find('.image');
        var $elementWidth = $emelent.width();
        var $imageWidth = $image.width();
        var $scrollCenter = ( $imageWidth - $elementWidth ) / 2;
        // console.log($scrollCenter);
        $emelent.animate({
            scrollLeft: "+="+ $scrollCenter + "px"
          });
    }
    scrollScrollbar();


    $(document).on('click', '.openimage', function(){
        $('.openimagepop').addClass('open');

    })
    $(document).on('click', '.openimagepop .close', function(){
        $('.openimagepop').removeClass('open');

    })

    $(document).on('mouseenter click', '.showpoint', function(){
        var pointId = $(this).attr('data-point');
        $('.image-point').removeClass('show');
        $('#image-point-' + pointId).addClass('show');
    })
    $(document).on('click', '.showpoint', function(){
        var pointId = $(this).attr('data-point');
        // $('.image-point').removeClass('show');
        // $('#image-point-' + pointId).addClass('show');
        var $height = $(window).innerHeight();
        // console.log($height);
        smoothScrollTo(findElement('#image-point-' + pointId), $height / 2, $height / 2);
    })


    
    function centeredContent(container, elementHeight) {
        var $contentCenteredInView = $(container);

        $contentCenteredInView.each(function(index, element) {
            // 'this' refers to the current element in the iteration
            // 'index' is the zero-based index of the element in the collection
            // 'element' is the actual DOM element
            // console.log(index);
            // console.log(element);
            var $contentHeight = $(element).find(elementHeight);
    
            var $height = 0;
            $contentHeight.each(function(index, innerElement) {
                // 'this' refers to the current element in the iteration
                // 'index' is the zero-based index of the element in the collection
                // 'element' is the actual DOM element
                // console.log(index);
                var $elementHeight = $(innerElement).height();
                $height = $height + $elementHeight;
    
            });
            // console.log($height);
            $(element).css('top', 'calc(50% - '+ $height/2+'px');
    
        });
    }
    centeredContent('.contentCenteredInView', '.contentInView');
    $(window).resize(function() {
        centeredContent('.contentCenteredInView', '.contentInView');
    });


    // function animateElement(element, markers, rotateDesktop = 0, rotateMobile = 0, opacityDesktop = 1, opacityMobile = 1, scaleDesktop = 1, scaleMobile = 1, moveXDesktop = 0, moveXMobile = 0, moveYDesktop = 0, moveYMobile = 0) {
    //     var $element = $(element);
        
    //     if(innerWidth > 767) {
      
    //     if($element.length) {
    //         // console.log(ornamentsLoop_3)
    //         gsap.to($element, {  // do dołu z rotacja
    //           scrollTrigger: {
    //             trigger: $element,
    //             start: "top bottom",
    //             end: "",
    //             scrub: true,
    //             // scrub: true,
    //             markers: markers,
    //           }, // start the animation when ".box" enters the viewport (once)
    //           rotation: rotateDesktop,
    //           // rotation: 360,
    //           opacity: opacityDesktop,
    //           scale: scaleDesktop,
    //           x : moveXDesktop,
    //           y : moveYDesktop,
    //           ease: "easeInOut",
    //           duration: 3
    //         });
    //       }
    //     } else {
    //       if($element.length) {
    //         gsap.to($element, {  // do dołu z rotacja
    //           scrollTrigger: {
    //             trigger: $element,
    //             sstart: "top bottom",
    //             end: "",
    //             scrub: true,
    //             // scrub: true,
    //             markers: markers,
    //           }, // start the animation when ".box" enters the viewport (once)
    //           rotation: rotateMobile,
    //           opacity: opacityMobile,
    //           scale: scaleMobile,
    //           x : moveXMobile,
    //           y : moveYMobile,
    //           // rotation: 360,
    //           ease: "easeInOut",
    //           duration: 3
    //         });
    //       }
    //     }
    //   }


    //   animateElement('.ornaments_7.ornament__pumpkin', false, 20, 10, 0.7 ,0.7 ,1.3 , 1,-10,-10 );


  }); //doc ready




      
