var MM=Microsoft.Maps,GGMap=function(n){var t={credentials:Settings.mapApiKey,showMapTypeSelector:!1,showDashboard:!1,enableClickableLogo:!1,enableSearchLogo:!1,showScalebar:!1,disableBirdseye:!0,disableKeyboardInput:!0},i=document.getElementById(n);this._map=MM.Map(i,t);this._markers=[]},initMap,ResultList;GGMap.Marker=function(n,t,i,r){this._id=n;this._location=t;this._pushpin=i;this._icons=r};GGMap.Marker.prototype.getLocation=function(){return this._location};GGMap.Marker.prototype.getPushpin=function(){return this._pushpin};GGMap.Marker.prototype.getId=function(){return this._id};GGMap.Marker.prototype.setState=function(n){var t=this._icons[n];t&&this._pushpin.setOptions({icon:t.data,anchor:new Microsoft.Maps.Point(t.width/2,t.height)})};GGMap.MarkerGenerator=function(n,t){this._initialized=!1;this._textOptions=n.textOptions;this._img=new Image;var i=this;this._img.onload=function(){i._initialized=!0;t()};this._img.src=n.url};GGMap.MarkerGenerator.prototype.isReady=function(){return this._initialized};GGMap.MarkerGenerator.prototype.generateMarker=function(n){var t=document.createElement("canvas"),i,r;return t.width=this._img.width,t.height=this._img.height,i=t.getContext("2d"),i.drawImage(this._img,0,0,t.width,t.height,0,0,t.width,t.height),n&&(r=i.measureText(n).width,i.textBaseline="top",i.font=this._textOptions.font,i.fillStyle=this._textOptions.color,i.fillText(n,Math.floor((t.width-r)/2),this._textOptions.offsetY)),{data:t.toDataURL(),width:t.width,height:t.height}};GGMap.prototype.getMarker=function(n,t,i,r){var u={},f;for(f in t)u[f]=t[f].generateMarker(r);var o=n.location,e=u[i],s=new Microsoft.Maps.Pushpin(o,{icon:e.data,anchor:new Microsoft.Maps.Point(e.width/2,e.height)});return new GGMap.Marker(n.id,o,s,u)};GGMap.prototype.addMarkers=function(n,t,i,r){var o=this._map,u=this,f={},s=function(){var e,t;for(e in f)if(!f[e].isReady())return;Array.isArray(n)?n.forEach(function(n){var t=u.getMarker(n,f,i,n.label);u._markers.push(t);o.entities.push(t.getPushpin())}):(t=u.getMarker(n,f,i),u._markers.push(t),o.entities.push(t.getPushpin()));u.refitMap();r&&r()},e;for(e in t)f[e]=new GGMap.MarkerGenerator(t[e],s)};GGMap.prototype.getMarkerBoundingBox=function(){var n=[],t=-90,i=90,r=-180,u=180;this._markers.forEach(function(f){var e=f.getLocation();n.push(e);e.latitude>t&&(t=e.latitude);e.latitude<i&&(i=e.latitude);e.longitude>r&&(r=e.longitude);e.longitude<u&&(u=e.longitude)});var f=.07,e=(t-i)*f,o=(r-u)*f;return n.push(new MM.Location(i-e,r+o)),n.push(new MM.Location(t+e,u-o)),MM.LocationRect.fromLocations(n)};GGMap.prototype.refitMap=function(){var n,t;this._markers.length==1?(n=this._markers[0].getLocation(),this._map.setView({center:n,zoom:16})):(t=this.getMarkerBoundingBox(),this._map.setView({bounds:t}))};GGMap.prototype.setIndexedMarkerState=function(n,t){this._markers[n].setState(t)};GGMap.prototype.getMarkerById=function(n){for(var t=0;t<this._markers.length;t++)if(this._markers[t].getId()==n)return this._markers[t]};GGMap.prototype.setMarkerStateById=function(n,t){var i=this.getMarkerById(n);i&&i.setState(t)};initMap=function(){var n=$(".map-item").map(function(){return{id:$(this).data("id"),label:($(this).data("index")+1).toString(),location:$(this).data("location")}}).toArray();if(n.length==0){$(".map-placeholder").hide();return}var t=n.length==1,i=new GGMap("map-holder"),r,e=t?"single_poi.png":"empty_poi.png",u={font:"12px Sans-Serif",color:"black",offsetY:7},f={dormant:{url:"/Content/images/"+e,textOptions:u}};t||(f.active={url:"/Content/images/empty_active_poi.png",textOptions:u},r=function(){$(".map-item").on("mouseenter",function(){i.setMarkerStateById($(this).data("id"),"active")}).on("mouseleave",function(){i.setMarkerStateById($(this).data("id"),"dormant")})});t&&(n=n[0]);i.addMarkers(n,f,"dormant",r)};ResultList={};ResultList.initCategoryLists=function(){$(".expand-categories").on("click",function(n){$(this).closest("ul").find(">li").removeClass("hidden");$(this).closest("li").remove();n.preventDefault()})};$(function(){ResultList.initCategoryLists()})