// Bike Data const bikes = [ { id: 1, name: "Thunder Beast X1", category: "Sport", price: "$24,999", engine: "1000cc", power: "200 HP", image: "http://static.photos/technology/640x360/101" }, { id: 2, name: "Cruiser Deluxe Pro", category: "Cruiser", price: "$19,999", engine: "1200cc", power: "150 HP", image: "http://static.photos/technology/640x360/102" }, { id: 3, name: "Adventure Rider 500", category: "Adventure", price: "$22,499", engine: "850cc", power: "120 HP", image: "http://static.photos/technology/640x360/103" }, { id: 4, name: "Urban Street Fighter", category: "Street", price: "$16,999", engine: "750cc", power: "110 HP", image: "http://static.photos/technology/640x360/104" }, { id: 5, name: "Electric E-Storm", category: "Electric", price: "$28,999", engine: "Electric", power: "250 HP", image: "http://static.photos/technology/640x360/105" }, { id: 6, name: "Classic Vintage 900", category: "Classic", price: "$18,499", engine: "900cc", power: "95 HP", image: "http://static.photos/technology/640x360/106" } ]; // Initialize Page document.addEventListener('DOMContentLoaded', function() { // Hide loader setTimeout(() => { const loader = document.getElementById('loader'); loader.classList.add('hidden'); setTimeout(() => { loader.style.display = 'none'; }, 500); }, 1500); // Load bikes loadBikes(); // Initialize counters initCounters(); // Setup form submission setupContactForm(); // Setup scroll effects setupScrollEffects(); }); // Load Bikes function loadBikes() { const bikesGrid = document.getElementById('bikesGrid'); bikes.forEach((bike, index) => { const bikeCard = document.createElement('div'); bikeCard.className = 'bike-card bg-primary-800 rounded-xl overflow-hidden shadow-xl hover:shadow-2xl cursor-pointer'; bikeCard.innerHTML = `
${bike.name}
${bike.category}

${bike.name}

${bike.price}
${bike.engine} • ${bike.power}
`; bikesGrid.appendChild(bikeCard); // Animate cards on scroll setTimeout(() => { bikeCard.style.opacity = '0'; bikeCard.style.transform = 'translateY(20px)'; bikeCard.style.transition = 'all 0.5s ease'; setTimeout(() => { bikeCard.style.opacity = '1'; bikeCard.style.transform = 'translateY(0)'; }, 100 * index); }, 100); }); } // View Bike Details function viewBikeDetails(bikeId) { const bike = bikes.find(b => b.id === bikeId); if (bike) { showNotification(`Viewing details for ${bike.name}`); // In a real app, this would navigate to a details page or open a modal } } // Initialize Counter Animation function initCounters() { const counters = document.querySelectorAll('.counter'); const speed = 200; const observerOptions = { threshold: 0.5 }; const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { const counter = entry.target; const target = +counter.getAttribute('data-target'); const increment = target / speed; const updateCounter = () => { const current = +counter.innerText; if (current < target) { counter.innerText = Math.ceil(current + increment); setTimeout(updateCounter, 10); } else { counter.innerText = target; } }; updateCounter(); observer.unobserve(counter); } }); }, observerOptions); counters.forEach(counter => { observer.observe(counter); }); } // Setup Contact Form function setupContactForm() { const form = document.getElementById('contactForm'); if (form) { form.addEventListener('submit', function(e) { e.preventDefault(); // Show success notification showNotification('Message sent successfully! We\'ll get back to you soon.'); // Reset form form.reset(); }); } } // Setup Scroll Effects function setupScrollEffects() { let lastScroll = 0; const navbar = document.querySelector('nav'); window.addEventListener('scroll', () => { const currentScroll = window.pageYOffset; // Add shadow on scroll if (currentScroll > 10) { navbar.classList.add('shadow-lg', 'navbar-scrolled'); } else { navbar.classList.remove('shadow-lg', 'navbar-scrolled'); } lastScroll = currentScroll; }); } // Smooth Scroll to Section function scrollToSection(sectionId) { const section = document.getElementById(sectionId); if (section) { section.scrollIntoView({ behavior: 'smooth', block: 'start' }); } } // Show Notification function showNotification(message) { // Create notification element const notification = document.createElement('div'); notification.className = 'fixed bottom-4 right-4 bg-accent-500 text-white px-6 py-3 rounded-lg shadow-lg z-50 transform translate-y-20 transition-transform duration-300'; notification.textContent = message; document.body.appendChild(notification); // Show notification setTimeout(() => { notification.style.transform = 'translateY(0)'; }, 100); // Hide notification after 3 seconds setTimeout(() => { notification.style.transform = 'translateY(20px)'; setTimeout(() => { document.body.removeChild(notification); }, 300); }, 3000); } // Filter Bikes by Category function filterBikes(category) { const filteredBikes = category === 'all' ? bikes : bikes.filter(bike => bike.category.toLowerCase() === category.toLowerCase()); const bikesGrid = document.getElementById('bikesGrid'); bikesGrid.innerHTML = ''; filteredBikes.forEach((bike, index) => { const bikeCard = document.createElement('div'); bikeCard.className = 'bike-card bg-primary-800 rounded-xl overflow-hidden shadow-xl hover:shadow-2xl cursor-pointer'; bikeCard.innerHTML = `
${bike.name}
${bike.category}

${bike.name}

${bike.price}
${bike.engine} • ${bike.power}
`; bikesGrid.appendChild(bikeCard); }); } // Add to Cart (for future implementation) function addToCart(bikeId) { const bike = bikes.find(b => b.id === bikeId); if (bike) { showNotification(`${bike.name} added to wishlist!`); } } // Search Bikes function searchBikes(query) { const filteredBikes = bikes.filter(bike => bike.name.toLowerCase().includes(query.toLowerCase()) || bike.category.toLowerCase().includes(query.toLowerCase()) ); if (filteredBikes.length === 0) { showNotification('No bikes found matching your search.'); } else { // Update the grid with filtered results const bikesGrid = document.getElementById('bikesGrid'); bikesGrid.innerHTML = ''; filteredBikes.forEach((bike, index) => { // Reuse the bike card creation logic }); } }