function GoogleGCGetLatLng(n,t){g_Geocoder==null&&(g_Geocoder=new google.maps.Geocoder),g_Geocoder.geocode({address:n},t)}function _InitialiseMarkersMap(t,i){var f=new google.maps.LatLngBounds,u=new Array(i.length),e=i.length>0?new google.maps.LatLng(i[0].position.lat(),i[0].position.lng()):new google.maps.LatLng(0,0),o={zoom:15,center:e,mapTypeId:google.maps.MapTypeId.ROADMAP},r=new google.maps.Map(t,o);for(g_GMap=r,infowindow=new google.maps.InfoWindow({content:"temp",maxWidth:350}),n=0;n<i.length;n++)u[n]=new google.maps.Marker({position:new google.maps.LatLng(i[n].position.lat(),i[n].position.lng()),map:r,title:i[n].title,content:i[n].content,UID:i[n].UID}),google.maps.event.addListener(u[n],"click",function(){infowindow.setContent('<div class="MapInfoWindowContent">'+this.content+"</div>"),infowindow.open(r,this)}),f.extend(u[n].position);return i.length>1?r.fitBounds(f):r.setZoom(11),u}function InitialiseHomePickupAreaMap(n,t,i,r,u){var e;if(t!=null&&i!=null&&r!=null&&u!=null){var o=new google.maps.LatLngBounds(new google.maps.LatLng(t.lat,t.lng),new google.maps.LatLng(i.lat,i.lng)),s={zoom:11,center:new google.maps.LatLng(r.lat,r.lng),mapTypeId:google.maps.MapTypeId.ROADMAP,layout:"fit"},f=new google.maps.Map(n,s);return g_GMap=f,u!=""&&(g_HomePickupAreaOverlay=new google.maps.GroundOverlay(u,o),g_HomePickupAreaOverlay.setMap(f)),e=new google.maps.LatLngBounds,e.extend(new google.maps.LatLng(t.lat,t.lng)),e.extend(new google.maps.LatLng(i.lat,i.lng)),f.fitBounds(e),f}jQuery(n).hide()}function FindNearestPoints(n,t,r){if(r.length==0)return null;var e,u=new Array(0),f=new Array(0);for(j=0;j<r.length;j++)r[j].Dist=GetDistanceBetweenLatLng(r[j].position.lat(),r[j].position.lng(),n.lat(),n.lng()),u.push(r[j]);for(u.sort(_FindNearestPoints_SortFunc),e=t<u.length?t:u.length,i=0;i<e;i++)f.push(u[i]);return f}function _FindNearestPoints_SortFunc(n,t){return n.Dist-t.Dist}function GetDistanceBetweenLatLng(n,t,i,r){var h=6371,e=(i-n).toRad(),u=(r-t).toRad(),c=n.toRad(),l=i.toRad(),f=Math.sin(e/2)*Math.sin(e/2)+Math.sin(u/2)*Math.sin(u/2)*Math.cos(c)*Math.cos(l),o=2*Math.atan2(Math.sqrt(f),Math.sqrt(1-f));return h*o}function InitialiseGoogleMarkersMap(t){if(filtermapmarkers=t,g_arrMarkers.length>0?(g_arrMarkers=_InitialiseMarkersMap(document.getElementById("MarkersMapCanvas"),g_arrMarkers),g_GMap=g_arrMarkers[0].map):(jQuery("#MarkersMapCanvas").hide(),t=!1),t){for(n=0;n<g_arrMarkers.length;n++)g_arrMarkers[n].setVisible(!1);jQuery(".MapTableHeaderDistance, .MapTableDistance").show(),jQuery("#FilterContainer").show(),jQuery("tr.MapItem").show(),jQuery("#MapTable").hide(),google.maps.event.addListener(g_GMap,"click",function(){}),jQuery("#GoogleMarkersMapFilterTerm").bind("keypress",function(n){n.keyCode==13&&FilterNearestMapMarkersBySearchTerm(jQuery("#GoogleMarkersMapFilterTerm").val())})}else{g_arrMarkers.length==1&&(g_IDLE_INITAL_LOAD_LISTENER=google.maps.event.addListener(g_arrMarkers[0].map,"idle",function(){google.maps.event.trigger(g_arrMarkers[0],"click"),google.maps.event.removeListener(g_IDLE_INITAL_LOAD_LISTENER)})),jQuery("#FilterContainer").hide(),jQuery("#MapTable").show();var i=0;jQuery('#MapTable tbody tr[display!="none"]').each(function(){i%2==1&&jQuery(this).addClass("MapItemAlt"),++i})}g_arrMarkers.length>0&&jQuery("#MarkersMapCanvas").show()}function FilterNearestMapMarkersBySearchTerm(n){GoogleGCGetLatLng(n,function(n,t){t==google.maps.GeocoderStatus.OK?(jQuery("#GoogleMarkersMapFilterTerm_Error").hide(),FilterNearestMapMarkersByLatLng(n[0].geometry.location)):jQuery("#GoogleMarkersMapFilterTerm_Error").show()})}function FilterNearestMapMarkersByLatLng(n,t){var e=new google.maps.LatLngBounds,r,o=0,u,f;for(i=0;i<g_arrMarkers.length;i++)g_arrMarkers[i].setVisible(!1),u=jQuery("#MapMarker_"+g_arrMarkers[i].UID.toString()),u.removeClass("MapItemAlt"),u.detach(),u.appendTo("#MarkerMap_BufferTable");for(jQuery('[id^="MapMarker_"]').hide(),f=FindNearestPoints(n,10,g_arrMarkers),x=0;x<f.length;x++)for(y=0;y<g_arrMarkers.length;y++)f[x].UID==g_arrMarkers[y].UID&&(g_arrMarkers[y].setVisible(!0),r=jQuery("#MapMarker_"+g_arrMarkers[y].UID,jQuery("#MarkerMap_BufferTable")),r.detach().appendTo("#MapTable"),r.show(),x%2==1&&r.addClass("MapItemAlt"),jQuery("#DistanceContainer",r).text(metricunits?g_arrMarkers[y].Dist.toFixed(1)+" Km":(g_arrMarkers[y].Dist/1.61).toFixed(1)+" mi"),e.extend(g_arrMarkers[y].position));g_YouAreHereMarker!=null&&g_YouAreHereMarker.setMap(null),t!=null&&(g_YouAreHereMarker=new google.maps.Marker({position:new google.maps.LatLng(n.lat(),n.lng()),map:g_GMap,title:t,content:t}),g_YouAreHereInfoWindow=new google.maps.InfoWindow({content:'<div class="MapInfoWindowContent">'+t+"</div>",maxWidth:350}),g_YouAreHereInfoWindow.open(g_GMap,g_YouAreHereMarker)),jQuery("#MapTable").show(),e.extend(n),g_arrMarkers[0].map.fitBounds(e)}var g_GMap=null,g_Geocoder=null,infowindow=null,g_YouAreHereInfoWindow=null,g_YouAreHereMarker=null,filtermapmarkers=null,g_HomePickupAreaOverlay,g_IDLE_INITAL_LOAD_LISTENER;typeof Number.prototype.toRad=="undefined"&&(Number.prototype.toRad=function(){return this*Math.PI/180}),g_HomePickupAreaOverlay=null,g_IDLE_INITAL_LOAD_LISTENER=null