File size: 9,049 Bytes
f2f3fd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
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
});