// Intersection Observer for Table of Contents highlighting document.addEventListener('DOMContentLoaded', function() { const sections = document.querySelectorAll('.policy-section'); const tocLinks = document.querySelectorAll('.toc-link'); // Create intersection observer const observerOptions = { root: null, rootMargin: '-20% 0px -80% 0px', // Trigger when section is near top threshold: 0 }; const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { // Remove active class from all links tocLinks.forEach(link => { link.classList.remove('active'); }); // Add active class to current link const activeLink = document.querySelector(`.toc-link[href="#${entry.target.id}"]`); if (activeLink) { activeLink.classList.add('active'); } } }); }, observerOptions); // Observe all sections sections.forEach(section => { observer.observe(section); }); // Smooth scroll for anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const target = document.querySelector(this.getAttribute('href')); if (target) { const headerOffset = 100; const elementPosition = target.getBoundingClientRect().top; const offsetPosition = elementPosition + window.pageYOffset - headerOffset; window.scrollTo({ top: offsetPosition, behavior: 'smooth' }); } }); }); // Update copyright year dynamically const yearElements = document.querySelectorAll('.current-year'); yearElements.forEach(el => { el.textContent = new Date().getFullYear(); }); // Mobile menu toggle (if needed in future) const mobileMenuBtn = document.getElementById('mobile-menu-btn'); const mobileMenu = document.getElementById('mobile-menu'); if (mobileMenuBtn && mobileMenu) { mobileMenuBtn.addEventListener('click', function() { mobileMenu.classList.toggle('hidden'); }); } }); // Print functionality function printPolicy() { window.print(); }