window.FlexibleMap=function(){let s,l,t,i,r,o,e=!1;this.getMap=function(){return s},this.getCenter=function(){return l},this.setCenter=function(e){l=e,s.setCenter(l)},this.setMarkerLocation=function(e){t=e},this.getMarkerLocation=function(){return t},this.setMarkerPoint=function(e){i=e},this.getMarkerPoint=function(){return i},this.setMarkerInfowin=function(e){r=e},this.getMarkerInfowin=function(){return r},this.getKmlLayer=function(){return o},this.redrawOnce=function(){e||(e=!0,this.redraw())},this.showMap=function(e,t){l=new google.maps.LatLng(t[0],t[1]);t={small:google.maps.ZoomControlStyle.SMALL,large:google.maps.ZoomControlStyle.LARGE,default:google.maps.ZoomControlStyle.DEFAULT};let i=t.small;this.zoomControlStyle in t&&(i=t[this.zoomControlStyle]);var r,o,n,a,t={mapTypeId:this.mapTypeId,mapTypeControl:this.mapTypeControl,scaleControl:this.scaleControl,panControl:this.panControl,streetViewControl:this.streetViewControl,zoomControl:this.zoomControl,zoomControlOptions:{style:i},fullscreenControl:this.fullscreen,center:l,zoom:this.zoom};return r=t,void 0!==(o=this).gestureHandling?r.gestureHandling=o.gestureHandling:void 0===o.draggable&&void 0===o.dblclickZoom&&void 0===o.scrollwheel?r.gestureHandling="cooperative":(n=void 0===o.draggable||o.draggable,a=void 0!==o.dblclickZoom&&!o.draggable,o=void 0!==o.scrollwheel&&o.scrollwheel,n||!a||o?n&&!a&&o?r.gestureHandling="greedy":(r.draggable=n,r.disableDoubleClickZoom=a,r.scrollwheel=o):r.gestureHandling="none"),t=r,this.mapTypeIds&&(t.mapTypeControlOptions={mapTypeIds:this.mapTypeIds.split(",")}),s=new google.maps.Map(document.getElementById(e),t),this.mapTypeId in this.mapTypes&&s.mapTypes.set(this.mapTypeId,this.mapTypes[this.mapTypeId]._styled_map),s},this.loadKmlMap=function(e){let t=this;e={map:s,url:e};return this.kmlCentre&&(e.preserveViewport=!0,e.center=new google.maps.LatLng(this.kmlCentre[0],this.kmlCentre[1])),o=new google.maps.KmlLayer(e),google.maps.event.addListenerOnce(o,"defaultviewport_changed",this.kmlCentre?function(){t.zoom||s.fitBounds(o.getDefaultViewport()),t.setCenter(new google.maps.LatLng(t.kmlCentre[0],t.kmlCentre[1]))}:function(){l=o.getDefaultViewport().getCenter()}),o},!this.localised&&"flxmap"in window&&this.localise(),this.mapTypeId=google.maps.MapTypeId.ROADMAP,this.mapTypeControl=!0,this.scaleControl=!1,this.panControl=!1,this.zoomControl=!0,this.zoomControlStyle="small",this.streetViewControl=!1,this.fullscreen=!0,this.gestureHandling=void 0,this.scrollwheel=void 0,this.draggable=void 0,this.dblclickZoom=void 0,this.zoom=16,this.markerTitle="",this.markerDescription="",this.markerHTML="",this.markerLink="",this.markerLinkTarget="",this.markerLinkText=!1,this.markerIcon="",this.markerShowInfo=!0,this.markerAnimation="drop",this.markerDirections=!1,this.markerDirectionsShow=!1,this.markerDirectionsDefault="",this.markerAddress="",this.targetFix=!0,this.dirService=!1,this.dirRenderer=!1,this.dirDraggable=!1,this.dirSuppressMarkers=!1,this.dirShowSteps=!0,this.dirShowSearch=!0,this.dirTravelMode="driving",this.dirUnitSystem=void 0,this.region="",this.locale="en",this.localeActive=!1,this.kmlCentre=!1,this.kmlcache="none"},FlexibleMap.prototype=(()=>{function m(e){e.stopPropagation(),e.preventDefault()}let c="undefined"==typeof MutationObserver?()=>{}:(i,e)=>{let r=document.getElementById(e).parentNode;function o(e){e=window.getComputedStyle(e);return"none"===e.display||"hidden"===e.visibility}o(r)&&new MutationObserver(function(e,t){o(r)||(i.redrawOnce(),t.disconnect())}).observe(r,{attributes:!0,attributeFilter:["style"]})};return{constructor:FlexibleMap,i18n:{},mapTypes:{},localised:!1,localise:function(){if("i18n"in flxmap&&(FlexibleMap.prototype.i18n=flxmap.i18n),"mapTypes"in flxmap){var e,t=flxmap.mapTypes;for(e in t)t[e]._styled_map=new google.maps.StyledMapType(t[e].styles,t[e].options);FlexibleMap.prototype.mapTypes=t}FlexibleMap.prototype.localised=!0},setlocale:function(e){return(this.locale=e)in this.i18n||e.substr(0,2)in this.i18n?this.localeActive=e:this.localeActive=!1,this.localeActive},gettext:function(e){var t=this.localeActive;return t&&e in this.i18n[t]?this.i18n[t][e]:e},showKML:function(e,t,i){this.zoom=i;let o=this,n=document.getElementById(e).getAttribute("data-flxmap"),r=this.showMap(e,[0,0]);t=this.loadKmlMap(((t,i)=>{i=/^(\d+)\s*(minute|hour|day)s?$/.exec(i);let r;if(i){var o=(new Date).getTime();let e=+i[1];switch(i[2]){case"minute":e<5&&(e=5),r=o/(6e4*e);break;case"hour":r=o/(36e5*e);break;case"day":r=o/(864e5*e);break;default:r=!1}r&&(r=Math.floor(r),t+=(-1<t.indexOf("?")?"&":"?")+"nocache="+r)}return t})(t,this.kmlcache));c(this,e),void 0!==i&&google.maps.event.addListenerOnce(r,"zoom_changed",function(){r.setZoom(i),o.zoom=i}),(this.markerDirections||this.markerDirectionsShow)&&this.startDirService(r),google.maps.event.addListener(t,"click",function(e){var t,i=e.featureData;function r(e){var e=e.charCodeAt(0),t=e.toString(16);return e<256?"\\x"+("00"+t).slice(-2):"\\u"+("0000"+t).slice(-4)}i._flxmapOnce||(i._flxmapOnce=!0,o.targetFix&&i.description&&(i.description=i.description.replace(t=/ target="_blank"/gi,""),i.infoWindowHtml=i.infoWindowHtml.replace(t,"")),o.markerDirections&&(e=(t=e.latLng).lat()+","+t.lng()+",'"+(i.name,function(e){return e.replace(/[\\/"'&<>\x00-\x1f\x7f-\xa0\u2000-\u200f\u2028-\u202f]/g,r)})+"',true",t='<br /><a href="#" onclick="'+n+".showDirections("+e+'); return false;">'+o.gettext("Directions")+"</a>",i.infoWindowHtml=i.infoWindowHtml.replace(/<\/div><\/div>$/i,t+"</div></div>")))})},showMarker:function(o,n,a){let s=this.showMap(o,n);var n=new google.maps.LatLng(a[0],a[1]),e={map:s,position:n,icon:this.markerIcon},t=google.maps.Animation;switch(this.markerAnimation){case"drop":e.animation=t.DROP;break;case"bounce":e.animation=t.BOUNCE}let l=new google.maps.Marker(e);if(this.setMarkerPoint(l),this.setMarkerLocation(n),c(this,o),this.markerTitle||(this.markerTitle=this.markerAddress),this.markerTitle||this.markerHTML||this.markerDescription||this.markerLink||this.markerDirections){let t=this;n=document.createElement("DIV");let i,e;if(n.className="flxmap-infowin",(i=document.createElement("DIV")).className="flxmap-marker-title",this.markerTitle&&(i.appendChild(document.createTextNode(this.markerTitle)),l.setTitle(this.markerTitle)),n.appendChild(i),this.markerHTML&&((i=document.createElement("DIV")).innerHTML=this.markerHTML,n.appendChild(i)),this.markerDescription||this.markerLink){if((i=document.createElement("DIV")).className="flxmap-marker-link",this.markerDescription){var d=this.markerDescription.split("\n");for(let e=0,t=d.length;e<t;e++)0<e&&i.appendChild(document.createElement("BR")),i.appendChild(document.createTextNode(d[e]));this.markerLink&&i.appendChild(document.createElement("BR"))}this.markerLink&&((e=document.createElement("A")).href=this.markerLink,this.markerLinkTarget&&(e.target=this.markerLinkTarget),e.appendChild(document.createTextNode(this.markerLinkText||this.gettext("Click for details"))),i.appendChild(e)),n.appendChild(i)}this.markerDirections&&((i=document.createElement("DIV")).className="flxmap-directions-link",(e=document.createElement("A")).href="#",e.dataLatitude=a[0],e.dataLongitude=a[1],e.addEventListener("click",function(e){m(e),t.showDirections(this.dataLatitude,this.dataLongitude,!0)}),e.appendChild(document.createTextNode(this.gettext("Directions"))),i.appendChild(e),n.appendChild(i));let r=new google.maps.InfoWindow({content:n});this.setMarkerInfowin(r),this.markerShowInfo&&google.maps.event.addListenerOnce(s,"tilesloaded",function(){r.open(s,l)}),google.maps.event.addListener(l,"click",function(){r.open(s,l)});o=function(){t.updateGoogleLink()};google.maps.event.addListener(s,"idle",o),google.maps.event.addListener(s,"center_changed",o),google.maps.event.addListenerOnce(s,"tilesloaded",o)}(this.markerDirections||this.markerDirectionsShow)&&(this.startDirService(s),this.markerDirectionsShow)&&this.showDirections(a[0],a[1],!1)},showAddress:function(i,e){let r=this;var t=new google.maps.Geocoder;this.markerAddress=e,""===this.markerTitle&&(this.markerTitle=e),t.geocode({address:e,region:this.region},function(e,t){t===google.maps.GeocoderStatus.OK?(e=[(e=e[0].geometry.location).lat(),e.lng()],r.showMarker(i,e,e)):window.alert("Map address returns error: "+t)})},updateGoogleLink:function(){if("querySelectorAll"in document)try{var e=this.getMap().getDiv(),t=this.getMarkerLocation(),i=e.querySelectorAll("a[href*='maps.google.com/maps']:not([href*='mps_dialog']):not([href*='&q='])"),r=encodeURIComponent((this.markerAddress||this.markerTitle)+" @"+t.lat()+","+t.lng());for(let e=0,t=i.length;e<t;e++)i[e].href+="&mrt=loc&iwloc=A&q="+r}catch{}},redraw:function(){var e=this.getMap(),t=this.getKmlLayer();google.maps.event.trigger(e,"resize"),t?(e.fitBounds(t.getDefaultViewport()),this.zoom&&e.setZoom(this.zoom)):(e.setCenter(this.getCenter()),e.setZoom(this.zoom),(t=this.getMarkerInfowin())&&t.open(e,this.getMarkerPoint()))},startDirService:function(e){this.dirService||(this.dirService=new google.maps.DirectionsService),this.dirRenderer||(this.dirRenderer=new google.maps.DirectionsRenderer({map:e,draggable:this.dirDraggable,suppressMarkers:this.dirSuppressMarkers,panel:this.dirShowSteps?document.getElementById(this.markerDirectionsDiv):null}))},showDirections:function(i,r,o){let n=this;function a(e){var t={origin:e,destination:""===n.markerAddress?new google.maps.LatLng(i,r):n.markerAddress};switch(n.region&&(t.region=n.region),n.dirTravelMode){case"bicycling":t.travelMode=google.maps.TravelMode.BICYCLING;break;case"driving":t.travelMode=google.maps.TravelMode.DRIVING;break;case"transit":t.travelMode=google.maps.TravelMode.TRANSIT;break;case"walking":t.travelMode=google.maps.TravelMode.WALKING}switch(n.dirUnitSystem){case"imperial":t.unitSystem=google.maps.UnitSystem.IMPERIAL;break;case"metric":t.unitSystem=google.maps.UnitSystem.METRIC}n.dirService.route(t,s)}function s(e,t){var i=google.maps.DirectionsStatus;switch(t){case i.OK:n.dirRenderer.setDirections(e);break;case i.ZERO_RESULTS:window.alert("No route could be found between the origin and destination.");break;case i.OVER_QUERY_LIMIT:window.alert("The webpage has gone over the requests limit in too short a period of time.");break;case i.REQUEST_DENIED:window.alert("The webpage is not allowed to use the directions service.");break;case i.INVALID_REQUEST:window.alert("Invalid directions request.");break;case i.NOT_FOUND:window.alert("Origin or destination was not found.");break;default:window.alert("A directions request could not be processed due to a server error. The request may succeed if you try again.")}}if(this.markerDirectionsDiv&&this.dirShowSearch){var l=document.getElementById(n.markerDirectionsDiv),d=document.createElement("form");let e,t;for(e=l.lastChild;e;e=l.lastChild)l.removeChild(e);(e=document.createElement("p")).appendChild(document.createTextNode(n.gettext("From")+": ")),(t=document.createElement("input")).type="text",t.name="from",t.value=n.markerDirectionsDefault,e.appendChild(t);var c=document.createElement("input");c.type="submit",c.value=n.gettext("Get directions"),e.appendChild(c),d.appendChild(e),l.appendChild(d),o&&t.focus(),d.addEventListener("submit",function(e){m(e);e=this.elements.from.value;/\S/.test(e)&&a(e)})}this.markerDirectionsDefault&&a(this.markerDirectionsDefault)}}})();