// LoperBoys - Main JS document.addEventListener('DOMContentLoaded', function() { // --- Navbar scroll effect --- const navbar = document.getElementById('navbar'); window.addEventListener('scroll', function() { navbar.classList.toggle('scrolled', window.scrollY > 50); }); // --- Mobile nav toggle --- const navToggle = document.getElementById('navToggle'); const navLinks = document.getElementById('navLinks'); navToggle.addEventListener('click', function() { navToggle.classList.toggle('active'); navLinks.classList.toggle('active'); }); // Close mobile nav on link click navLinks.querySelectorAll('a').forEach(function(link) { link.addEventListener('click', function() { navToggle.classList.remove('active'); navLinks.classList.remove('active'); }); }); // --- Smooth scroll for anchor links --- document.querySelectorAll('a[href^="#"]').forEach(function(anchor) { anchor.addEventListener('click', function(e) { e.preventDefault(); const target = document.querySelector(this.getAttribute('href')); if (target) { target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); }); // --- Floating CTA visibility --- const floatingCta = document.getElementById('floatingCta'); window.addEventListener('scroll', function() { floatingCta.style.opacity = window.scrollY > 400 ? '1' : '0'; floatingCta.style.pointerEvents = window.scrollY > 400 ? 'auto' : 'none'; }); floatingCta.style.opacity = '0'; floatingCta.style.transition = 'opacity 0.3s ease'; // --- Phone number formatting --- const phoneInput = document.getElementById('phone'); if (phoneInput) { phoneInput.addEventListener('input', function(e) { let value = e.target.value.replace(/\D/g, ''); if (value.length >= 6) { value = '(' + value.slice(0,3) + ') ' + value.slice(3,6) + '-' + value.slice(6,10); } else if (value.length >= 3) { value = '(' + value.slice(0,3) + ') ' + value.slice(3,6); } e.target.value = value; }); } // --- Contact form handling --- const contactForm = document.getElementById('contactForm'); if (contactForm) { contactForm.addEventListener('submit', function(e) { e.preventDefault(); const formData = new FormData(contactForm); const data = {}; formData.forEach(function(value, key) { data[key] = value; }); // Send via fetch to PHP endpoint (SMTP relay via hMailserver) fetch('send-contact.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(function(response) { contactForm.innerHTML = '
Thanks for reaching out! We\'ll be in touch soon.
' + 'For urgent inquiries, please call 220-200-4022
' + '