// Initialize when DOM is loaded document.addEventListener('DOMContentLoaded', function() { // Initialize animations initScrollAnimations(); // Initialize smooth scrolling initSmoothScroll(); // Initialize contact form initContactForm(); // Initialize theme toggle initThemeToggle(); }); // Scroll animations function initScrollAnimations() { const observerOptions = { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }; const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('animated'); } }); }, observerOptions); // Observe all animated elements document.querySelectorAll('.animate-on-scroll').forEach(el => { observer.observe(el); }); } // Smooth scrolling for anchor links function initSmoothScroll() { 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', block: 'start' }); } }); }); } // Contact form handling function initContactForm() { const form = document.getElementById('contactForm'); if (form) { form.addEventListener('submit', function(e) { e.preventDefault(); // Get form data const formData = new FormData(form); const data = Object.fromEntries(formData); // Show success message showNotification('Thank you for your message! We\'ll get back to you soon.', 'success'); // Reset form form.reset(); }); } } // Theme toggle function initThemeToggle() { const themeToggle = document.getElementById('themeToggle'); if (themeToggle) { themeToggle.addEventListener('click', function() { document.documentElement.classList.toggle('dark'); localStorage.setItem('theme', document.documentElement.classList.contains('dark') ? 'dark' : 'light'); }); } // Load saved theme const savedTheme = localStorage.getItem('theme'); if (savedTheme === 'dark' || (!savedTheme && window.matchMedia('(prefers-color-scheme: dark)').matches)) { document.documentElement.classList.add('dark'); } } // Notification system function showNotification(message, type = 'info') { const notification = document.createElement('div'); notification.className = `fixed bottom-4 right-4 px-6 py-4 rounded-lg shadow-lg transform translate-y-full transition-transform duration-300 z-50`; // Set background color based on type if (type === 'success') { notification.classList.add('bg-green-500', 'text-white'); } else if (type === 'error') { notification.classList.add('bg-red-500', 'text-white'); } else { notification.classList.add('bg-blue-500', 'text-white'); } notification.innerHTML = `