(function($){'use strict';var maps=[];$('.cmb-type-pw-map').each(function(){initializeMap($(this))});function initializeMap(mapInstance){var searchInput=mapInstance.find('.pw-map-search');var mapCanvas=mapInstance.find('.pw-map');var latitude=mapInstance.find('.pw-map-latitude');var longitude=mapInstance.find('.pw-map-longitude');var latLng=new google.maps.LatLng(54.800685,-4.130859);var zoom=5;if(latitude.val().length>0&&longitude.val().length>0){latLng=new google.maps.LatLng(latitude.val(), longitude.val());zoom=17};var mapOptions={center:latLng,zoom:zoom};var map=new google.maps.Map(mapCanvas[0],mapOptions);var markerOptions={map:map,draggable:true,title:'Drag to set the exact location'};var marker=new google.maps.Marker(markerOptions);if(latitude.val().length>0&&longitude.val().length>0){marker.setPosition(latLng)};var autocomplete=new google.maps.places.Autocomplete(searchInput[0]);autocomplete.bindTo('bounds',map);google.maps.event.addListener(autocomplete,'place_changed',function(){var place=autocomplete.getPlace();if(!place.geometry){return};if(place.geometry.viewport){map.fitBounds(place.geometry.viewport)}else{map.setCenter(place.geometry.location);map.setZoom(17)};marker.setPosition(place.geometry.location);latitude.val(place.geometry.location.lat());longitude.val(place.geometry.location.lng())});$(searchInput).keypress(function(event){if(13===event.keyCode){event.preventDefault()}});google.maps.event.addListener(marker,'drag',function(){latitude.val(marker.getPosition().lat());longitude.val(marker.getPosition().lng())});maps.push(map);};if(typeof postboxes!=='undefined'){postboxes.pbshow=function(){var arrayLength=maps.length;for(var i=0;i