// Fixed top Header
window.addEventListener("DOMContentLoaded", function(){
    let themeworkheader = document.getElementsByClassName('themeworkheader');
    // If class exists
    if (themeworkheader.length > 0) {
        const headerNav = document.querySelector(".navbar");
        const topOfNav = headerNav.offsetHeight;
        window.addEventListener('scroll', function() {
          if (window.scrollY >= topOfNav) {
            // add padding top to show content behind navbar
            document.body.style.paddingTop = headerNav.offsetHeight + 'px';
            headerNav.classList.add("bg-white", "fixed-top");
          } else {
            document.body.style.paddingTop = "";
            headerNav.classList.remove("bg-white", "fixed-top");
          } 
      });
    }
});

// Page scroll to go top
document.addEventListener("DOMContentLoaded", function(){
     let pagescrolltop = document.getElementsByClassName('ct-scroll-top');
    // If class exists
    if (pagescrolltop.length > 0) {
      window.addEventListener('scroll', function() {
          if (window.scrollY > 200) {
            document.getElementById('page-scroll-top').classList.add('on');
           // document.body.style.paddingTop = 22 + 'px';
          } else {
             //  document.body.style.paddingTop = 0;
            document.getElementById('page-scroll-top').classList.remove('on');
          } 
      });
    }
});

// document.addEventListener("DOMContentLoaded", function(){
//   var themeworkheader = document.getElementsByClassName('themeworkheader');
//     // If class exists
//     if (themeworkheader.length > 0) {
//       window.addEventListener('scroll', function() {
//       let scrollpos = window.scrollY;
//       const header = document.querySelector("nav");
//       const header_height = header.offsetHeight;
//       const add_class_on_scroll = () => header.classList.add("bg-light", "fixed-top");
//       const remove_class_on_scroll = () => header.classList.remove("bg-light", "fixed-top");
//       window.addEventListener('scroll', function() { 
//         scrollpos = window.scrollY;
//         if (scrollpos >= header_height) { add_class_on_scroll() }
//         else { remove_class_on_scroll() }
//         })
//       });
//     }
// });

// Bootstrap slider in 3 row
window.addEventListener("DOMContentLoaded", function(){
    let bootstrapSlider = document.getElementsByClassName('carousel');
    // If class exists
    if (bootstrapSlider.length > 0) {
    let items = document.querySelectorAll('.carousel .carousel-item');
    items.forEach((el) => {
        // number of slides per carousel-item
        const minPerSlide = 3;
        let next = el.nextElementSibling;
        for (var i=1; i<minPerSlide; i++) {
            if (!next) {
                // wrap carousel by using first child
                next = items[0];
            }
            let cloneChild = next.cloneNode(true);
            el.appendChild(cloneChild.children[0]);
            next = next.nextElementSibling;
        }
    })
  }
});
// Search button code Start
function openSearch() {
  document.getElementById("myOverlay").style.display = "block";
}
function closeSearch() {
  document.getElementById("myOverlay").style.display = "none";
}
// Search button code End
window.addEventListener("DOMContentLoaded", function(){
      let secondbutton = document.getElementsByClassName('second-button');
    // If class exists
    if (secondbutton.length > 0) {
    document.querySelector('.second-button').addEventListener('click', function () {
            document.querySelector('.animated-icon2').classList.toggle('open');
        });
    }
});