============================================================ */ (function () { "use strict"; function init() { var root = document.querySelector(".tl-commercial"); if (!root) return; /* ---------- AUTO-DETECT WP HEADER HEIGHT ---------- */ var wpHeader = document.querySelector("header") || document.querySelector("#masthead") || document.querySelector(".site-header") || document.querySelector("[class*='header']"); if (wpHeader) { var headerH = wpHeader.offsetHeight || 0; if (headerH > 0) { root.style.setProperty("--tlc-wp-header-height", headerH + "px"); } } /* ---------- HERO CAROUSEL ---------- */ var heroCarousel = document.getElementById("tlc-hero-carousel"); var heroSlides = heroCarousel ? heroCarousel.querySelectorAll(".tlc-hero-slide") : []; var heroDotsWrap = document.getElementById("tlc-hero-dots"); var heroIndex = 0; var heroTimer = null; var videoPlaying = false; function buildDots(container, count, clickFn) { container.innerHTML = ""; for (var i = 0; i < count; i++) { var btn = document.createElement("button"); btn.className = "tlc-dot-btn" + (i === 0 ? " active" : ""); btn.setAttribute("aria-label", "Slide " + (i + 1)); (function (idx) { btn.addEventListener("click", function (e) { e.stopPropagation(); clickFn(idx); }); })(i); container.appendChild(btn); } } function showHeroSlide(idx) { heroIndex = idx; heroSlides.forEach(function (s, i) { s.classList.toggle("active", i === idx); }); var dots = heroDotsWrap.querySelectorAll(".tlc-dot-btn"); dots.forEach(function (d, i) { d.classList.toggle("active", i === idx); }); var hint = heroCarousel.querySelector(".tlc-carousel-hint"); if (hint) hint.style.display = heroSlides[idx].dataset.type === "video" ? "none" : ""; if (heroSlides[idx].dataset.type !== "video") stopHeroVideo(); } function nextHero() { showHeroSlide((heroIndex + 1) % heroSlides.length); } function prevHero() { showHeroSlide((heroIndex - 1 + heroSlides.length) % heroSlides.length); } function startHeroTimer() { stopHeroTimer(); heroTimer = setInterval(function () { if (!videoPlaying && heroSlides[heroIndex].dataset.type !== "video") nextHero(); }, 3000); } function stopHeroTimer() { if (heroTimer) { clearInterval(heroTimer); heroTimer = null; } } function stopHeroVideo() { videoPlaying = false; var videoSlide = heroSlides[0]; if (!videoSlide) return; var iframeWrap = videoSlide.querySelector(".tlc-hero-video-iframe"); var thumb = videoSlide.querySelector(".tlc-video-thumb-wrap"); if (iframeWrap) { iframeWrap.style.display = "none"; var iframe = iframeWrap.querySelector("iframe"); if (iframe) { iframe.src = ""; } } if (thumb) thumb.style.display = ""; } if (heroCarousel && heroSlides.length) { buildDots(heroDotsWrap, heroSlides.length, showHeroSlide); var playBtn = document.getElementById("tlc-hero-play"); if (playBtn) { playBtn.addEventListener("click", function (e) { e.stopPropagation(); videoPlaying = true; stopHeroTimer(); var videoSlide = heroSlides[0]; var iframeWrap = videoSlide.querySelector(".tlc-hero-video-iframe"); var thumb = videoSlide.querySelector(".tlc-video-thumb-wrap"); if (thumb) thumb.style.display = "none"; if (iframeWrap) { iframeWrap.style.display = ""; var iframe = iframeWrap.querySelector("iframe"); if (iframe && iframe.dataset.src) { iframe.src = iframe.dataset.src; } } }); } heroCarousel.addEventListener("click", function () { if (videoPlaying) return; openLightbox("hero", heroIndex); }); startHeroTimer(); } /* ---------- LIGHTBOX (shared) ---------- */ function openLightbox(type, startIdx) { var lb, contentEl, dotsEl, counterEl, items; if (type === "hero") { lb = document.getElementById("tlc-hero-lightbox"); contentEl = document.getElementById("tlc-hero-lb-content"); dotsEl = document.getElementById("tlc-hero-lb-dots"); counterEl = document.getElementById("tlc-hero-lb-counter"); items = []; heroSlides.forEach(function (s) { if (s.dataset.type === "video") { var iframe = s.querySelector("iframe"); if (iframe) items.push({ type: "iframe", src: iframe.dataset.src || iframe.src }); } else { var img = s.querySelector("img"); if (img) items.push({ type: "image", src: img.src, alt: img.alt || "" }); } }); } else { lb = document.getElementById("tlc-gallery-lightbox"); contentEl = document.getElementById("tlc-gallery-lb-content"); dotsEl = document.getElementById("tlc-gallery-lb-dots"); counterEl = document.getElementById("tlc-gallery-lb-counter"); var galleryItemEls = document.querySelectorAll("#tlc-gallery-grid .tlc-gallery-item"); items = []; galleryItemEls.forEach(function (el) { if (el.dataset.type === "video") { items.push({ type: "iframe", src: el.dataset.src }); } else { var img = el.querySelector("img"); if (img) items.push({ type: "image", src: img.src, alt: img.alt || "" }); } }); } if (!items.length) return; var currentIdx = startIdx || 0; lb.classList.add("open"); document.body.style.overflow = "hidden"; function render() { var item = items[currentIdx]; if (item.type === "video" || item.type === "iframe") { contentEl.innerHTML = '