// MASERVICES site interactions document.addEventListener("DOMContentLoaded", () => { // ===== AOS animations ===== if (window.AOS) { AOS.init({ duration: 700, easing: "ease-out-quart", once: true, }); } // ===== Smooth scroll for internal nav links ===== document.querySelectorAll('a[href^="#"]').forEach(link => { link.addEventListener("click", e => { const targetId = link.getAttribute("href"); if (!targetId || !targetId.startsWith("#")) return; const targetEl = document.querySelector(targetId); if (targetEl) { e.preventDefault(); window.scrollTo({ top: targetEl.getBoundingClientRect().top + window.scrollY - 60, behavior: "smooth" }); } }); }); // ===== Animated counters in stats-section (أرقامنا تتكلم) ===== function animateCount(box){ const target = parseInt(box.getAttribute("data-target"),10) || 0; const numberEl = box.querySelector(".count"); if (!numberEl) return; const duration = 1500; const startTime = performance.now(); function tick(now){ const progress = Math.min((now - startTime)/duration,1); const val = Math.floor(progress*target); numberEl.textContent = val.toString(); if (progress < 1){ requestAnimationFrame(tick); } } requestAnimationFrame(tick); } const statBoxes = document.querySelectorAll(".stat-box"); if (statBoxes.length){ const obsOptions = { threshold: 0.3 }; const obs = new IntersectionObserver(entries => { entries.forEach(entry => { if (entry.isIntersecting && !entry.target.dataset.played){ entry.target.dataset.played = "1"; animateCount(entry.target); } }); }, obsOptions); statBoxes.forEach(b => obs.observe(b)); } // ===== Testimonials auto slider ===== const slides = Array.from(document.querySelectorAll(".testi-slide")); const dots = Array.from(document.querySelectorAll(".slider-dots .dot")); let currentSlide = 0; function showSlide(i){ currentSlide = (i + slides.length) % slides.length; slides.forEach((s,idx)=>{ if(idx === currentSlide){ s.classList.add("active"); }else{ s.classList.remove("active"); } }); dots.forEach((d,idx)=>{ if(idx === currentSlide){ d.classList.add("active"); }else{ d.classList.remove("active"); } }); } dots.forEach(d=>{ d.addEventListener("click", ()=>{ const i = parseInt(d.getAttribute("data-slide"),10) || 0; showSlide(i); }); }); if (slides.length > 1){ setInterval(()=>{ showSlide(currentSlide+1); },4000); } // ===== Portfolio Lightbox ===== const lightbox = document.getElementById("lightbox"); const lightboxIframe = document.getElementById("lightbox-iframe"); const lightboxClose = lightbox ? lightbox.querySelector(".lightbox-close") : null; function openLightbox(videoUrl){ if (!lightbox || !lightboxIframe) return; const url = videoUrl.includes("?") ? videoUrl + "&autoplay=1" : videoUrl + "?autoplay=1"; lightboxIframe.setAttribute("src", url); lightbox.classList.add("active"); lightbox.setAttribute("aria-hidden","false"); } function closeLightbox(){ if (!lightbox || !lightboxIframe) return; lightbox.classList.remove("active"); lightbox.setAttribute("aria-hidden","true"); lightboxIframe.setAttribute("src", ""); } document.querySelectorAll(".portfolio-item").forEach(item=>{ item.addEventListener("click", ()=>{ const videoUrl = item.getAttribute("data-video"); if(videoUrl){ openLightbox(videoUrl); } }); }); if(lightboxClose){ lightboxClose.addEventListener("click", closeLightbox); } if(lightbox){ lightbox.addEventListener("click", e=>{ if(e.target === lightbox){ closeLightbox(); } }); } // ===== Countdown timer for Pack إنطلاقة ===== const countdownBox = document.querySelector(".countdown"); if (countdownBox){ const deadline = Date.now() + 7*24*60*60*1000; function updateCountdown(){ const now = Date.now(); let diff = deadline - now; if(diff < 0) diff = 0; const sec = Math.floor(diff/1000)%60; const min = Math.floor(diff/1000/60)%60; const hour = Math.floor(diff/1000/60/60)%24; const day = Math.floor(diff/1000/60/60/24); const dEl = countdownBox.querySelector(".cd-days"); const hEl = countdownBox.querySelector(".cd-hours"); const mEl = countdownBox.querySelector(".cd-mins"); const sEl = countdownBox.querySelector(".cd-secs"); if(dEl) dEl.textContent = String(day).padStart(2,"0"); if(hEl) hEl.textContent = String(hour).padStart(2,"0"); if(mEl) mEl.textContent = String(min).padStart(2,"0"); if(sEl) sEl.textContent = String(sec).padStart(2,"0"); } updateCountdown(); setInterval(updateCountdown,1000); } // ===== FAQ accordion ===== document.querySelectorAll(".faq-question").forEach(btn=>{ btn.addEventListener("click", ()=>{ const item = btn.closest(".faq-item"); const open = item.classList.contains("active"); document.querySelectorAll(".faq-item").forEach(i=>i.classList.remove("active")); if(!open){ item.classList.add("active"); } }); }); // ===== Back to top button ===== const backTopBtn = document.querySelector(".back-to-top"); function toggleBackToTop(){ if(!backTopBtn) return; if(window.scrollY > window.innerHeight * 0.5){ backTopBtn.classList.add("show"); }else{ backTopBtn.classList.remove("show"); } } if(backTopBtn){ window.addEventListener("scroll", toggleBackToTop, {passive:true}); backTopBtn.addEventListener("click", ()=>{ window.scrollTo({top:0,behavior:"smooth"}); }); toggleBackToTop(); } // ===== Lead WhatsApp Popup (delayed once per load) ===== const leadPopup = document.getElementById("leadPopup"); const leadPopupClose = document.getElementById("leadPopupClose"); let leadPopupShown = false; function showLeadPopup(){ if(leadPopupShown) return; leadPopupShown = true; if(leadPopup){ leadPopup.classList.add("active"); leadPopup.setAttribute("aria-hidden","false"); } } function hideLeadPopup(){ if(leadPopup){ leadPopup.classList.remove("active"); leadPopup.setAttribute("aria-hidden","true"); } } // if(leadPopup){ // setTimeout(()=>{ // showLeadPopup(); // }, 9000); // ~9 seconds // } if(leadPopupClose){ leadPopupClose.addEventListener("click", hideLeadPopup); } if(leadPopup){ leadPopup.addEventListener("click", (e)=>{ if(e.target === leadPopup){ hideLeadPopup(); } }); } // ===== Quick Contact Form -> WhatsApp redirect ===== const leadForm = document.getElementById("leadForm"); if(leadForm){ leadForm.addEventListener("submit", (e)=>{ e.preventDefault(); const name = document.getElementById("qc-name")?.value?.trim() || ""; const phone = document.getElementById("qc-phone")?.value?.trim() || ""; const service = document.getElementById("qc-service")?.value || ""; const msg = document.getElementById("qc-message")?.value?.trim() || ""; // Build WhatsApp text let text = "الاسم: " + name + "\n"; text += "الهاتف: " + phone + "\n"; text += "الخدمة: " + service + "\n"; if(msg){ text += "الرسالة: " + msg; } const encoded = encodeURIComponent(text); const url = "https://wa.me/212631008682?text=" + encoded; window.open(url, "_blank"); }); } });