if("object"!=typeof window.google||!window.google.maps)throw"Google Maps API is required. Please register the following JavaScript library http://maps.google.com/maps/api/js?sensor=true.";var extend_object=function(t,e){var i;if(t===e)return t;for(i in e)t[i]=e[i];return t},replace_object=function(t,e){var i;if(t===e)return t;for(i in e)void 0!=t[i]&&(t[i]=e[i]);return t},array_map=function(t,e){var i,n=Array.prototype.slice.call(arguments,2),r=[],o=t.length;if(Array.prototype.map&&t.map===Array.prototype.map)r=Array.prototype.map.call(t,function(t){return callback_params=n,callback_params.splice(0,0,t),e.apply(this,callback_params)});else for(i=0;o>i;i++)callback_params=n,callback_params.splice(0,0,t[i]),r.push(e.apply(this,callback_params));return r},array_flat=function(t){var e,i=[];for(e=0;e0&&"number"!=typeof t[i][0]?arrayToLatLng(t[i],e):coordsToLatLngs(t[i],e);return t},getElementById=function(t,e){var i,t=t.replace("#","");return i="jQuery"in this&&e?$("#"+t,e)[0]:document.getElementById(t)},findAbsolutePosition=function(t){var e=0,i=0;if(t.offsetParent)do e+=t.offsetLeft,i+=t.offsetTop;while(t=t.offsetParent);return[e,i]},GMaps=function(){"use strict";var t=document,e=function(i){if(!this)return new e(i);i.zoom=i.zoom||15,i.mapType=i.mapType||"roadmap";var n,r=this,o=["bounds_changed","center_changed","click","dblclick","drag","dragend","dragstart","idle","maptypeid_changed","projection_changed","resize","tilesloaded","zoom_changed"],a=["mousemove","mouseout","mouseover"],s=["el","lat","lng","mapType","width","height","markerClusterer","enableNewStyle"],l=i.el||i.div,c=i.markerClusterer,h=google.maps.MapTypeId[i.mapType.toUpperCase()],u=new google.maps.LatLng(i.lat,i.lng),d=i.zoomControl||!0,p=i.zoomControlOpt||{style:"DEFAULT",position:"TOP_LEFT"},f=p.style||"DEFAULT",g=p.position||"TOP_LEFT",m=i.panControl||!0,v=i.mapTypeControl||!0,y=i.scaleControl||!0,x=i.streetViewControl||!0,b=b||!0,w={},_={zoom:this.zoom,center:u,mapTypeId:h},k={panControl:m,zoomControl:d,zoomControlOptions:{style:google.maps.ZoomControlStyle[f],position:google.maps.ControlPosition[g]},mapTypeControl:v,scaleControl:y,streetViewControl:x,overviewMapControl:b};if(this.el="string"==typeof i.el||"string"==typeof i.div?getElementById(l,i.context):l,"undefined"==typeof this.el||null===this.el)throw"No element defined.";for(window.context_menu=window.context_menu||{},window.context_menu[r.el.id]={},this.controls=[],this.overlays=[],this.layers=[],this.singleLayers={},this.markers=[],this.polylines=[],this.routes=[],this.polygons=[],this.infoWindow=null,this.overlay_el=null,this.zoom=i.zoom,this.registered_events={},this.el.style.width=i.width||this.el.scrollWidth||this.el.offsetWidth,this.el.style.height=i.height||this.el.scrollHeight||this.el.offsetHeight,google.maps.visualRefresh=i.enableNewStyle,n=0;n'+a.title+""}if(getElementById("gmaps_context_menu")){var s=getElementById("gmaps_context_menu");s.innerHTML=i;var l=s.getElementsByTagName("a"),c=l.length;for(o=0;c>o;o++){var h=l[o],u=function(i){i.preventDefault(),n[this.id.replace(t+"_","")].action.apply(r,[e]),r.hideContextMenu()};google.maps.event.clearListeners(h,"click"),google.maps.event.addDomListenerOnce(h,"click",u,!1)}var d=findAbsolutePosition.apply(this,[r.el]),p=d[0]+e.pixel.x-15,f=d[1]+e.pixel.y-15;s.style.left=p+"px",s.style.top=f+"px",s.style.display="block"}};this.buildContextMenu=function(t,e){if("marker"===t){e.pixel={};var i=new google.maps.OverlayView;i.setMap(r.map),i.draw=function(){var n=i.getProjection(),r=e.marker.getPosition();e.pixel=n.fromLatLngToContainerPixel(r),C(t,e)}}else C(t,e)},this.setContextMenu=function(e){window.context_menu[r.el.id][e.control]={};var i,n=t.createElement("ul");for(i in e.options)if(e.options.hasOwnProperty(i)){var o=e.options[i];window.context_menu[r.el.id][e.control][o.name]={title:o.title,action:o.action}}n.id="gmaps_context_menu",n.style.display="none",n.style.position="absolute",n.style.minWidth="100px",n.style.background="white",n.style.listStyle="none",n.style.padding="8px",n.style.boxShadow="2px 2px 6px #ccc",t.body.appendChild(n);var a=getElementById("gmaps_context_menu");google.maps.event.addDomListener(a,"mouseout",function(t){t.relatedTarget&&this.contains(t.relatedTarget)||window.setTimeout(function(){a.style.display="none"},400)},!1)},this.hideContextMenu=function(){var t=getElementById("gmaps_context_menu");t&&(t.style.display="none")};for(var S=function(t,e){google.maps.event.addListener(t,e,function(t){void 0==t&&(t=this),i[e].apply(this,[t]),r.hideContextMenu()})},T=0;Tt;t++)e.push(this.markers[t].getPosition());this.fitLatLngBounds(e)},this.fitLatLngBounds=function(t){for(var e=t.length,i=new google.maps.LatLngBounds,n=0;e>n;n++)i.extend(t[n]);this.map.fitBounds(i)},this.setCenter=function(t,e,i){this.map.panTo(new google.maps.LatLng(t,e)),i&&i()},this.getElement=function(){return this.el},this.zoomIn=function(t){t=t||1,this.zoom=this.map.getZoom()+t,this.map.setZoom(this.zoom)},this.zoomOut=function(t){t=t||1,this.zoom=this.map.getZoom()-t,this.map.setZoom(this.zoom)};var L,A=[];for(L in this.map)"function"!=typeof this.map[L]||this[L]||A.push(L);for(n=0;n0&&t.paths[0].length>0&&(t.paths=array_flat(array_map(t.paths,arrayToLatLng,e)));for(var i=new google.maps.Polygon(t),n=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"],r=0;r0&&t.locations[0].length>0&&(t.locations=array_flat(array_map([t.locations],arrayToLatLng,!1)));var e=t.callback;delete t.callback;var i=new google.maps.ElevationService;if(t.path){var n={path:t.locations,samples:t.samples};i.getElevationAlongPath(n,function(t,i){e&&"function"==typeof e&&e(t,i)})}else delete t.path,delete t.samples,i.getElevationForLocations(t,function(t,i){e&&"function"==typeof e&&e(t,i)})},GMaps.prototype.cleanRoute=GMaps.prototype.removePolylines,GMaps.prototype.drawRoute=function(t){var e=this;this.getRoutes({origin:t.origin,destination:t.destination,travelMode:t.travelMode,waypoints:t.waypoints,unitSystem:t.unitSystem,callback:function(i){i.length>0&&(e.drawPolyline({path:i[i.length-1].overview_path,strokeColor:t.strokeColor,strokeOpacity:t.strokeOpacity,strokeWeight:t.strokeWeight}),t.callback&&t.callback(i[i.length-1]))}})},GMaps.prototype.travelRoute=function(t){if(t.origin&&t.destination)this.getRoutes({origin:t.origin,destination:t.destination,travelMode:t.travelMode,waypoints:t.waypoints,callback:function(e){if(e.length>0&&t.start&&t.start(e[e.length-1]),e.length>0&&t.step){var i=e[e.length-1];if(i.legs.length>0)for(var n,r=i.legs[0].steps,o=0;n=r[o];o++)n.step_number=o,t.step(n,i.legs[0].steps.length-1)}e.length>0&&t.end&&t.end(e[e.length-1])}});else if(t.route&&t.route.legs.length>0)for(var e,i=t.route.legs[0].steps,n=0;e=i[n];n++)e.step_number=n,t.step(e)},GMaps.prototype.drawSteppedRoute=function(t){var e=this;if(t.origin&&t.destination)this.getRoutes({origin:t.origin,destination:t.destination,travelMode:t.travelMode,waypoints:t.waypoints,callback:function(i){if(i.length>0&&t.start&&t.start(i[i.length-1]),i.length>0&&t.step){var n=i[i.length-1];if(n.legs.length>0)for(var r,o=n.legs[0].steps,a=0;r=o[a];a++)r.step_number=a,e.drawPolyline({path:r.path,strokeColor:t.strokeColor,strokeOpacity:t.strokeOpacity,strokeWeight:t.strokeWeight}),t.step(r,n.legs[0].steps.length-1)}i.length>0&&t.end&&t.end(i[i.length-1])}});else if(t.route&&t.route.legs.length>0)for(var i,n=t.route.legs[0].steps,r=0;i=n[r];r++)i.step_number=r,e.drawPolyline({path:i.path,strokeColor:t.strokeColor,strokeOpacity:t.strokeOpacity,strokeWeight:t.strokeWeight}),t.step(i)},GMaps.Route=function(t){this.origin=t.origin,this.destination=t.destination,this.waypoints=t.waypoints,this.map=t.map,this.route=t.route,this.step_count=0,this.steps=this.route.legs[0].steps,this.steps_length=this.steps.length,this.polyline=this.map.drawPolyline({path:new google.maps.MVCArray,strokeColor:t.strokeColor,strokeOpacity:t.strokeOpacity,strokeWeight:t.strokeWeight}).getPath()},GMaps.Route.prototype.getRoute=function(t){var i=this;this.map.getRoutes({origin:this.origin,destination:this.destination,travelMode:t.travelMode,waypoints:this.waypoints||[],callback:function(){i.route=e[0],t.callback&&t.callback.call(i)}})},GMaps.Route.prototype.back=function(){if(this.step_count>0){this.step_count--;var t=this.route.legs[0].steps[this.step_count].path;for(var e in t)t.hasOwnProperty(e)&&this.polyline.pop()}},GMaps.Route.prototype.forward=function(){if(this.step_count0){e.markers=[];for(var i=0;i0){var n=this.polylines[0];e.polyline={},e.polyline.path=google.maps.geometry.encoding.encodePath(n.getPath()),e.polyline.strokeColor=n.strokeColor,e.polyline.strokeOpacity=n.strokeOpacity,e.polyline.strokeWeight=n.strokeWeight}return GMaps.staticMapURL(e)},GMaps.staticMapURL=function(t){function e(t,e){if("#"===t[0]&&(t=t.replace("#","0x"),e)){if(e=parseFloat(e),e=Math.min(1,Math.max(e,0)),0===e)return"0x00000000";e=(255*e).toString(16),1===e.length&&(e+=e),t=t.slice(0,8)+e}return t}var i,n=[],r="http://maps.googleapis.com/maps/api/staticmap";t.url&&(r=t.url,delete t.url),r+="?";var o=t.markers;delete t.markers,!o&&t.marker&&(o=[t.marker],delete t.marker);var a=t.styles;delete t.styles;var s=t.polyline;if(delete t.polyline,t.center)n.push("center="+t.center),delete t.center;else if(t.address)n.push("center="+t.address),delete t.address;else if(t.lat)n.push(["center=",t.lat,",",t.lng].join("")),delete t.lat,delete t.lng;else if(t.visible){var l=encodeURI(t.visible.join("|"));n.push("visible="+l)}var c=t.size;c?(c.join&&(c=c.join("x")),delete t.size):c="630x300",n.push("size="+c),t.zoom||t.zoom===!1||(t.zoom=15);var h=t.hasOwnProperty("sensor")?!!t.sensor:!0;delete t.sensor,n.push("sensor="+h);for(var u in t)t.hasOwnProperty(u)&&n.push(u+"="+t[u]);if(o)for(var d,p,f=0;i=o[f];f++){d=[],i.size&&"normal"!==i.size?(d.push("size:"+i.size),delete i.size):i.icon&&(d.push("icon:"+encodeURI(i.icon)),delete i.icon),i.color&&(d.push("color:"+i.color.replace("#","0x")),delete i.color),i.label&&(d.push("label:"+i.label[0].toUpperCase()),delete i.label),p=i.address?i.address:i.lat+","+i.lng,delete i.address,delete i.lat,delete i.lng;for(var u in i)i.hasOwnProperty(u)&&d.push(u+":"+i[u]);d.length||0===f?(d.push(p),d=d.join("|"),n.push("markers="+encodeURI(d))):(d=n.pop()+encodeURI("|"+p),n.push(d))}if(a)for(var f=0;fr;r++)for(var o=this.getPaths().getAt(r),a=o.getLength(),s=a-1,l=0;a>l;l++){var c=o.getAt(l),h=o.getAt(s);(c.lng()=t.lng()||h.lng()=t.lng())&&c.lat()+(t.lng()-c.lng())/(h.lng()-c.lng())*(h.lat()-c.lat())>>0;if(0===i)return-1;var n=0;if(arguments.length>1&&(n=Number(arguments[1]),n!=n?n=0:0!=n&&1/0!=n&&n!=-1/0&&(n=(n>0||-1)*Math.floor(Math.abs(n)))),n>=i)return-1;for(var r=n>=0?n:Math.max(i-Math.abs(n),0);i>r;r++)if(r in e&&e[r]===t)return r;return-1});