!function(e){function t(t,n){function a(){n.MapOptions.center&&(n.MapOptions.center=r(n.MapOptions.center)),n.MapOptions.zoom||(n.MapOptions.zoom=8),l(),e(n.getRouteButton).length>0&&e(n.getTravelMode).length>0&&u(this),e(n.geoLocationButton).length>0&&e(n.geoLocationButton).on("click",function(e){e.preventDefault(),m(G.map)}.bind(this)),P("onInit")}function i(t,a){for(var i=new google.maps.LatLngBounds,r=0;r0){var t=G.markers[0].position.toString(),o="?q="+t;navigator.userAgent.toLowerCase().indexOf("android")>-1?e(n.externalLink).attr("href",n.AndroidMapLink+o):navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPod/i)?e(n.externalLink).attr("href",n.AppleMapLink+o):e(n.externalLink).attr("href",n.GenericMapLink+o)}}function l(){var t=(new google.maps.InfoWindow,new google.maps.Geocoder),o="",a=[],l=I.clone(),g=n.AutoComplete;g&&C(),e(n.SearchButton).length>0&&e(n.SearchBox).length>0?(e(n.SearchButton).on("click",function(t){t.preventDefault();var o=e(n.SearchBox).val();B(o,G.map)}),e(n.SearchBox).keypress(function(t){if(13===t.which){var o=e(n.SearchBox).val();B(o,G.map)}})):e(n.getRouteButton).length>0&&e(n.getFromAddress).length>0&&e(n.getFromAddress).keypress(function(t){13===t.which&&e(n.getRouteButton).trigger("click")});var c=new google.maps.Map(I[0],n.MapOptions);l.find("div.map-marker").each(function(n){e(this).attr("data-latlng")?(o=e(this),p(o.data("icon"),o.data("icon2x"),function(t){var n=new google.maps.Marker({map:c,title:o.data("title"),position:r(o.data("latlng")),icon:t});if(o.has("div.map-infowindow").length>0){var i=new google.maps.InfoWindow({content:o.find("div.map-infowindow").parent().html()});google.maps.event.addListener(n,"click",function(){i.open(c,n)})}else if(o.has("div.map-custom-infowindow").length>0){var s=o.find("div.map-custom-infowindow").parent().html();google.maps.event.addListener(n,"click",function(){e("#simplegmaps-c-iw").remove(),e('
').insertAfter(I),e("#simplegmaps-c-iw").html(s),e("#simplegmaps-c-iw .close").on("click",function(t){t.preventDefault(),e("#simplegmaps-c-iw").remove()})})}a.push(n)})):e(this).attr("data-address")&&(o=e(this),t.geocode({address:e(this).data("address")},function(t,n){n===google.maps.GeocoderStatus.OK&&p(o.data("icon"),o.data("icon2x"),function(n){var i=new google.maps.Marker({map:c,title:o.data("title"),position:t[0].geometry.location,icon:n});if(o.has("div.map-infowindow").length>0){var r=new google.maps.InfoWindow({content:o.find("div.map-infowindow").parent().html()});google.maps.event.addListener(i,"click",function(){r.open(c,i)})}else if(o.has("div.map-custom-infowindow").length>0){var s=o.find("div.map-custom-infowindow").parent().html();google.maps.event.addListener(i,"click",function(){e("#simplegmaps-c-iw").remove(),e('
').insertAfter(I),e("#simplegmaps-c-iw").html(s),e("#simplegmaps-c-iw .close").on("click",function(t){t.preventDefault(),e("#simplegmaps-c-iw").remove()})})}a.push(i)})}))}),google.maps.event.addListenerOnce(c,"idle",function(){if(a.length>0)i(c,a);else if(!n.MapOptions.center){var e=new google.maps.LatLngBounds;c.fitBounds(e),c.setCenter(e.getCenter())}G={map:c,markers:a},s(),n.GeoLocation&&m(G.map),P("onMapDrawn")})}function p(e,t,o){var n="",a=new Image;window.devicePixelRatio>1.5&&t?(a.onload=function(){var e={url:t,size:new google.maps.Size(a.naturalWidth/2,a.naturalHeight/2),scaledSize:new google.maps.Size(a.naturalWidth/2,a.naturalHeight/2),origin:new google.maps.Point(0,0)};o(e)},a.src=t):e?(a.onload=function(){var t={url:e,size:new google.maps.Size(a.naturalWidth,a.naturalHeight)};o(t)},a.src=e):o(n)}function g(t){var o=G.markers;directionsDisplay.setMap(G.map),directionsDisplay.setPanel(e(n.routeDirections)[0]);var a={origin:t,destination:o[0].position,travelMode:google.maps.TravelMode[currentTravelmode]};jQuery.extend(a,n.DirectionsRequestOptions),directionsService.route(a,function(e,t){t===google.maps.DirectionsStatus.OK&&(directionsDisplay.setDirections(e),P("onRouteDrawn"))})}function c(e){var t=N.length;currentTravelmode=n.defaultTravelMode;for(var o=0;t>o;o++)N[o]===e&&(currentTravelmode=e)}function u(){directionsService=new google.maps.DirectionsService,directionsDisplay=new google.maps.DirectionsRenderer({draggable:!0}),e(n.getRouteButton).on("click",function(t){t.preventDefault();var o=e(n.getTravelMode).val();c(o),e(n.getFromAddress).val().length>0&&g(e(n.getFromAddress).val())})}function m(e){navigator.geolocation?navigator.geolocation.getCurrentPosition(function(t){var o=new google.maps.LatLng(t.coords.latitude,t.coords.longitude);e.setCenter(o)},function(){h(e,!0)}):h(e,!1)}function d(){W&&null!==W.map?W.setMap(null):(W=new google.maps.TrafficLayer,W.setMap(G.map))}function f(){z&&null!==z.map?z.setMap(null):(z=new google.maps.BicyclingLayer,z.setMap(G.map))}function h(e,t){var o;o=t?"Error: The Geolocation service failed.":"Error: Your browser doesn't support geolocation.";var n={map:e,position:new google.maps.LatLng(60,105),content:o};new google.maps.InfoWindow(n);G.setCenter(n.position)}function v(e){var t=n.AndroidMapLink+e;return t}function w(e){var t=n.iOSAppleMapLink+"?q="+e;return t}function L(e){var t=n.WP7MapLink+e;return t}function M(e){var t=n.DesktopMapLink+"?q="+e;return t}function k(e){var t="";return t=A()?v(e):y()?w(e):D()?L(e):M(e)}function A(){return navigator.userAgent.toLowerCase().indexOf("android")>-1?!0:!1}function y(){return navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPod/i)?!0:!1}function D(){return navigator.userAgent.match(/Windows Phone/i)?!0:!1}function C(){var t=e(n.SearchBox)[0],o=n.AutoCompleteOptions;R=new google.maps.places.Autocomplete(t,o),e(n.getRouteButton).length>0&&e(n.getFromAddress).length>0?R.addListener("place_changed",function(){e(n.getRouteButton).trigger("click")}):R.addListener("place_changed",x)}function x(){var e=R.getPlace();if(e.geometry){if(n.AutoCompleteOptions.moveMap&&(G.map.panTo(e.geometry.location),G.map.setZoom(15)),n.AutoCompleteOptions.setMarker){new google.maps.Marker({map:G.map,position:e.geometry.location})}P("onAutoCompletePlaceChanged")}}function B(e,t){var o=new google.maps.Geocoder;o.geocode({address:e},function(e,o){if(o===google.maps.GeocoderStatus.OK){t.setCenter(e[0].geometry.location);new google.maps.Marker({map:t,position:e[0].geometry.location})}})}function S(e,t){return t?void(n[e]=t):n[e]}function O(){I.each(function(){var t=e(this);P("onDestroy"),t.removeData("plugin_"+o)})}function P(e){void 0!==n[e]&&n[e].call(T)}var R,T=t,I=e(t),G=!1,W=!1,z=!1,N=["DRIVING","WALKING","BICYCLING","TRANSIT"];return n=e.extend({},e.fn[o].defaults,n),a(),{option:S,destroy:O,getNativeMapLink:k,toggleTrafficLayer:d,toggleBicycleLayer:f,getGoogleMapLink:v,getAppleMapsLink:w,getWindowsPhone7MapLink:L,getDesktopMapLink:M}}var o="simplegmaps";e.fn[o]=function(n){if("string"==typeof arguments[0]){var a,i=arguments[0],r=Array.prototype.slice.call(arguments,1);return this.each(function(){if(!e.data(this,"plugin_"+o)||"function"!=typeof e.data(this,"plugin_"+o)[i])throw new Error("Method "+i+" does not exist on jQuery."+o);a=e.data(this,"plugin_"+o)[i].apply(this,r)}),void 0!==a?a:this}return"object"!=typeof n&&n?void 0:this.each(function(){e.data(this,"plugin_"+o)||e.data(this,"plugin_"+o,new t(this,n))})},e.fn[o].defaults={GeoLocation:!1,MapOptions:{draggable:!0,zoom:8,scrollwheel:!1,streetViewControl:!1,panControl:!0,zoomControl:!0,zoomControlOptions:{style:"DEFAULT"}},SearchBox:"#simplegmaps-searchbox",SearchButton:"#simplegmaps-searchbutton",AutoComplete:!1,AutoCompleteOptions:{types:["geocode"],componentRestrictions:{country:"se"},moveMap:!1,setMarker:!1},iOSAppleMapLink:"http://maps.apple.com/",iOSGoogleMapLink:"comgooglemaps://",AndroidMapLink:"comgooglemaps://",WP7MapLink:"maps:",DesktopMapLink:"http://www.google.com/maps",getRouteButton:"#simplegmaps-getroute",getTravelMode:"#simplegmaps-travelmode input:checked",routeDirections:"#simplegmaps-directions",externalLink:"#simplegmaps-external",getFromAddress:"#simplegmaps-fromaddress",defaultTravelMode:"DRIVING",onInit:function(){},onLoad:function(){},onDestroy:function(){},onRouteDrawn:function(){},onMapDrawn:function(){},onAutoCompletePlaceChanged:function(){}}}(jQuery);