/* VIVA Tours — site-wide interactions */ (function () { "use strict"; /* Header scroll state */ var header = document.querySelector(".header"); function onScroll() { if (!header) return; if (window.scrollY > 40) header.classList.add("header--scrolled"); else header.classList.remove("header--scrolled"); } window.addEventListener("scroll", onScroll, { passive: true }); onScroll(); /* Mobile nav toggle */ var toggle = document.querySelector(".nav-toggle"); var nav = document.querySelector(".header__nav"); if (toggle && nav) { toggle.addEventListener("click", function () { var open = nav.classList.toggle("is-open"); toggle.classList.toggle("is-open", open); document.body.style.overflow = open ? "hidden" : ""; }); /* Close nav when a link is tapped */ nav.querySelectorAll("a").forEach(function (link) { link.addEventListener("click", function () { nav.classList.remove("is-open"); toggle.classList.remove("is-open"); document.body.style.overflow = ""; }); }); } /* Reveal-on-scroll */ var revealEls = document.querySelectorAll(".reveal"); if ("IntersectionObserver" in window && revealEls.length) { var io = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (entry.isIntersecting) { entry.target.classList.add("is-visible"); io.unobserve(entry.target); } }); }, { threshold: 0.12 }); revealEls.forEach(function (el) { io.observe(el); }); } else { revealEls.forEach(function (el) { el.classList.add("is-visible"); }); } /* FAQ accordion */ document.querySelectorAll(".faq-item__q").forEach(function (q) { q.addEventListener("click", function () { var item = q.closest(".faq-item"); var answer = item.querySelector(".faq-item__a"); var isOpen = item.classList.contains("is-open"); /* close siblings in the same group */ var group = q.closest(".faq-group"); if (group) { group.querySelectorAll(".faq-item.is-open").forEach(function (other) { if (other !== item) { other.classList.remove("is-open"); other.querySelector(".faq-item__a").style.maxHeight = "0px"; } }); } if (isOpen) { item.classList.remove("is-open"); answer.style.maxHeight = "0px"; } else { item.classList.add("is-open"); answer.style.maxHeight = answer.scrollHeight + "px"; } }); }); /* Tour filters (tours.html) */ var chips = document.querySelectorAll(".filter-chip"); var cards = document.querySelectorAll(".tour-card"); var countLabel = document.getElementById("toursCount"); if (chips.length && cards.length) { chips.forEach(function (chip) { chip.addEventListener("click", function () { chips.forEach(function (c) { c.classList.remove("is-active"); }); chip.classList.add("is-active"); var filter = chip.getAttribute("data-filter"); var visible = 0; cards.forEach(function (card) { var tags = (card.getAttribute("data-tags") || "").split(" "); var show = filter === "all" || tags.indexOf(filter) !== -1; card.style.display = show ? "" : "none"; if (show) visible++; }); if (countLabel) countLabel.textContent = visible + " tours"; }); }); } /* Year in footer */ document.querySelectorAll("[data-year]").forEach(function (el) { el.textContent = new Date().getFullYear(); }); })();