function clone(deep){var objectClone=new this.constructor();for(var property in this)if(!deep)objectClone[property]=this[property];else if(typeof this[property]=='object')objectClone[property]=this[property].clone(deep);else objectClone[property]=this[property];return objectClone;}Object.prototype.clone=clone;function DataLayer(gmap){this._objs=new Array();this._map=gmap;}DataLayer.prototype=new DataLayer();DataLayer.prototype._objs=null;DataLayer.prototype._map=null;DataLayer.prototype._focusedIndex=-1;DataLayer.prototype.isEnabled=true;DataLayer.prototype.add=function(newObj){newObj._container=this;this._objs.push(newObj);if(newObj.type==TYPE_POLYLINE)newObj.show(this._map);};DataLayer.prototype.show=function(){this.isEnabled=true;for(var i=0;i<this._objs.length;i++){if(!this._objs[i].isVisible)this._objs[i].show(this._map);}};DataLayer.prototype.hide=function(){this.isEnabled=false;for(var i=0;i<this._objs.length;i++){if(this._objs[i].isVisible)this._objs[i].hide(this._map);}};DataLayer.prototype.blur=function(){for(var i=0;i<this._objs.length;i++){this._objs[i].blur(this._map);}};DataLayer.prototype.enable=function(){this.isEnabled=true;this.refresh();};DataLayer.prototype.disable=function(){this.isEnabled=false;this.hide();};DataLayer.prototype.clear=function(){this.hide();for(var i=0;i<this._objs.length;i++){this._objs[i]._container=null;}this._objs=Array();};DataLayer.prototype.destroy=function(){this.clear();};DataLayer.prototype.size=function(){return this._objs.length;};DataLayer.prototype.refresh=function(){if(!this.isEnabled)return;var bounds=this._map.getBounds();for(var i=0;i<this._objs.length;++i){if(this._objs[i].type==TYPE_POLYLINE){continue;}var inBounds=this._objs[i].isInBounds(bounds);var isVisible=this._objs[i].isVisible;if(inBounds&&!isVisible)this._objs[i].show(this._map);else if(!inBounds&&isVisible)this._objs[i].hide(this._map);}};DataLayer.prototype.getClosestEvent=function(p){var objs;if(arguments.length<2)objs=this._objs;else objs=arguments[1];var minDist=99999999;var minP=-1;for(var i=0;i<objs.length;++i){if(objs[i].type!=TYPE_MARKER)continue;var dist=objs[i].distance(p);if(dist<minDist){minDist=dist;minP=objs[i];}}return minP;};DataLayer.prototype.getClosestFutureEvent=function(p){var objs=array();for(var i=0;i<this._objs.length;++i){if(this._objs[i].isFuture)objs.push(this._objs[i]);}return this.getClosestEvent(p,objs);};DataLayer.prototype.moveToClosestEvent=function(p){this.moveToEvent(this.getClosestEvent(p),p);};DataLayer.prototype.moveToClosestFutureEvent=function(p){this.moveToEvent(this.getClosestFutureEvent(p),p);};DataLayer.prototype.moveToEventWithId=function(event_id){if(arguments.length<2)this.moveToEvent(this.getEvent(event_id));else this.moveToEvent(this.getEvent(event_id),arguments[1]);};DataLayer.prototype.moveToEvent=function(event){var p=event.p;var tempLayer=new DataLayer(this._map);if(arguments.length>=2){p=arguments[1];this._map.setCenter(new GLatLng((p.lat()+event.p.lat())/2,(p.lng()+event.p.lng())/2),0);while(1){var b=this._map.getBounds();if(b.contains(p)&&b.contains(event.p))this._map.setZoom(this._map.getZoom()+3);else{this._map.setZoom(this._map.getZoom()-2);break;}}tempLayer.add(new DynamicMarker(p,startIcon));tempLayer.add(new DynamicPolyline(Array(event.p,p),"#6699CC"));tempLayer.show();}else{this._map.setCenter(event.p);}this._focusMe(event);return tempLayer;};DataLayer.prototype.getEvent=function(event_id){for(var i=0;i<this._objs.length;++i){if(this._objs[i].eventId==event_id)return this._objs[i];}return null;};DataLayer.prototype._focusMe=function(o){if(this._objs[this._focusedIndex]==o){o.blur(this._map);o.focus(this._map);return;}if(this._focusedIndex!=-1)this._objs[this._focusedIndex].blur(this._map);for(var i=0;i<this._objs.length;++i){if(this._objs[i]==o){this._focusedIndex=i;o.focus(this._map);}}};var TYPE_MARKER=1;var TYPE_POLYLINE=2;DynamicOverlay.prototype.show=function(gmap){if(!this.isVisible){gmap.addOverlay(this.overlay);this.isVisible=true;}};DynamicOverlay.prototype.hide=function(gmap){if(this.isVisible){gmap.removeOverlay(this.overlay);this.isVisible=false;}};DynamicOverlay.prototype.isInBounds=null;DynamicOverlay.prototype.isVisible=false;DynamicOverlay.prototype._container=null;DynamicMarker.prototype=new DynamicOverlay();DynamicMarker.prototype.constructor=DynamicMarker;DynamicMarker.prototype.base=DynamicOverlay;DynamicMarker.prototype.isInBounds=function(bounds){return bounds.contains(this.p);};DynamicPolyline.prototype=new DynamicOverlay();DynamicPolyline.prototype.constructor=DynamicPolyline;DynamicPolyline.prototype.base=DynamicOverlay;DynamicPolyline.prototype.isInBounds=function(bounds){for(var i=0;i<this.points.length;++i)if(!bounds.contains(this.points[i]))return false;return true;};function DynamicOverlay(){}function DynamicMarker(point){this.type=TYPE_MARKER;this.p=point;this.icon=null;this.focusIcon=null;this.focusHandlers=Array();this.blurHandlers=Array();this._listener=null;if(arguments.length>1){this.icon=arguments[1];this.focusedIcon=arguments[1];}if(arguments.length>2)this.focusedIcon=arguments[2];if(arguments.length>3)this.focusHandlers=arguments[3];if(arguments.length>4)this.blurHandlers=arguments[4];this._createMarker=function(icon){if(this._listener!=null)GEvent.removeListener(this._listener);var o=new GMarker(this.p,icon);o._parent=this;this._listener=GEvent.addListener(o,"click",function(){GEvent.callback(o._parent,o._parent.clickEvent)();});return o;};this.type=TYPE_MARKER;this.overlay=this._createMarker(this.icon);this.addClickEvent=function(event_handler){this.clickHandlers.push(event_handler);};this.clickEvent=function(){this.focusThis();};this.focusThis=function(){this._container._focusMe(this);};this.focus=function(gmap){this.hide(gmap);this.overlay=this._createMarker(this.focusedIcon);this.show(gmap);for(var i=0;i<this.focusHandlers.length;++i){this.focusHandlers[i](this,gmap);}};this.blur=function(gmap){this.hide(gmap);this.overlay=this._createMarker(this.icon);this.show(gmap);for(var i=0;i<this.blurHandlers.length;++i){this.blurHandlers[i](this,gmap);}};this.distance=function(p){return p.distanceFrom(this.p);};}function DynamicPolyline(arr_p){this. points=arr_p;this. color;this. weight;this. opacity;if(arguments.length>1)this.color=arguments[1];if(arguments.length>2)this.weight=arguments[2];if(arguments.length>3)this.opacity=arguments[3];this.overlay=new GPolyline(this.points,this.color,this.weight,this.opacity);this.type=TYPE_POLYLINE;}