// Main JavaScript for MileTruck Project document.addEventListener('DOMContentLoaded', function() { // Initialize components initializeStatsCounter(); initializeFleetGallery(); initializePartnerLogos(); initializeFleetNavigation(); // Add smooth scroll to anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const targetId = this.getAttribute('href'); if (targetId === '#') return; const targetElement = document.querySelector(targetId); if (targetElement) { window.scrollTo({ top: targetElement.offsetTop - 80, behavior: 'smooth' }); } }); }); }); // Stats Counter Animation function initializeStatsCounter() { const statElements = document.querySelectorAll('.stat-counter'); const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { const element = entry.target; const target = parseFloat(element.getAttribute('data-target')); const suffix = element.textContent.includes('مليون') ? ' مليون' : element.textContent.includes('مليار') ? ' مليار' : element.textContent.includes(' ألف') ? ' ألف' : ''; let start = 0; const duration = 2000; // 2 seconds const increment = target / (duration / 16); // 60fps const timer = setInterval(() => { start += increment; if (start >= target) { element.textContent = formatNumber(target) + suffix; clearInterval(timer); } else { element.textContent = formatNumber(Math.floor(start)) + suffix; } }, 16); observer.unobserve(element); } }); }, { threshold: 0.5 }); statElements.forEach(el => observer.observe(el)); } function formatNumber(num) { if (num >= 1000000) { return (num / 1000000).toFixed(1).replace('.0', ''); } return num.toLocaleString('en-US'); } // Fleet Gallery Initialization function initializeFleetGallery() { const fleetData = [ { category: 'traila', type: 'تريلا', name: 'تريلا سطحة محورين', image: 'https://www.shahen-sa.com/assets/images/home/truck-images/traila/flatbed-trailer-2axles.webp', length: 'طول المقطورة حتى 13.5 متر', capacity: 'حمولة قصوى 25 طن' }, { category: 'traila', type: 'تريلا', name: 'تريلا سطحة ثلاث محاور', image: 'https://www.shahen-sa.com/assets/images/home/truck-images/traila/flatbed-trailer-3axles.webp', length: 'طول المقطورة حتى 13.5 متر', capacity: 'حمولة قصوى 30 طن' }, { category: 'traila', type: 'تريلا', name: 'تريلا ستارة', image: 'https://www.shahen-sa.com/assets/images/home/truck-images/traila/curtain-trailer.webp', length: 'طول المقطورة حتى 13.5 متر', capacity: 'حمولة قصوى 25 طن' }, { category: 'traila', type: 'تريلا', name: 'تريلا جوانب عالية', image: 'https://www.shahen-sa.com/assets/images/home/truck-images/traila/high-sided-trailer.webp', length: 'طول المقطورة حتى 15 متر', capacity: 'حمولة قصوى 20 طن' }, { category: 'six', type: 'سقس', name: 'سقس جوانب عالية', image: 'https://www.shahen-sa.com/assets/images/home/truck-images/six/sax-high-sided.webp', length: 'الطول حتى 8 متر', capacity: 'حمولة قصوى 13 طن' }, { category: 'six', type: 'سقس', name: 'سقس ثلاجة', image: 'https://www.shahen-sa.com/assets/images/home/truck-images/six/sax-refrigerated.webp', length: 'الطول حتى 8 متر', capacity: 'حمولة قصوى 10 طن' }, { category: 'lorry', type: 'لوري', name: 'لوري شبك', image: 'https://www.shahen-sa.com/assets/images/home/truck-images/lorry/Lorry-Cage-Truck-7M.webp', length: 'الطول حتى 7.5 متر', capacity: 'حمولة قصوى 8 طن' }, { category: 'lorry', type: 'لوري', name: 'لوري جاف (مغلق)', image: 'https://www.shahen-sa.com/assets/images/home/truck-images/lorry/closed-lorry.webp', length: 'الطول حتى 6.5 متر', capacity: 'حمولة قصوى 6 طن' }, { category: 'dyna', type: 'دينا', name: 'دينا شبك', image: 'https://www.shahen-sa.com/assets/images/home/truck-images/dyna/open-dyna.webp', length: 'الطول حتى 6 متر', capacity: 'حمولة قصوى 4 طن' }, { category: 'pickup', type: 'بكب', name: 'بكب', image: 'https://www.shahen-sa.com/assets/images/home/truck-images/pickup/Pickup-Truck.webp', length: 'الطول حتى 5 متر', capacity: 'حمولة قصوى 2 طن' } ]; const container = document.querySelector('.fleet-container'); function renderFleetItems(filter = 'all') { container.innerHTML = ''; const filteredFleet = filter === 'all' ? fleetData : fleetData.filter(item => item.category === filter); filteredFleet.forEach((item, index) => { const fleetCard = document.createElement('div'); fleetCard.className = `fleet-card bg-white rounded-xl shadow-lg overflow-hidden hover:shadow-xl transition-shadow duration-300`; fleetCard.style.animationDelay = `${index * 100}ms`; fleetCard.innerHTML = `