File size: 11,516 Bytes
a2f906c
f621bf2
 
 
 
 
 
a2f906c
f621bf2
f30b63a
 
 
f621bf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a2f906c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f621bf2
a2f906c
 
f621bf2
 
 
 
 
 
 
 
a2f906c
 
f621bf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fedcbcb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f621bf2
 
 
 
 
fedcbcb
 
 
 
 
 
f621bf2
 
 
a2f906c
fedcbcb
 
 
a2f906c
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337

// AdsScalePro - Interactive Functionality

// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
    initializeCounters();
    initializeAnimations();
    initializeFormHandling();
});
document.addEventListener("DOMContentLoaded", () => {
  feather.replace();
});

// Counter Animation
function initializeCounters() {
    const counters = document.querySelectorAll('.counter');
    
    const animateCounter = (counter) => {
        const target = parseFloat(counter.getAttribute('data-target'));
        const decimals = parseInt(counter.getAttribute('data-decimals')) || 0;
        const duration = 2000; // 2 seconds
        const start = performance.now();
        
        function updateCounter(currentTime) {
            const elapsed = currentTime - start;
            const progress = Math.min(elapsed / duration, 1);
            
            // Easing function for smooth animation
            const easeOutCubic = 1 - Math.pow(1 - progress, 3);
            const current = target * easeOutCubic;
            
            counter.textContent = current.toFixed(decimals);
            
            if (progress < 1) {
                requestAnimationFrame(updateCounter);
            } else {
                counter.textContent = target.toFixed(decimals);
            }
        }
        
        requestAnimationFrame(updateCounter);
    };
    
    // Create intersection observer for counters
    const counterObserver = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting && !entry.target.classList.contains('animated')) {
                entry.target.classList.add('animated');
                animateCounter(entry.target);
            }
        });
    }, {
        threshold: 0.5
    });
    
    counters.forEach(counter => {
        counterObserver.observe(counter);
    });
}

// Initialize animations and interactions
function initializeAnimations() {
    // Card hover effects (enhance CSS with JS)
    const cards = document.querySelectorAll('.card-hover');
    cards.forEach(card => {
        card.addEventListener('mouseenter', function() {
            this.style.transform = 'translateY(-8px) scale(1.02)';
        });
        
        card.addEventListener('mouseleave', function() {
            this.style.transform = 'translateY(0) scale(1)';
        });
    });
    
    // Add stagger effect to service cards
    const serviceCards = document.querySelectorAll('#services .glass');
    serviceCards.forEach((card, index) => {
        card.style.opacity = '0';
        card.style.transform = 'translateY(30px)';
        card.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
        
        // Animate in when scrolled to
        const observer = new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    setTimeout(() => {
                        entry.target.style.opacity = '1';
                        entry.target.style.transform = 'translateY(0)';
                    }, index * 100);
                }
            });
        }, { threshold: 0.1 });
        
        observer.observe(card);
    });
    
    // Progress bars animation
    const progressBars = document.querySelectorAll('.progress > span');
    progressBars.forEach(bar => {
        const observer = new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    setTimeout(() => {
                        const value = bar.style.getPropertyValue('--value');
                        bar.style.width = value;
                    }, 500);
                }
            });
        }, { threshold: 0.5 });
        
        observer.observe(bar);
    });
}

// Form handling
function initializeFormHandling() {
    const contactForm = document.querySelector('#contact form');
    
    if (contactForm) {
        contactForm.addEventListener('submit', function(e) {
            e.preventDefault();
            
            // Get form data
            const formData = new FormData(this);
            const formObject = {};
            formData.forEach((value, key) => {
                formObject[key] = value;
            });
            
            // Add visual feedback
            const submitButton = this.querySelector('button[type="submit"]');
            const originalText = submitButton.innerHTML;
            
            submitButton.innerHTML = '<i data-feather="send"></i> Sending...';
            submitButton.disabled = true;
            
            // Simulate form submission (replace with actual form handling)
            setTimeout(() => {
                submitButton.innerHTML = '<i data-feather="check"></i> Message sent!';
                submitButton.style.background = 'linear-gradient(135deg, #10b981 0%, #059669 100%)';
                
                // Re-initialize feather icons
                if (typeof feather !== 'undefined') {
                    feather.replace();
                }
                
                // Reset form after 2 seconds
                setTimeout(() => {
                    this.reset();
                    submitButton.innerHTML = originalText;
                    submitButton.style.background = '';
                    submitButton.disabled = false;
                    
                    if (typeof feather !== 'undefined') {
                        feather.replace();
                    }
                }, 2000);
            }, 1500);
        });
    }
}

// Button click tracking and interactions (excluding navbar buttons)
document.addEventListener('click', function(e) {
    // Handle CTA button clicks (excluding navbar)
    if (e.target.closest('.btn-primary') && !e.target.closest('header')) {
        // Add visual feedback
        const button = e.target.closest('.btn');
        button.style.transform = 'scale(0.95)';
        setTimeout(() => {
            button.style.transform = 'scale(1)';
        }, 150);
    }
    
    // Handle external links (excluding navbar and footer)
    if (e.target.closest('a[target="_blank"]') && !e.target.closest('header') && !e.target.closest('footer')) {
        const link = e.target.closest('a');
        // Add subtle animation
        link.style.transform = 'translateY(-2px)';
        setTimeout(() => {
            link.style.transform = 'translateY(0)';
        }, 200);
    }
});

// Lazy loading for images (if any are added later)
function initializeLazyLoading() {
    const images = document.querySelectorAll('img[data-src]');
    
    const imageObserver = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                const img = entry.target;
                img.src = img.dataset.src;
                img.classList.remove('lazy');
                imageObserver.unobserve(img);
            }
        });
    });
    
    images.forEach(img => imageObserver.observe(img));
}

// Performance optimization: Throttle scroll events
function throttle(func, limit) {
    let inThrottle;
    return function() {
        const args = arguments;
        const context = this;
        if (!inThrottle) {
            func.apply(context, args);
            inThrottle = true;
            setTimeout(() => inThrottle = false, limit);
        }
    }
}
// Apply throttling to scroll events
const throttledScrollHandler = throttle(function() {
    // Any scroll-based animations can be added here
}, 100);

window.addEventListener('scroll', throttledScrollHandler);

// Infinite Reviews Scroll Animation
function initializeInfiniteReviewsScroll() {
    const marqueeTrack = document.querySelector('.marquee-track');
    
    if (!marqueeTrack) return;
    
    // Create a more robust infinite scroll by cloning content
    const originalContent = marqueeTrack.innerHTML;
    marqueeTrack.innerHTML = originalContent + originalContent; // Duplicate content
    
    let scrollPosition = 0;
    const scrollSpeed = 0.5; // pixels per frame
    let isScrolling = true;
    
    function animateScroll() {
        if (isScrolling) {
            scrollPosition -= scrollSpeed;
            
            // Reset when we've scrolled through one complete set
            if (Math.abs(scrollPosition) >= marqueeTrack.scrollWidth / 2) {
                scrollPosition = 0;
            }
            
            marqueeTrack.style.transform = `translateX(${scrollPosition}px)`;
        }
        
        requestAnimationFrame(animateScroll);
    }
    
    // Pause on hover
    marqueeTrack.addEventListener('mouseenter', () => {
        isScrolling = false;
    });
    
    marqueeTrack.addEventListener('mouseleave', () => {
        isScrolling = true;
    });
    
    // Handle visibility change (pause when tab is not active)
    document.addEventListener('visibilitychange', () => {
        isScrolling = !document.hidden;
    });
    
    // Respect reduced motion preference
    if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
        requestAnimationFrame(animateScroll);
    }
}

// Enhanced scroll-to-top with smooth reveal
function initializeScrollToTopEnhanced() {
    // Create scroll to top button if not exists
    if (!document.querySelector('.scroll-to-top')) {
        const scrollButton = document.createElement('button');
        scrollButton.className = 'scroll-to-top fixed bottom-6 right-6 z-40 btn btn-primary rounded-full h-12 w-12 opacity-0 pointer-events-none transition-all duration-300 shadow-glow';
        scrollButton.innerHTML = '<i data-feather="arrow-up"></i>';
        scrollButton.setAttribute('aria-label', 'Scroll to top');
        
        document.body.appendChild(scrollButton);
        
        // Show/hide scroll to top button
        const toggleScrollButton = () => {
            if (window.pageYOffset > 300) {
                scrollButton.style.opacity = '1';
                scrollButton.style.pointerEvents = 'auto';
                scrollButton.style.transform = 'scale(1)';
            } else {
                scrollButton.style.opacity = '0';
                scrollButton.style.pointerEvents = 'none';
                scrollButton.style.transform = 'scale(0.8)';
            }
        };
        
        window.addEventListener('scroll', throttle(toggleScrollButton, 100));
        
        // Scroll to top on click
        scrollButton.addEventListener('click', function() {
            this.style.transform = 'scale(0.9)';
            setTimeout(() => {
                window.scrollTo({
                    top: 0,
                    behavior: 'smooth'
                });
                this.style.transform = 'scale(1)';
            }, 100);
        });
        
        // Re-initialize feather icons
        if (typeof feather !== 'undefined') {
            feather.replace();
        }
    }
}

// Add CSS class for reduced motion preference
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
    document.body.classList.add('reduce-motion');
}

// Initialize additional features
document.addEventListener('DOMContentLoaded', function() {
    initializeInfiniteReviewsScroll();
    initializeScrollToTopEnhanced();
});

// Export functions for potential external use
window.AdsScalePro = {
    initializeCounters,
    initializeAnimations,
    initializeFormHandling,
    initializeInfiniteReviewsScroll,
    initializeScrollToTopEnhanced
};