$(function () {
  $(document).scroll(function () {
    var $nav = $(".navbar");
    var $navbrand = $(".navbar-brand");
    // $nav.toggleClass("scrolled", $(this).scrollTop() > $nav.height());
    $navbrand.toggleClass("scrolled", $(this).scrollTop() > $nav.height());
  });
});

//show up the image to full screen
// function fullScreenImage(element) {
//   document.getElementById("modalImage").src = element.src;
//   document.getElementById("imagePopup").style.display = "block";
// }
const businessImage = document.querySelectorAll(".business_dept");
const serviceImage = document.querySelectorAll(".service_dept");
const exportImage = document.querySelectorAll(".export_dept");
const wholeSaleImage = document.querySelectorAll(".wholesale_dept");
const educationImage = document.querySelectorAll(".edu_dept");
const csrImage = document.querySelectorAll(".csr_dept");

businessImage.forEach((img, idx) => {
  img.addEventListener("click", (e) => setActiveImage(businessImage, idx));
});

serviceImage.forEach((img, idx) => {
  img.addEventListener("click", (e) => setActiveImage(serviceImage, idx));
});
exportImage.forEach((img, idx) => {
  img.addEventListener("click", (e) => setActiveImage(exportImage, idx));
});
wholeSaleImage.forEach((img, idx) => {
  img.addEventListener("click", (e) => setActiveImage(wholeSaleImage, idx));
});

educationImage.forEach((img, idx) => {
  img.addEventListener("click", (e) => setActiveImage(educationImage, idx));
});
csrImage.forEach((img, idx) => {
  img.addEventListener("click", (e) => setActiveImage(csrImage, idx));
});

function setActiveImage(arr, num) {
  arr.forEach((i, idx) => {
    idx === num ? i.classList.add("active") : i.classList.remove("active");
  });
}

var btn = $("#button");

$(window).scroll(function () {
  if ($(window).scrollTop() > 300) {
    btn.addClass("show");
  } else {
    btn.removeClass("show");
  }
});

btn.on("click", function (e) {
  e.preventDefault();
  $("html, body").animate({ scrollTop: 0 }, "300");
});

// function changeLanguage(el, lang) {
//   if (lang === "uk") {
//     if (el.className === "btn") {
//       el.className = "btn active";
//       el.nextElementSibling.className = "btn";
//     } else {
//       el.className = "btn";
//       el.nextElementSibling.className = "btn active";
//     }
//   } else {
//     if (el.className === "btn") {
//       el.className = "btn active";
//       el.previousElementSibling.className = "btn";
//     } else {
//       el.className = "btn";
//       el.previousElementSibling.className = "btn active";
//     }
//   }
// }
