jQuery(function(){"use strict";var e=jQuery(document),t=e.find(".content.map > .google-map"),o=t.find(".loader-box"),a=e.find(".content.locations > ul"),n=e.find(".field.filter select"),i=[];if(t.length&&a.length){var l,d,c=a.data("open-map-text");a.on("filter",function(e,o){l.selected_location&&m(),a.find("li").each(function(){var e=jQuery(this);e.toggle(""==o||e.data("city")==o)}),t.trigger("updatemarkers")}),n.on("change",function(){var e=this.value;n.not(this).val(e),a.trigger("filter",e)});var s=function(){jQuery(i).each(function(e){i[e].setMap(null)}),i=[]},g=function(){var o={mapTypeId:google.maps.MapTypeId.ROADMAP,selectedLocation:null,center:{lat:56.9826,lng:24.2033},zoom:13,mapTypeControl:!1,streetViewControl:!1,clickableIcons:!1};l=new google.maps.Map(t.get(0),o),d=new google.maps.InfoWindow,google.maps.event.addListener(d,"closeclick",m),e.on("resizeend",function(){google.maps.event.trigger(l,"resize")})},r=function(){a.find("li").each(function(o,a){var n=jQuery(a),i={position:{lat:parseFloat(n.data("latitude")),lng:parseFloat(n.data("longitude"))},node:n};i.marker=new google.maps.Marker({position:i.position,map:null,location:i,icon:{url:"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMzAiIGhlaWdodD0iMzUiIHZpZXdCb3g9IjAgMCAzMCAzNSI+PGRlZnM+PHBhdGggaWQ9ImEiIGQ9Ik0wIDBoMzB2MjhsLTE0Ljk1IDdMMCAyOHoiLz48L2RlZnM+PGcgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj48dXNlIGZpbGw9IiNFRDAwMzkiIHhsaW5rOmhyZWY9IiNhIi8+PHBhdGggc3Ryb2tlPSIjRkZGIiBzdHJva2Utd2lkdGg9IjIiIGQ9Ik0xIDFoMjh2MjYuMzY0bC0xMy45NTEgNi41MzJMMSAyNy4zNjJWMXoiLz48cGF0aCBmaWxsPSIjRkZGIiBkPSJNMCAxMGgzMHYySDB6Ii8+PC9nPjwvc3ZnPg==",scaledSize:new google.maps.Size(32,32)},optimized:!1}),i.marker.addListener("click",function(){u(this.location)}),n.data("location",i),n.on("click",function(t){/^(medium|full)$/.test(e.data("layout"))&&n.find("a.title").click()}),n.find("a").on("click",function(e){e.stopPropagation()}),n.find("a.title, .more a").on("click",function(o){o.preventDefault(),u(i),"compact"==e.data("layout")&&jQuery("html, body").animate({scrollTop:t.offset().top+"px"})})})};t.on("updatemarkers",function(){s();var e=new google.maps.LatLngBounds,t=a.find("li:visible");if(t.each(function(t,o){var a=jQuery(o),n=a.data("location").marker;n.setMap(l),e.extend(n.getPosition()),i.push(n)}),1==t.length&&u(t.first().data("location")),e.getNorthEast().equals(e.getSouthWest())){var o={latitude:e.getNorthEast().lat(),longitude:e.getNorthEast().lng()};e.extend(new google.maps.LatLng(o.latitude+.01,o.longitude+.01)),e.extend(new google.maps.LatLng(o.latitude-.01,o.longitude-.01))}l.fitBounds(e)});var u=function(e){l.selected_location&&m(),l.selected_location=e;var t=jQuery('<div class="location-details">').html(l.selected_location.node.html());t.find(".more a").addClass("button secondary").text(c),d.setContent(t[0].outerHTML),d.open(l,l.selected_location.marker),l.selected_location.node.addClass("selected")},m=function(){l.selected_location.node.removeClass("selected"),l.selected_location=null,d.close()};window.initialize=function(){"undefined"!=typeof google&&(o.hide(),g(),r(),a.trigger("filter",n.val()))};var p=document.createElement("script");document.getElementsByTagName("head")[0].appendChild(p),p.src="//maps.googleapis.com/maps/api/js?key="+t.data("google-maps-key")+"&callback=initialize&language="+document.documentElement.lang}});