`; grid.appendChild(item); }); }); /* ---------- Scroll reveal observer ---------- */ const io = new IntersectionObserver((entries)=>{ entries.forEach(e=>{ if(e.isIntersecting){ e.target.classList.add('in-view'); io.unobserve(e.target); } }); },{threshold:0.12, rootMargin:'0px 0px -60px 0px'}); document.querySelectorAll('.reveal, .reveal-scale').forEach(el=>io.observe(el)); /* ---------- Hover "Halt" Logic to Expand Actual Image ---------- */ let haltTimer = null; const haltLightbox = document.getElementById('haltLightbox'); const haltImg = document.getElementById('haltImg'); // Use event delegation to handle dynamically injected images document.body.addEventListener('mouseenter', (e) => { const item = e.target.closest('.gallery-item'); if(item) { const imgSrc = item.querySelector('img').src; // Start 700ms timer on hover haltTimer = setTimeout(() => { haltImg.src = imgSrc; haltLightbox.classList.add('active'); }, 700); } }, true); document.body.addEventListener('mouseleave', (e) => { const item = e.target.closest('.gallery-item'); if(item) { clearTimeout(haltTimer); haltLightbox.classList.remove('active'); } }, true); /* ---------- Modal control ---------- */ function openModal(){ document.getElementById('modalBackdrop').classList.add('open'); document.body.style.overflow='hidden'; } function closeModal(){ document.getElementById('modalBackdrop').classList.remove('open'); document.body.style.overflow=''; } document.getElementById('modalBackdrop').addEventListener('click',(e)=>{ if(e.target.id==='modalBackdrop') closeModal(); }); /* ---------- Exact Driving Distance Logic for Karsgutti Location ---------- */ // Approximate coordinates for Nagalogidda/Karsgutti area based on location mapping const FARM_LAT = 18.0675; const FARM_LON = 77.4675; // Fallback straight-line function if driving route fails function haversineKm(lat1,lon1,lat2,lon2){ const R=6371; const dLat=(lat2-lat1)*Math.PI/180; const dLon=(lon2-lon1)*Math.PI/180; const a=Math.sin(dLat/2)**2 + Math.cos(lat1*Math.PI/180)*Math.cos(lat2*Math.PI/180)*Math.sin(dLon/2)**2; const c=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a)); return R*c; } async function getAccurateDrivingDistance(lat, lon) { try { // Call Open Source Routing Machine for exact road distance const response = await fetch(`https://router.project-osrm.org/route/v1/driving/${lon},${lat};${FARM_LON},${FARM_LAT}?overview=false`); const data = await response.json(); if(data.routes && data.routes.length > 0) { return (data.routes[0].distance / 1000).toFixed(1); // Convert meters to km } } catch(err) { console.warn("Routing API failed. Using fallback."); } // Fallback if no road route is found return haversineKm(lat, lon, FARM_LAT, FARM_LON).toFixed(1) + " (Air)"; } async function processUnlock(event){ event.preventDefault(); const btn = document.getElementById('submitBtn'); btn.innerHTML = "⏳ Requesting GPS Access…"; btn.disabled = true; if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(handleLocationSuccess, handleLocationError, {enableHighAccuracy:true, timeout:10000}); } else { alert("Geolocation is not supported by your browser. Cannot unlock map."); resetButton(); } } async function handleLocationSuccess(position){ const lat = position.coords.latitude; const lon = position.coords.longitude; let townName = "Unknown Location"; // 1. Get Town Name try{ const response = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lon}`); const data = await response.json(); if(data && data.address){ townName = data.address.city || data.address.town || data.address.village || data.address.county || data.address.state || "User Location Found"; } }catch(err){ townName = `Lat: ${lat.toFixed(2)}, Lon: ${lon.toFixed(2)}`; } // 2. Calculate Exact Road Distance const distanceKm = await getAccurateDrivingDistance(lat, lon); const name = document.getElementById('custName').value; const phone = document.getElementById('custPhone').value; const email = document.getElementById('custEmail').value; const budget = document.getElementById('custBudget').value; const timeline = document.getElementById('custTimeline').value; const text = `*JMKS Royals Farm (Karsgutti) Inquiry*%0A%0A*Name:* ${name}%0A*Phone:* ${phone}%0A*Email:* ${email}%0A*Visitor Location:* ${townName}%0A*Actual Driving Distance:* ${distanceKm} km%0A*Budget:* ${budget}%0A*Timeline:* ${timeline}`; window.open(`https://wa.me/919553522533?text=${text}`, '_blank'); document.getElementById('distanceValue').innerHTML = `${distanceKm}
km away`; document.getElementById('resultBox').classList.add('show'); document.getElementById('inquiryForm').style.display = 'none'; } function handleLocationError(error){ let msg = "Location permission is required to view the map distance."; if(error.code === error.PERMISSION_DENIED){ msg = "Access Denied: You MUST allow location permissions in your browser to view the map route."; } alert(msg); resetButton(); } function resetButton(){ const btn = document.getElementById('submitBtn'); btn.innerHTML = "🔒 Authenticate & Unlock Map"; btn.disabled = false; } /* ---------- Anti-screenshot ---------- */ document.addEventListener('keyup',(e)=>{ if(e.key==='PrintScreen' || e.keyCode===44){ document.body.classList.add('blur-screen'); setTimeout(()=>document.body.classList.remove('blur-screen'),3000); } }); document.addEventListener('keydown',(e)=>{ if((e.metaKey && e.shiftKey) || (e.ctrlKey && e.key==='p')){ document.body.classList.add('blur-screen'); setTimeout(()=>document.body.classList.remove('blur-screen'),3000); } });