document.addEventListener('DOMContentLoaded', function() { // Mobile Menu Toggle const mobileMenuButton = document.getElementById('mobile-menu-button'); const mobileMenu = document.getElementById('mobile-menu'); mobileMenuButton.addEventListener('click', function() { mobileMenu.classList.toggle('hidden'); }); // Before/After Slider function initSliders() { const sliders = document.querySelectorAll('.before-after-container'); sliders.forEach(slider => { const beforeImage = slider.querySelector('.before-image'); const handle = slider.querySelector('.slider-handle'); let isDragging = false; let startX = 0; let startWidth = 0; function moveSlider(e) { if(!isDragging) return; let x; if(e.type === 'mousemove') { x = e.clientX - slider.getBoundingClientRect().left; } else if(e.type === 'touchmove') { x = e.touches[0].clientX - slider.getBoundingClientRect().left; } const deltaX = x - startX; const newWidth = startWidth + (deltaX / slider.offsetWidth) * 100; const percentage = Math.max(0, Math.min(100, newWidth)); beforeImage.style.width = percentage + '%'; handle.style.left = percentage + '%'; } function startDrag(e) { isDragging = true; if(e.type === 'mousedown') { startX = e.clientX; } else if(e.type === 'touchstart') { startX = e.touches[0].clientX; } startWidth = parseFloat(beforeImage.style.width) || 50; slider.style.userSelect = 'none'; } function stopDrag() { isDragging = false; slider.style.userSelect = ''; } // Mouse events handle.addEventListener('mousedown', startDrag); document.addEventListener('mouseup', stopDrag); document.addEventListener('mousemove', moveSlider); // Touch events handle.addEventListener('touchstart', startDrag, { passive: true }); document.addEventListener('touchend', stopDrag); document.addEventListener('touchmove', moveSlider, { passive: false }); // Click/tap to move slider.addEventListener('click', function(e) { const x = e.clientX - slider.getBoundingClientRect().left; const percentage = (x / slider.offsetWidth) * 100; beforeImage.style.width = percentage + '%'; handle.style.left = percentage + '%'; }); }); } // FAQ Accordion function initFAQ() { const faqItems = document.querySelectorAll('.faq-item'); faqItems.forEach(item => { const header = item.querySelector('.flex.justify-between.items-center'); const content = item.querySelector('.hidden'); const icon = header.querySelector('i'); header.addEventListener('click', function() { const isOpen = content.classList.contains('hidden'); // Close all other items faqItems.forEach(otherItem => { if(otherItem !== item) { otherItem.querySelector('.hidden').classList.add('hidden'); otherItem.querySelector('i').classList.remove('fa-chevron-up'); otherItem.querySelector('i').classList.add('fa-chevron-down'); } }); // Toggle current item if(isOpen) { content.classList.remove('hidden'); icon.classList.remove('fa-chevron-down'); icon.classList.add('fa-chevron-up'); } else { content.classList.add('hidden'); icon.classList.remove('fa-chevron-up'); icon.classList.add('fa-chevron-down'); } }); }); } // Smooth scrolling for navigation function initSmoothScrolling() { document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const target = document.querySelector(this.getAttribute('href')); if(target) { target.scrollIntoView({ behavior: 'smooth' }); // Close mobile menu if open mobileMenu.classList.add('hidden'); } }); }); } // Back to Top Button function initBackToTop() { const backToTopButton = document.getElementById('back-to-top'); window.addEventListener('scroll', function() { if(window.pageYOffset > 300) { backToTopButton.classList.remove('opacity-0', 'invisible'); backToTopButton.classList.add('opacity-100', 'visible'); } else { backToTopButton.classList.add('opacity-0', 'invisible'); backToTopButton.classList.remove('opacity-100', 'visible'); } }); backToTopButton.addEventListener('click', function() { window.scrollTo({ top: 0, behavior: 'smooth' }); }); } // Form Submission function initContactForm() { const contactForm = document.getElementById('contact-form'); if(contactForm) { contactForm.addEventListener('submit', function(e) { e.preventDefault(); const submitText = document.getElementById('submit-text'); const submitSpinner = document.getElementById('submit-spinner'); submitText.classList.add('hidden'); submitSpinner.classList.remove('hidden'); // Simulate form submission (replace with actual AJAX call) setTimeout(() => { submitText.classList.remove('hidden'); submitSpinner.classList.add('hidden'); // Show success message alert('Mensagem enviada com sucesso! Entraremos em contato em breve.'); contactForm.reset(); }, 1500); }); } } // Set current year in footer function setCurrentYear() { document.getElementById('current-year').textContent = new Date().getFullYear(); } // Lazy load images function lazyLoadImages() { const lazyImages = [].slice.call(document.querySelectorAll('img[loading="lazy"]')); if('IntersectionObserver' in window) { const lazyImageObserver = new IntersectionObserver(function(entries, observer) { entries.forEach(function(entry) { if(entry.isIntersecting) { const lazyImage = entry.target; lazyImage.src = lazyImage.dataset.src || lazyImage.src; lazyImageObserver.unobserve(lazyImage); } }); }); lazyImages.forEach(function(lazyImage) { lazyImageObserver.observe(lazyImage); }); } } // Initialize all functions initSliders(); initFAQ(); initSmoothScrolling(); initBackToTop(); initContactForm(); setCurrentYear(); lazyLoadImages(); // Add animation classes when elements come into view const animateOnScroll = function() { const elements = document.querySelectorAll('.animate-fade-in, .animate-slide-up'); elements.forEach(element => { const elementPosition = element.getBoundingClientRect().top; const windowHeight = window.innerHeight; if(elementPosition < windowHeight - 100) { element.style.opacity = '1'; element.style.transform = 'translateY(0)'; } }); }; window.addEventListener('scroll', animateOnScroll); animateOnScroll(); // Run once on page load });