var map;var geocoder=null;var _overlayManager=new EventOverlayManager();var _mapManager=new MapManager();var _baseIcon=new GIcon();var _basePath;function initializeMapVars(){_basePath=$("basePath").value;_baseIcon.shadow=_basePath+"images/icons/00shadow.png";_baseIcon.iconSize=new GSize(20,32);_baseIcon.shadowSize=new GSize(40,35);
_baseIcon.iconAnchor=new GPoint(10,32);_baseIcon.infoWindowAnchor=new GPoint(12,3);}function EventOverlayManager(){this.LINE_COLOR="#FF0000";this.POLY_COLOR="#f33f00";this.LINE_WEIGHT=4;this.LINE_WEIGHT_HIGHLIGHT=4;this.POLY_COLOR_HIGHLIGHT="#17ACFD";this.LINE_COLOR_HIGHLIGHT="#0000FF";this.INFO_WIDTH=450;
this.INFO_HEIGHT=375;this.ALPHA_CHARS="ABCDEFGHIJKLMNOPQRSTUVWXYZ";var E=[];var A=0;var F=[];var B=0;var D;var C;this.getOverlays=function(){return E;};this.clearOverlays=function(){E=[];A=0;F=[];B=0;};this.getFitToPolygon=function(){return F;};this.highlightSidebarItem=function(G){};this.makeOverlayHtml=function(G,H,I){return this.createInfoWindowHtml(G,H,350,150);
};this.limitWithinMapBounds=function(){return false;};this.initialize=function(){this.clearOverlays();this.hideZoomedPolygons(3);this.infoWindowListener();GEvent.addListener(map,"zoomend",function(){_overlayManager.hideZoomedPolygons(1);});GEvent.addListener(map,"moveend",function(){_overlayManager.hideZoomedPolygons(2);
});};this.infoWindowListener=function(){GEvent.addListener(map,"infowindowclose",function(){if(this.getInfoWindow().isHidden()){_overlayManager.unhighlightOverlay();}});};this.createOverlays=function(I,G){for(var H=0;H<I.length;H++){var J=I[H];if((G===null)||(J.id!=G)){if(J.gtype=="point"){this.createMarker(H,J,I.length);
}else{if((J.gtype=="line")||(J.gtype=="polygon")){this.createPoly(H,J,I.length);}}}}this.hideZoomedPolygons(3);};this.hideZoomedPolygons=function(G){E.each(function(M,I){bounds=map.getBounds();if(M.type=="polygon"){var H=M.overlay;var K=true;var O=M.points;var L=O.length;for(var J=0;J<L;J++){var N=O[J];
if((bounds.contains(N))||((J+1<L)&&_overlayManager.intersectsMap(bounds,N,O[J+1]))){K=false;break;}}if(K){map.removeOverlay(H);}else{map.addOverlay(H);}}});};this.gLatLngToJSON=function(G){return'{"gtype":"point","lat":'+G.lat()+',"lng":'+G.lng()+"}";};this.markersToJSON=function(J,G){var I='{"gtype":"'+G+'","line":[';
for(var H=0;H<J.length;H++){I+=this.gLatLngToJSON(J[H].getPoint());if(H!=J.length-1){I+=",";}}I+="]}";return I;};this.polyToJSON=function(I,G){var J='{"gtype":"'+G+'","line":[';for(var H=0;H<I.getVertexCount();H++){J+=this.gLatLngToJSON(I.getVertex(H));if(H!=I.length-1){J+=",";}}J+="]}";return J;};this.createPoly=function(K,H,M){var N=[];
var O=H.geom.line;for(i=0;i<O.length;i++){var J=new GLatLng(O[i].lat,O[i].lng);N.push(J);if(isEmpty($("where").value)){this.updateFitToPolygon(J);}}var G=this.newPoly(N,H.geom.gtype);if(G){var I=this.makeOverlayHtml(K,H,M);var L=this.recordOverlay(G,I,H.gtype,H.id,N);this.addOverlayClickListener(L);if(H.gtype=="line"){map.addOverlay(G);
}}};this.updateFitToPolygon=function(G){if((this.limitWithinMapBounds()==false)){F[B]=G;B++;}};this.getMarkerIcon=function(){var H=String.fromCharCode("A".charCodeAt(0)+A);var G=new GIcon(_baseIcon);G.image=_basePath+"images/icons/"+H+".png";return G;};this.createMarker=function(I,L,M){this.updateFitToPolygon(new GLatLng(L.geom.lat,L.geom.lng));
markerIcon=this.getMarkerIcon();var H={icon:markerIcon};var G=new GMarker(new GLatLng(L.geom.lat,L.geom.lng),H);var J=this.makeOverlayHtml(I,L,M);G.bindInfoWindow(J);map.addOverlay(G);var K=this.recordOverlay(G,J,"point",L.id);this.addOverlayClickListener(K);};this.recordOverlay=function(G,H,J,L,I){var K=new overlayItem(G,H,J,L,I);
E[A]=K;A++;return K;};this.addOverlayClickListener=function(G){GEvent.addListener(G.overlay,"click",function(H){_overlayManager.unhighlightOverlay();map.openInfoWindowHtml(H,G.html);if(G.type!="point"){_overlayManager.highlightOverlay(G);}_overlayManager.highlightSidebarItem(G);});};this.highlightOverlay=function(G){var H=this.redrawOverlay(G,_overlayManager.LINE_WEIGHT_HIGHLIGHT,_overlayManager.LINE_COLOR_HIGHLIGHT,_overlayManager.POLY_COLOR_HIGHLIGHT);
G.isHighlighted=true;G.overlay=H;this.addOverlayClickListener(G);};this.redrawOverlay=function(J,K,L,G){var H=J.overlay;map.removeOverlay(H);var I=J.points;H=this.newPoly(I,J.type,K,L,G);map.addOverlay(H);return H;};this.unhighlightOverlay=function(){for(var G=0;G<E.length;G++){if(E[G].isHighlighted==true){E[G].overlay=this.redrawOverlay(E[G],_overlayManager.LINE_WEIGHT,_overlayManager.LINE_COLOR,_overlayManager.POLY_COLOR);
E[G].isHighlighted=false;this.addOverlayClickListener(E[G]);}}};this.newPoly=function(J,H,K,L,G){if(K==undefined){K=this.LINE_WEIGHT;}if(L==undefined){L=this.LINE_COLOR;}if(G==undefined){G=this.POLY_COLOR;}J=this.setPolyClosure(H,J);if(J!=null){if((H=="line")){var I=new GPolyline.fromEncoded({color:L,weight:K,points:this.encodePoly(J).points,levels:this.encodePoly(J).levels,zoomFactor:32,numLevels:4});
return I;}else{if(H=="polygon"){return new GPolygon(J,G,K,0.8,L,0.25);}}}return null;};this.setPolyClosure=function(G,H){if((G=="line")){if(this.GLatLngEquals(H[0],H[H.length-1])){H.pop(H[H.length-1]);}}else{if(G=="polygon"){if(!this.GLatLngEquals(H[0],H[H.length-1])){H.push(H[0]);}}}return H;};this.GLatLngEquals=function(H,G){if((H==null)||(G==null)){return false;
}else{return((H.lat()==G.lat())&&(H.lng()==H.lng()));}};this.intersectsMap=function(H,O,M){var J=new Line(O,M);var N=H.getSouthWest();var I=H.getNorthEast();var K=new GLatLng(I.lat(),N.lng());var L=new GLatLng(N.lat(),I.lng());var G=new Line(N,I);var P=new Line(K,L);return this.intersectsLine(J,G)||this.intersectsLine(J,P);
};this.intersectsLine=function(K,I){var H=new Point2D(K.v0.lng(),K.v0.lat());var G=new Point2D(K.v1.lng(),K.v1.lat());var L=new Point2D(I.v0.lng(),I.v0.lat());var J=new Point2D(I.v1.lng(),I.v1.lat());var M=intersectLineLine(H,G,L,J);return M.status=="Intersection";};this.fitToResults=function(){var H=new GPolyline(F);
var G;if(F.length>=2){G=map.getBoundsZoomLevel(H.getBounds());if(!isEmpty($("where").value)&&(G>map.getZoom())){G=map.getZoom();}}else{if(F.length==1){G=12;}}if(F.length>0){map.setZoom(G);map.setCenter(this.getBoundsCenter(H));}};this.getBoundsCenter=function(G){if(F==1){return F[0];}else{return G.getBounds().getCenter();
}};this.getOverlaysIndex=function(H){var G;for(G=0;G<E.length;G++){if(E[G].id==H){break;}}return G;};this.showEvent=function(J,I){var G=this.getOverlaysIndex(J);var H=G+I;if((H>=0)&&(H<E.length)){this.openMarker(H);}};this.openMarker=function(I){if(E[I].type=="point"){E[I].overlay.openInfoWindowHtml(E[I].html);
}else{var H=E[I].overlay;_overlayManager.unhighlightOverlay();var G=this.findClosestVertex(map.getCenter(),H);map.openInfoWindow(G,E[I].html);_overlayManager.highlightOverlay(E[I]);}this.highlightSidebarItem(E[I]);};this.createInfoWindowHtml=function(I,M,K,G){if(K==null||K=="null"||K==""){K=this.INFO_WIDTH;
}if(G==null||G=="null"||G==""){G="max-height:"+this.INFO_HEIGHT+"px;";}else{G="height:"+G+"px;";}var J='<div class="result inforesult wikitext" style="width:'+K+"px;"+G+'margin-bottom:10px">';if(M.flagged){J+='<a target="_top" class="errorLabel" href="/event/changehistory.htm?id='+M.id+'">Flagged! </a>';
}if(I!=null){var L=this.ALPHA_CHARS.substring(I,I+1);J+='<img alt="marker" style="margin-right:4px;" src="'+_basePath+"images/icons/"+L+"_label.png"+'"/>';}J+='<span class="summary">'+M.summary.escapeHTML()+"</span><br/>"+'<span class="when">'+M.when+"</span><br/>"+'<span class="where">'+M.where.escapeHTML();
if(!isEmpty(M.accy)){J+=" (Accuracy: "+_msg_accy[M.accy]+")";}J+="</span><br/>"+M.description;var H=M.tags.split(",");var N=new Array();H.each(function(O,P){var Q=O.gsub("'","%27");if(-1==document.location.pathname.indexOf("embedded")){N[P]='<a target="_top" href="" onclick="_mapManager.goToTag(\''+Q+"'); return false;\">"+O+"</a>";
}else{N[P]='<a target="_top" href="'+"/search/eventsearch.htm?_tag="+Q+"&_maptype="+_mapManager.getMapTypeIndex()+'">'+O+"</a>";}});J+='<div class="usertags"><b>Tags: </b>'+N.join(", ")+"</div>";J+='<span class="source"><b>Source: </b>'+M.source+"</span>";J+="</div>";return J;};this.encodePoly=function(G){var K,J,I,H,O,N,M,L;
M=[];L=[];O={x:0,y:0};N={x:0,y:0};for(K=0;G[K];K++){M[K]="B";O.x=(G[K].x*100000)<<1;O.y=(G[K].y*100000)<<1;N.x=O.x-N.x;N.y=O.y-N.y;N.x^=N.x>>31;N.y^=N.y>>31;L.push(N.y.toString(32));L.push(N.x.toString(32));N.x=O.x;N.y=O.y;}for(K=0;L[K];K++){I=[];for(J=0;L[K].charAt(J);J++){I[J]=String.fromCharCode(parseInt(L[K].charAt(J),32)+(J?95:63));
}L[K]=I.reverse().join("");}M=M.join("");L=L.join("");return{levels:M,points:L};};this.fitToPoly=function(J,I){if(I==null){I=false;}var H=J.getBounds();var G=map.getBoundsZoomLevel(H);if((G>map.getZoom())||(I==true)){map.setZoom(G);}};this.findClosestVertex=function(G,H){var K=9999999;var J=0;for(var I=0;
I<H.getVertexCount();I++){distance=G.distanceFrom(H.getVertex(I));if(distance<K){J=I;K=distance;}}return H.getVertex(J);};}function MapManager(){this.ACCURACY_TO_ZOOM=[4,5,7,10,11,12,13,14,15];this.ZOOM_BOX_THRESHOLD=10;this.ZOOM_COUNTRY=5;this.ZOOM_USA=4;this.ZOOM_WORLD=2;this.MAP_TYPES=[G_NORMAL_MAP,G_SATELLITE_MAP,G_HYBRID_MAP,G_PHYSICAL_MAP];
var A=new GPolyline([new GLatLng(86,-180),new GLatLng(-86,180)]);this.initializeMap=function(B){if(GBrowserIsCompatible()){initializeMapVars();map=new GMap2(document.getElementById("map"));map.addControl(new GMapTypeControl(1));map.addMapType(G_PHYSICAL_MAP);if((B==null)||(B=="null")){B=new GLargeMapControl();
}map.addControl(B);map.enableDoubleClickZoom();map.enableScrollWheelZoom();geocoder=new GClientGeocoder();GEvent.addDomListener(map.getContainer(),"DOMMouseScroll",this.wheelevent);map.getContainer().onmousewheel=this.wheelevent;this.setMapExtent();map.checkResize();}};this.showDefault=function(){if(null==map.getCenter()){var B=A.getBounds();
map.setCenter(B.getCenter());map.setZoom(map.getBoundsZoomLevel(B));}};this.setMapExtent=function(){var C=$("map").offsetTop;var B=this.getHeight()-C-28;$("map").style.height=B+"px";};this.getHeight=function(){var C=0,B=0;if(typeof (window.innerWidth)=="number"){C=window.innerWidth;B=window.innerHeight;
}else{if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){C=document.documentElement.clientWidth;B=document.documentElement.clientHeight;}else{if(document.body&&(document.body.clientWidth||document.body.clientHeight)){C=document.body.clientWidth;
B=document.body.clientHeight;}}}return B;};this.getWidth=function(){var B=0;if(typeof (window.innerWidth)=="number"){B=window.innerWidth;}else{if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){B=document.documentElement.clientWidth;}else{if(document.body&&(document.body.clientWidth||document.body.clientHeight)){B=document.body.clientWidth;
}}}return B;};this.goToTag=function(B){B=B.gsub("%27","'");var B=encodeURIComponent(B);document.location="/search/eventsearch.htm?_tag="+B+"&_maptype="+_mapManager.getMapTypeIndex();};this.getMapTypeIndex=function(){var B=0;for(i=0;i<this.MAP_TYPES.length;i++){if(this.MAP_TYPES[i].getName()==map.getCurrentMapType().getName()){B=i;
}}return B;};this.wheelevent=function(B){if(!B){B=window.event;}if(B.preventDefault){B.preventDefault();}B.returnValue=false;};this.adjustSidebar=function(){};}function overlayItem(A,B,D,E,C){this.overlay=A;this.html=B;this.type=D;this.id=E;this.isHighlighted=false;this.points=C;}function Line(B,A){this.v0=B;
this.v1=A;}function Point2D(A,B){this.x=A;this.y=B;}function Intersection(A){this.status=A;this.points=new Array();}intersectLineLine=function(E,C,I,H){var J;var F=(H.x-I.x)*(E.y-I.y)-(H.y-I.y)*(E.x-I.x);var G=(C.x-E.x)*(E.y-I.y)-(C.y-E.y)*(E.x-I.x);var D=(H.y-I.y)*(C.x-E.x)-(H.x-I.x)*(C.y-E.y);if(D!=0){var B=F/D;
var A=G/D;if(0<=B&&B<=1&&0<=A&&A<=1){J=new Intersection("Intersection");J.points.push(new Point2D(E.x+B*(C.x-E.x),E.y+B*(C.y-E.y)));}else{J=new Intersection("No Intersection");}}else{if(F==0||G==0){J=new Intersection("Coincident");}else{J=new Intersection("Parallel");}}return J;};function isEmpty(A){return((null==A)||(""==A));
}