document.addEventListener('DOMContentLoaded', function() { // Initialize tooltips const tooltipTriggers = document.querySelectorAll('[data-tooltip]'); tooltipTriggers.forEach(trigger => { const tooltip = document.createElement('div'); tooltip.className = 'hidden bg-gray-800 text-white text-xs rounded py-1 px-2 absolute z-50'; tooltip.textContent = trigger.getAttribute('data-tooltip'); document.body.appendChild(tooltip); trigger.addEventListener('mouseenter', () => { const rect = trigger.getBoundingClientRect(); tooltip.style.top = `${rect.top - 30}px`; tooltip.style.left = `${rect.left + rect.width / 2}px`; tooltip.style.transform = 'translateX(-50%)'; tooltip.classList.remove('hidden'); }); trigger.addEventListener('mouseleave', () => { tooltip.classList.add('hidden'); }); }); // Mock visitor counter animation const visitorCounter = document.getElementById('visitor-counter'); if (visitorCounter) { let count = Math.floor(Math.random() * 100) + 50; setInterval(() => { count += Math.floor(Math.random() * 3) - 1; visitorCounter.textContent = count.toLocaleString() + ' Active Visitors'; }, 5000); } // Form submission handling const forms = document.querySelectorAll('form'); forms.forEach(form => { form.addEventListener('submit', function(e) { e.preventDefault(); const submitButton = form.querySelector('button[type="submit"]'); if (submitButton) { const originalText = submitButton.textContent; submitButton.innerHTML = ' Processing...'; feather.replace(); // Simulate API call setTimeout(() => { submitButton.textContent = originalText; // Show success message alert('Form submitted successfully!'); }, 1500); } }); }); // Mobile menu toggle (if exists) const mobileMenuButton = document.getElementById('mobile-menu-button'); const mobileMenu = document.getElementById('mobile-menu'); if (mobileMenuButton && mobileMenu) { mobileMenuButton.addEventListener('click', () => { mobileMenu.classList.toggle('hidden'); }); } // Smooth scrolling for anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function(e) { e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); }); }); // Initialize all feather icons feather.replace(); }); // Debounce function for resize/scroll events function debounce(func, wait = 20, immediate = true) { let timeout; return function() { const context = this, args = arguments; const later = function() { timeout = null; if (!immediate) func.apply(context, args); }; const callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; }