jQuery(document).ready(function(e){function p(e,a){"undefined"===typeof a&&(a=!1);var b=e.data("mpce_gma_map");if("undefined"!==typeof b){if(a)var d=b.getCenter();google.maps.event.trigger(b,"resize");a&&b.panTo(d)}}function s(c){for(var a=new google.maps.LatLngBounds,b=0;b<c.length;++b){var d=e(c[b]).data("lat-lng");a.extend(new google.maps.LatLng(d.lat,d.lng))}return a.getCenter()}function r(c){var a=c.children(".mpce-gma-map-canvas");if(!a.length)return!1;var b=c.find(".mpce-gma-markers .mpce-gma-marker"),
d=a.data("type"),k=a.data("zoom"),w=a.data("scrollwheel"),p=a.data("draggable"),l=a.data("disable-default-ui"),m=a.data("map-style"),t=new google.maps.DirectionsRenderer,q=e.Deferred();a.data("mpce_gma_promise",q.promise());var g;b.length?g=s(b):(g=new google.maps.LatLng(0,0,!0),k=1);d={center:g,zoom:k,mapTypeId:google.maps.MapTypeId[d],scrollwheel:!1,draggable:!1,disableDefaultUI:l};"default"!=m&&(d.styles=mpce_gma_styles[m]);var h=new google.maps.Map(a[0],d);t.setMap(h);a.data("mpce_gma_map",h);
a.data("mpce_gma_directions_display",t);a.data("mpce_gma_center",h.getCenter());var r=[];b.length&&b.each(function(){var a=e(this),b=e.Deferred();a.data("address-type");var c=a.data("address"),d=a.data("lat-lng"),k=a.data("title"),l=a.data("icon-type"),f;a.data("mpce_gma_deferred",b);a.data("mpce_gma_promise",b.promise());if(c){c={position:new google.maps.LatLng(d.lat,d.lng,!0),map:h};k&&(c.title=k);k="marker";if("media"===l){if(l=a.data("media-icon"))c.icon=l}else if("font"===l&&(l=a.data("font-icon"))){k=
!1;d=String((new Date).getTime());f=0;var n="";for(f=0;f<d.length;f+=2)n+=Number(d.substr(f,2)).toString(36);d="d"+n;a.data("mpce_gma_id",d);c.mpceGmaId=d;c.icon=" ";f=" mpce-gma-marker-id-"+d+" ";n="";"custom"===a.data("font-icon-color")?n+="color:"+a.data("font-icon-custom-color")+";":f+=" "+a.data("font-icon-color");f+=" mpce-gma-marker-size-"+a.data("font-icon-size");"custom"===a.data("font-icon-size")?(d=a.data("font-icon-custom-size"),n+="font-size:"+d+"px;"):d=48;c.anchorPoint=new google.maps.Point(0,
-d+3);c.labelContent='<i class="'+l+f+'" style="'+n+'"></i>'}f=k?new google.maps.Marker(c):new MarkerWithLabel(c);a.data("mpce_gma_marker",f);x(a,f,h);b.resolve()}else b.reject();r.push(f)});google.maps.event.addListenerOnce(h,"tilesloaded",function(){var d,c,k,l,m;b.each(function(){if(c=e(this).data("mpce_gma_id"))k=a.find(".mpce-gma-marker-id-"+c).eq(0),k.length&&(d=e(this).data("mpce_gma_marker"),"undefined"!==typeof d&&(l=k.width()/2,m=k.height(),d.labelAnchor=new google.maps.Point(Math.ceil(l),
m),d.setMap(h),e(this).data("mpce_gma_deferred").resolve()))})});q.resolve();google.maps.event.addListener(h,"mousedown",function(){h.setOptions({scrollwheel:w});h.setOptions({draggable:p})});google.maps.event.addListener(h,"mouseout",function(){h.setOptions({scrollwheel:!1});h.setOptions({draggable:!1})});c.live("click",function(a){a=a.target;if(e(a).is(".mpce-google-map-link")){var b=e(a).data("lat-lng"),d=y(r,b),b=new google.maps.LatLng(b.lat,b.lng);h.panTo(b);d.setAnimation();e(a).blur();u(d);
setTimeout(function(){u(d)},1500)}})}function y(c,a){var b;e.each(c,function(d,c){if(a.lat==c.getPosition().lat()&&a.lng==c.getPosition().lng())return b=c,0});return b}function u(c){null!=c.getAnimation()?c.setAnimation(null):c.setAnimation(google.maps.Animation.BOUNCE)}function x(c,a,b){var d=c.html(),e=null;d&&(e=new google.maps.InfoWindow({content:d}));google.maps.event.addListener(a,"click",function(){q&&q.close();e&&(q=e,e.open(b,a))});c.data("mpce_gma_popup",e)}function z(c){var a=c.data("address"),
b=c.data("lat-lng");a&&navigator.geolocation?navigator.geolocation.getCurrentPosition(function(a){a={origin:new google.maps.LatLng(a.coords.latitude,a.coords.longitude),destination:new google.maps.LatLng(b.lat,b.lng,!0),travelMode:google.maps.TravelMode.DRIVING};g.route(a,function(a,b){b==google.maps.DirectionsStatus.OK&&c.closest(".mpce-gma-map-canvas").data("mpce_gma_directions_display").setDirections(a)})},function(){alert(MPCE_GMA.lang.gl_service_failed)}):alert(MPCE_GMA.lang.gl_not_supported)}
e("body").on("MPCEObjectCreated MPCEObjectUpdated",function(c,a,b){"sm_google_map"===b&&r(a.find(".mpce-gma-wrapper"))});e("body").on("MPCEObjectInteraction",function(c,a){if("sm_google_map"===a.objName&&"child"===a.interacted&&"sm_google_map_marker"===a.childObjName){var b=a.objElement.find(".mpce-gma-map-canvas"),d=a.childObjElement.find(".mpce-gma-marker"),e=a.childObjElement.find(".mpce-gma-markers .mpce-gma-marker");if(!b.length||!d.length)return!1;var g=b.data("mpce_gma_promise");if("undefined"===
typeof g)return!1;g.done(function(){var c=d.data("mpce_gma_promise");if("undefined"===typeof c)return!1;c.done(function(){var c=d.data("mpce_gma_marker"),m=d.data("mpce_gma_popup");if("undefined"===typeof c||"undefined"===typeof m)return!1;var g=b.data("mpce_gma_map");switch(a.action){case "activate":m?m.open(g,c):g.panTo(c.getPosition());break;case "deactivate":m&&m.close(g,c),e.length?(c=s(e),g.panTo(c)):g.panTo(b.data("mpce_gma_center"))}})})}});e("body").on("MPCEObjectSplitStop",function(c,a){if(a.involvedElements.hasOwnProperty("sm_google_map")){var b;
e.each(a.involvedElements.sm_google_map,function(){b=e(this).find(".mpce-gma-map-canvas");b.length&&p(b,!0)})}});e("body").on("MPCEObjectResizeStop MPCEObjectStyleChanged",function(c,a){if("sm_google_map"===a.objName){var b=a.objElement.find(".mpce-gma-map-canvas");b.length&&p(b,!0)}});e("body").on("MPCEObjectDrop MPCEObjectRemove",function(c,a){if(a.involvedElements.hasOwnProperty("sm_google_map")){var b;e.each(a.involvedElements.sm_google_map,function(){b=e(this).find(".mpce-gma-map-canvas");b.length&&
p(b,!0)})}});var v=null,g=null,q=null;google.maps.event.addDomListener(window,"load",function(){v||(v=new google.maps.Geocoder);g||(g=new google.maps.DirectionsService);e(".mpce-gma-wrapper").each(function(){r(e(this))});e(".mpce-gma-wrapper").on("click",".mpce-gma-dd-link",function(){z(e(this))})});google.maps.event.addDomListener(window,"resize",function(){e(".mpce-gma-map-canvas").each(function(){p(e(this),!0)})})});

