/* ============================ AV Luxury Vacations — Main JS ============================ */ const INTAKE_URL = 'https://secure.foratravel.com/intake/av-luxury-vacations/lFhFPJNAWM'; /* ── Nav HTML factory — must run first so hamburger exists for listeners ── */ function buildNav() { const el = document.getElementById('nav'); if (!el) return; el.innerHTML = ` `; } buildNav(); /* ── Navigation ── */ (function () { const nav = document.getElementById('nav'); if (!nav) return; const hamburger = document.getElementById('hamburger'); const navLinks = document.getElementById('navLinks'); window.addEventListener('scroll', () => { nav.classList.toggle('scrolled', window.scrollY > 40); }, { passive: true }); hamburger?.addEventListener('click', () => { const open = navLinks.classList.toggle('open'); hamburger.classList.toggle('open', open); document.body.style.overflow = open ? 'hidden' : ''; }); navLinks?.querySelectorAll('a').forEach(link => { link.addEventListener('click', () => { navLinks.classList.remove('open'); hamburger?.classList.remove('open'); document.body.style.overflow = ''; }); }); // Mark active page const current = location.pathname.split('/').pop() || 'index.html'; navLinks?.querySelectorAll('a').forEach(a => { const href = a.getAttribute('href')?.split('/').pop(); if (href === current) a.style.color = 'var(--gold)'; }); })(); /* ── Scroll-triggered fade-in ── */ (function () { const els = document.querySelectorAll('.fade-in'); if (!els.length) return; const io = new IntersectionObserver((entries) => { entries.forEach(e => { if (e.isIntersecting) { e.target.classList.add('visible'); io.unobserve(e.target); } }); }, { threshold: 0.12 }); els.forEach(el => io.observe(el)); })(); /* ── FAQ accordion ── */ (function () { document.querySelectorAll('.faq-item').forEach(item => { item.querySelector('.faq-question')?.addEventListener('click', () => { const isOpen = item.classList.contains('open'); document.querySelectorAll('.faq-item.open').forEach(i => i.classList.remove('open')); if (!isOpen) item.classList.add('open'); }); }); })(); /* ── Smooth-scroll anchor links ── */ document.querySelectorAll('a[href^="#"]').forEach(a => { a.addEventListener('click', e => { const target = document.querySelector(a.getAttribute('href')); if (target) { e.preventDefault(); target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); }); /* ── Contact form ── */ (function () { const form = document.getElementById('contactForm'); if (!form) return; form.addEventListener('submit', e => { e.preventDefault(); const btn = form.querySelector('button[type=submit]'); btn.textContent = 'Message Sent ✓'; btn.disabled = true; btn.style.background = '#2d9d78'; setTimeout(() => { btn.textContent = 'Send Message'; btn.disabled = false; btn.style.background = ''; form.reset(); }, 4000); }); })();