document.addEventListener('DOMContentLoaded', function () { var menuButton = document.querySelector('.menu-toggle'); var nav = document.querySelector('.nav'); if (menuButton && nav) menuButton.addEventListener('click', function () { nav.classList.toggle('open'); }); var slides = Array.from(document.querySelectorAll('.slide')); if (slides.length) { var index = slides.findIndex(function (s) { return s.classList.contains('active'); }); if (index < 0) index = 0; function show(next) { slides[index].classList.remove('active'); index = (next + slides.length) % slides.length; slides[index].classList.add('active'); } var prev = document.querySelector('.slide-arrow.left'); var next = document.querySelector('.slide-arrow.right'); if (prev) prev.addEventListener('click', function () { show(index - 1); }); if (next) next.addEventListener('click', function () { show(index + 1); }); setInterval(function () { show(index + 1); }, 6000); } var officeDataEl = document.getElementById('office-data'); if (officeDataEl) { var officeData = JSON.parse(officeDataEl.textContent); var officeLinks = Array.from(document.querySelectorAll('[data-office]')); function selectOffice(id) { var data = officeData[id] || officeData.sydney; officeLinks.forEach(function (a) { a.classList.toggle('active', a.dataset.office === id); }); document.getElementById('office-title').textContent = 'Wind Engineering & Wind Tunnel Testing Specialists - ' + data[0]; document.getElementById('office-copy').textContent = data[1]; document.getElementById('office-phone').textContent = data[2]; document.getElementById('office-phone-link').href = 'tel:' + data[2].replace(/[^+0-9]/g, ''); document.getElementById('office-address').textContent = data[3]; document.getElementById('office-map').href = 'https://maps.google.com/?q=' + encodeURIComponent(data[3]); } officeLinks.forEach(function (a) { a.addEventListener('click', function () { selectOffice(a.dataset.office); }); }); selectOffice((location.hash || '#sydney').slice(1)); } }); // Homepage news carousel: shows three desktop tiles, one mobile tile. document.addEventListener('DOMContentLoaded', function () { var tiles = Array.from(document.querySelectorAll('[data-news-slide]')); var dotsWrap = document.querySelector('.news-dots'); if (!tiles.length || !dotsWrap) return; var current = 0; function visibleCount() { return window.matchMedia('(max-width: 900px)').matches ? 1 : 3; } function pageCount() { return Math.max(1, tiles.length - visibleCount() + 1); } function drawDots() { dotsWrap.innerHTML = ''; for (var i = 0; i < pageCount(); i += 1) { var dot = document.createElement('button'); dot.type = 'button'; dot.className = 'news-dot'; dot.setAttribute('aria-label', 'Show news set ' + (i + 1)); dot.dataset.index = String(i); dot.addEventListener('click', function () { showNews(Number(this.dataset.index)); }); dotsWrap.appendChild(dot); } } function showNews(next) { current = (next + pageCount()) % pageCount(); var count = visibleCount(); tiles.forEach(function (tile, i) { tile.classList.toggle('visible', i >= current && i < current + count); }); Array.from(dotsWrap.children).forEach(function (dot, i) { dot.classList.toggle('active', i === current); }); } var prev = document.querySelector('.news-prev'); var next = document.querySelector('.news-next'); if (prev) prev.addEventListener('click', function () { showNews(current - 1); }); if (next) next.addEventListener('click', function () { showNews(current + 1); }); window.addEventListener('resize', function () { drawDots(); showNews(Math.min(current, pageCount() - 1)); }); drawDots(); showNews(0); });