/* * 2010 - GData Locator - by Justin Bane */ function calculateDistance(locale, client) { try { var glatlng1 = new GLatLng(locale['lat'], locale['long']); var glatlng2 = new GLatLng(client.latitude, client.longitude); var miledistance = glatlng1.distanceFrom(glatlng2, 3959).toFixed(1); var kmdistance = (miledistance * 1.609344).toFixed(1); return miledistance; } catch (error) { // Do nothing } } /* * Main Executable Code */ var mainNumber = "(877) ITS-VITAL"; // Locations var locArray = new Array("sacramento","berkeley","sf","seattle","boston"); // Locations details var loc = new Array(); loc['sacramento'] = new Array(); loc['sacramento']['lat'] = "38.615772"; loc['sacramento']['long'] = "-121.517334"; loc['sacramento']['phone'] = "(916) 436-8757"; loc['berkeley'] = new Array(); loc['berkeley']['lat'] = "37.900722"; loc['berkeley']['long'] = "-122.312265"; loc['berkeley']['phone'] = "(510) 545-4428"; loc['sf'] = new Array(); loc['sf']['lat'] = "37.758773"; loc['sf']['long'] = "-122.447090"; loc['sf']['phone'] = "(415) 233-4643"; loc['seattle'] = new Array(); loc['seattle']['lat'] = "47.270020"; loc['seattle']['long'] = "-122.488531"; loc['seattle']['phone'] = "(206) 965-9682"; loc['boston'] = new Array(); loc['boston']['lat'] = "42.511488"; loc['boston']['long'] = "-71.035330"; loc['boston']['phone'] = "(781) 587-0191"; // Client location var clientLocation = new Object(); clientLocation.latitude = 34.1321; clientLocation.longitude = -117.8511; if (jQuery.cookie('vnLocation') == null) { var distance = 0; for (var i = 0; i < locArray.length; i++) { var calculatedDistance = calculateDistance(loc["" + locArray[i] + ""], clientLocation); if (distance == 0) { distance = calculatedDistance; } // Set city and closest location variables/cookie if (parseInt(calculatedDistance) <= parseInt(distance)) { distance = calculatedDistance; jQuery.cookie('vnDistance', distance); jQuery.cookie('vnLocation', locArray[i]); } } } /* * Update page items to reflect distance information */ if (parseInt(jQuery.cookie('vnDistance')) < 100) { mainNumber = loc["" + jQuery.cookie('vnLocation') + ""]['phone']; jQuery(document).ready(function($){ jQuery('#phone, #main-phone').html(mainNumber); jQuery('#phone, #main-phone').slideToggle("fast"); jQuery('.locations div.'+ jQuery.cookie('vnLocation')).css("display", "none"); if(jQuery.cookie('vnLocation') == 'berkeley') { jQuery('.locations div.sf').css("display", "none"); } else { jQuery('.locations div.berkeley').css("display", "none"); } jQuery('#featured-location').css("margin-bottom", "20px"); jQuery('#featured-location').css("display", "block"); jQuery('#featured-location #'+ jQuery.cookie('vnLocation')).slideToggle("fast"); }); } else { jQuery(document).ready(function($){ jQuery('#phone, #main-phone').html(mainNumber); jQuery('#phone, #main-phone').slideToggle("fast"); }); }