// Prime Escritório Financeiro - JavaScript Principal document.addEventListener('DOMContentLoaded', function() { // Variáveis globais const navbar = document.getElementById('navbar'); const navbarToggler = document.getElementById('navbar-toggler'); const navbarMenu = document.getElementById('navbar-menu'); const navLinks = document.querySelectorAll('.nav-link'); const preloader = document.getElementById('preloader'); const cookieBanner = document.getElementById('cookie-banner'); const acceptCookies = document.getElementById('accept-cookies'); const testimonialsCarousel = document.getElementById('testimonials-carousel'); const testimonialPrev = document.getElementById('testimonial-prev'); const testimonialNext = document.getElementById('testimonial-next'); const testimonialIndicators = document.getElementById('testimonial-indicators'); const formContato = document.getElementById('form-contato'); const formFeedback = document.getElementById('form-feedback'); // Preloader window.addEventListener('load', function() { setTimeout(() => { preloader.style.opacity = '0'; preloader.style.visibility = 'hidden'; setTimeout(() => { preloader.style.display = 'none'; }, 500); }, 500); // Iniciar animações AOS initAOS(); }); // Navbar scroll effect window.addEventListener('scroll', function() { if (window.scrollY > 50) { navbar.classList.add('scrolled'); } else { navbar.classList.remove('scrolled'); } }); // Mobile menu toggle if (navbarToggler) { navbarToggler.addEventListener('click', function() { navbarMenu.classList.toggle('active'); // Animar hamburger const spans = this.querySelectorAll('span'); if (navbarMenu.classList.contains('active')) { spans[0].style.transform = 'rotate(45deg) translateY(8px)'; spans[1].style.opacity = '0'; spans[2].style.transform = 'rotate(-45deg) translateY(-8px)'; } else { spans[0].style.transform = 'none'; spans[1].style.opacity = '1'; spans[2].style.transform = 'none'; } }); } // Smooth scrolling para links de navegação navLinks.forEach(link => { link.addEventListener('click', function(e) { e.preventDefault(); const targetId = this.getAttribute('href'); const targetSection = document.querySelector(targetId); if (targetSection) { const offsetTop = targetSection.offsetTop - 80; window.scrollTo({ top: offsetTop, behavior: 'smooth' }); // Fechar menu mobile navbarMenu.classList.remove('active'); // Resetar hamburger const spans = navbarToggler.querySelectorAll('span'); spans[0].style.transform = 'none'; spans[1].style.opacity = '1'; spans[2].style.transform = 'none'; } }); }); // Atualizar link ativo na navegação window.addEventListener('scroll', function() { let current = ''; const sections = document.querySelectorAll('section'); sections.forEach(section => { const sectionTop = section.offsetTop; const sectionHeight = section.clientHeight; if (scrollY >= (sectionTop - 200)) { current = section.getAttribute('id'); } }); navLinks.forEach(link => { link.classList.remove('active'); if (link.getAttribute('href') === '#' + current) { link.classList.add('active'); } }); }); // Cookie banner if (cookieBanner) { // Verificar se já aceitou cookies if (!localStorage.getItem('cookiesAccepted')) { setTimeout(() => { cookieBanner.classList.add('show'); }, 2000); } if (acceptCookies) { acceptCookies.addEventListener('click', function() { localStorage.setItem('cookiesAccepted', 'true'); cookieBanner.classList.remove('show'); setTimeout(() => { cookieBanner.style.display = 'none'; }, 300); }); } } // Carrossel de depoimentos if (testimonialsCarousel) { const testimonialItems = testimonialsCarousel.querySelectorAll('.testimonial-item'); let currentTestimonial = 0; const totalTestimonials = testimonialItems.length; // Criar indicadores if (testimonialIndicators) { for (let i = 0; i < totalTestimonials; i++) { const indicator = document.createElement('button'); indicator.addEventListener('click', () => goToTestimonial(i)); testimonialIndicators.appendChild(indicator); } updateIndicators(); } // Navegação if (testimonialPrev) { testimonialPrev.addEventListener('click', () => { currentTestimonial = (currentTestimonial - 1 + totalTestimonials) % totalTestimonials; updateCarousel(); }); } if (testimonialNext) { testimonialNext.addEventListener('click', () => { currentTestimonial = (currentTestimonial + 1) % totalTestimonials; updateCarousel(); }); } function goToTestimonial(index) { currentTestimonial = index; updateCarousel(); } function updateCarousel() { testimonialsCarousel.scrollTo({ left: currentTestimonial * testimonialsCarousel.offsetWidth, behavior: 'smooth' }); updateIndicators(); } function updateIndicators() { const indicators = testimonialIndicators.querySelectorAll('button'); indicators.forEach((indicator, index) => { indicator.classList.toggle('active', index === currentTestimonial); }); } // Auto-play setInterval(() => { currentTestimonial = (currentTestimonial + 1) % totalTestimonials; updateCarousel(); }, 5000); // Touch/swipe para mobile let touchStartX = 0; let touchEndX = 0; testimonialsCarousel.addEventListener('touchstart', e => { touchStartX = e.changedTouches[0].screenX; }); testimonialsCarousel.addEventListener('touchend', e => { touchEndX = e.changedTouches[0].screenX; handleSwipe(); }); function handleSwipe() { if (touchEndX < touchStartX - 50) { // Swipe left currentTestimonial = (currentTestimonial + 1) % totalTestimonials; updateCarousel(); } if (touchEndX > touchStartX + 50) { // Swipe right currentTestimonial = (currentTestimonial - 1 + totalTestimonials) % totalTestimonials; updateCarousel(); } } } // Formulário de contato if (formContato) { formContato.addEventListener('submit', function(e) { e.preventDefault(); // Coletar dados do formulário const formData = new FormData(this); // Mostrar loading const submitBtn = this.querySelector('button[type="submit"]'); const originalText = submitBtn.innerHTML; submitBtn.disabled = true; submitBtn.innerHTML = 'Enviando...'; // Fazer requisição AJAX fetch('processar-contato.php', { method: 'POST', body: formData }) .then(response => response.json()) .then(result => { // Mostrar feedback formFeedback.style.display = 'block'; if (result.success) { formFeedback.className = 'alert alert-success'; formFeedback.innerHTML = 'Mensagem enviada com sucesso!
' + (result.message || 'Entraremos em contato em breve.'); // Limpar formulário formContato.reset(); // Rastrear conversão (se tiver Google Analytics) if (typeof gtag !== 'undefined') { gtag('event', 'form_submit', { 'event_category': 'Contact', 'event_label': 'Contact Form' }); } } else { formFeedback.className = 'alert alert-error'; formFeedback.innerHTML = 'Erro ao enviar mensagem
' + (result.message || 'Por favor, tente novamente.'); } // Scroll para feedback formFeedback.scrollIntoView({ behavior: 'smooth', block: 'center' }); // Esconder feedback após 5 segundos setTimeout(() => { formFeedback.style.display = 'none'; }, 5000); }) .catch(error => { console.error('Erro:', error); formFeedback.style.display = 'block'; formFeedback.className = 'alert alert-error'; formFeedback.innerHTML = 'Erro ao enviar mensagem
Por favor, tente novamente ou entre em contato pelo WhatsApp.'; }) .finally(() => { // Restaurar botão submitBtn.disabled = false; submitBtn.innerHTML = originalText; }); }); // Máscara para telefone const telefoneInput = document.getElementById('telefone'); if (telefoneInput) { telefoneInput.addEventListener('input', function(e) { let value = e.target.value.replace(/\D/g, ''); if (value.length <= 11) { value = value.replace(/^(\d{2})(\d{5})(\d{4}).*/, '($1) $2-$3'); } e.target.value = value; }); } } // Animações AOS-like customizadas function initAOS() { const animatedElements = document.querySelectorAll('[data-aos]'); const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('aos-animate'); // Aplicar delay se especificado const delay = entry.target.getAttribute('data-aos-delay'); if (delay) { entry.target.style.transitionDelay = delay + 'ms'; } } }); }, { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }); animatedElements.forEach(element => { observer.observe(element); }); } // Contador de números animado const statNumbers = document.querySelectorAll('.stat-item h3'); let animated = false; function animateNumbers() { if (animated) return; statNumbers.forEach(stat => { const target = parseInt(stat.innerText); const increment = target / 50; let current = 0; const updateNumber = () => { current += increment; if (current < target) { stat.innerText = Math.floor(current) + '+'; requestAnimationFrame(updateNumber); } else { stat.innerText = target + '+'; } }; updateNumber(); }); animated = true; } // Observar seção de estatísticas const heroStats = document.querySelector('.hero-stats'); if (heroStats) { const statsObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { animateNumbers(); } }); }, { threshold: 0.5 }); statsObserver.observe(heroStats); } // Lazy loading para imagens const lazyImages = document.querySelectorAll('img[loading="lazy"]'); if ('IntersectionObserver' in window) { const imageObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { const img = entry.target; img.src = img.src; img.classList.add('loaded'); imageObserver.unobserve(img); } }); }); lazyImages.forEach(img => imageObserver.observe(img)); } // Adicionar classe para fonte dinâmica const fontFamily = document.documentElement.style.getPropertyValue('--font-family'); if (fontFamily) { document.body.style.fontFamily = fontFamily; } // Verificar performance window.addEventListener('load', function() { if ('performance' in window) { const perfData = window.performance.timing; const pageLoadTime = perfData.loadEventEnd - perfData.navigationStart; console.log('Tempo de carregamento da página:', pageLoadTime + 'ms'); } }); // Ajustar altura do viewport para mobile function setViewportHeight() { const vh = window.innerHeight * 0.01; document.documentElement.style.setProperty('--vh', `${vh}px`); } setViewportHeight(); window.addEventListener('resize', setViewportHeight); });