GMap2.prototype.plotMarkers=function(B,D,C){D=(D>0)?D:0;C=(C>0&&C>D)?C:B.length;for(var A=D;A<C;A++){this.addOverlay(B[A].marker())}};GMap2.prototype.setToBounds=function(D){var B=(D.getNorthEast().lat()+D.getSouthWest().lat())/2;var E=(D.getNorthEast().lng()+D.getSouthWest().lng())/2;var A=new GLatLng(B,E);var C=this.getBoundsZoomLevel(D,this.getSize())+1;map1.setCenter(A,Math.min(C,14))};var rankingsApp;var theMap;var contextmenu;var summaryBox;var nhbdMarkers;var nhbdPolys=[];var polyMgr;var geoHelper;var APPVERSION_BIGMAP=0;var APPVERSION_CITY=1;var NUM_SLICES=15;var POLY_COLOR="#0000ff";var POLY_WEIGHT=2;var POLY_OPACITY=0.5;var NUM_TILESERVERS=3;var TILESERVER_DNS_OFFSET=0;var walkScoreLayers="walkscore";function getBaseURL(A){return"http://histo.walkscore.com/1.0.0"}function initNationalPageComponents(){}function initCityPageComponents(){rankingsApp=new RankingsApp(APPVERSION_CITY)}function initBigmapPageComponents(){rankingsApp=new RankingsApp(APPVERSION_BIGMAP)}function RankingsApp(A){geoHelper=new GeoHelper();this.data=new Object();this.data.cityIndex=grabCityIndex();this.data.cities=grabCityData().cities;if(A==APPVERSION_CITY||A==APPVERSION_BIGMAP){summaryBox=new SummaryBox(this,A);theMap=initMap(A,this.getRegionBoundset());createContextMenu(theMap);polyMgr=new PolyManager(theMap,this.cityBounds(this.cityIndex()));this.data.nhbds=grabNhbdData().nhbds;this.data.nhbdIndex=grabNhbdIndex();cityMarkers=new CityMarkerController(theMap,this);polyMgr.init();if(this.nhbdIndex()!=-1){appEvents.fireEvent(null,"selectNhbd",[this.nhbdIndex()])}else{appEvents.fireEvent(null,"selectCity",[])}GEvent.addListener(theMap,"mousemove",mouseMove)}}RankingsApp.prototype.getRegionBoundset=function(){var C=[this.cityBounds(this.cityIndex())];var A=new GLatLngBounds(new GLatLng(C[0].getSouthWest().lat()-0.1,C[0].getSouthWest().lng()-0.1),new GLatLng(C[0].getNorthEast().lat()+0.1,C[0].getNorthEast().lng()+0.1));var D=this.data.cities.length;for(var B=0;B<D;B++){if(B!=this.data.cityIndex&&A.intersects(this.cityBounds(B))){C.push(this.cityBounds(B))}}return C};RankingsApp.prototype.cityIndex=function(A){return this.data.cityIndex};RankingsApp.prototype.cityCount=function(A){return this.data.cities.length};RankingsApp.prototype.cityPop=function(A){return this.data.cities[A].population};RankingsApp.prototype.cityName=function(A){return replaceAll(this.data.cities[A].name,"+","'")};RankingsApp.prototype.cityBounds=function(A){return this.data.cities[A].bounds};RankingsApp.prototype.cityCentroid=function(A){return this.data.cities[A].centroid};RankingsApp.prototype.cityScore=function(A){return this.data.cities[A].score};RankingsApp.prototype.nhbdIndex=function(A){return this.data.nhbdIndex};RankingsApp.prototype.nhbdCount=function(A){return this.data.nhbds.length};RankingsApp.prototype.nhbdPop=function(A){return this.data.nhbds[A].population};RankingsApp.prototype.nhbdName=function(A){return replaceAll(this.data.nhbds[A].name,"+","'")};RankingsApp.prototype.nhbdCentroid=function(A){return this.data.nhbds[A].centroid};RankingsApp.prototype.nhbdScore=function(A){return this.data.nhbds[A].score};RankingsApp.prototype.currentNhbd=function(){var A=polyMgr.currentNhbdIdx();if(A>=0&&A<this.data.nhbds.length){return this.data.nhbds[A].name}return""};function createContextMenu(A){contextmenu=document.createElement("div");contextmenu.className="context";contextmenu.style.visibility="hidden";contextmenu.innerHTML="<a href='javascript:getWalkScore()'>Get Walk Score</a><img src='http://www2.walkscore.com/images/crosshairs.gif'>";A.getContainer().appendChild(contextmenu);GEvent.addListener(A,"singlerightclick",function(C,D){clickedPixel=C;var B=C.x;var F=C.y;if(B>A.getSize().width-120){B=A.getSize().width-120}if(F>A.getSize().height-30){F=A.getSize().height-30}var E=new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(B+1,F+1));E.apply(contextmenu);contextmenu.style.visibility="visible"});GEvent.addListener(A,"click",function(){contextmenu.style.visibility="hidden"})}function getWalkScore(){var A=theMap.fromContainerPixelToLatLng(clickedPixel);polyMgr.update(A);var C=rankingsApp.currentNhbd();var B=rankingsApp.cityName(rankingsApp.cityIndex());var D="";if(C.length>1){D+=C+" neighborhood, "}D+=B;document.location="/get-score.php?street="+D+"&lat="+A.lat()+"&lng="+A.lng()}function initMap(A,B){suppressErrors();if(GBrowserIsCompatible()){map1=new GMap2(document.getElementById("map"),{mapTypes:[G_NORMAL_MAP,G_HYBRID_MAP]});map1.addControl(new GSmallMapControl());map1.addControl(new GMapTypeControl());map1.addControl(new GScaleControl());if(B&&B[0]){map1.setToBounds(B[0])}regionBoundset=B;if(A==APPVERSION_CITY||A==APPVERSION_BIGMAP){gridLayer1=new GTileLayer(new GCopyrightCollection("Walkscore"),1,17);gridLayer1.myFormat="png";gridLayer1.getTileUrl=CustomGetTileUrl;gridLayer1.getOpacity=function(){return 0.45};showLayers(map1,walkScoreLayers)}return map1}restoreErrors()}function SummaryBox(B,A){this.app=B;this.ver=A;appEvents.addListener("selectNhbd",this.showNhbd,this);appEvents.addListener("selectCity",this.showCity,this)}SummaryBox.prototype.showNhbd=function(A){var C=getBaseURL(A)+"/images/"+linkifyName(this.app.cityName(this.app.cityIndex()))+"/"+linkifyName(this.app.nhbdName(A))+".png";setHTML("sum-title","#"+(A+1)+" "+this.app.nhbdName(A));setHTML("sum-score","Walk Score: <strong>"+this.app.nhbdScore(A)+"</strong>");if(this.ver==APPVERSION_CITY){setStyle("sum-title","font-size: 14px;");setHTML("sum-pop","Population: <strong>"+this.app.nhbdPop(A)+"</strong>");var B=document.getElementById("sum-hist-img");if(B){B.src=C}}};SummaryBox.prototype.showCity=function(){idx=this.app.cityIndex();var B=getBaseURL(idx)+"/images/"+linkifyName(this.app.cityName(idx))+".png";setHTML("sum-title","#"+(idx+1)+" "+this.app.cityName(idx));setHTML("sum-score","Walk Score: <strong>"+this.app.cityScore(idx)+"</strong>");if(this.ver==APPVERSION_CITY){setStyle("sum-title","font-size: 18px;");setHTML("sum-pop","Population: <strong>"+this.app.cityPop(idx)+"</strong>");var A=document.getElementById("sum-hist-img");if(A){A.src=B}}};function CityMarkerController(D,E){this.markers=[];this.map=D;var A=E.cityCount();var C=E.cityIndex();for(var B=0;B<A;B++){if(B!=C){this.markers.push(new CityMarker(E.cityCentroid(B),B,"/rankings/"+linkifyName(E.cityName(B))))}}this.map.plotMarkers(this.markers)}function CityMarker(C,A,B){this.latlng=C;this.idx=A;this.gMarker=new GMarker(this.latlng);GEvent.bind(this.gMarker,"click",this,function(){document.location=B})}CityMarker.prototype.marker=function(){return this.gMarker};function linkifyName(A){A=replaceAll(A," ","_");return A}function unlinkifyName(A){A=replaceAll(A,"_"," ");return A}function GeoHelper(){}GeoHelper.prototype.stripParens=function(A){return A.slice(A.indexOf("(")+1,A.indexOf(")"))};GeoHelper.prototype.strToPoint=function(B){var A=B.split(" ");return new GLatLng(1*A[1],1*A[0])};GeoHelper.prototype.strToBounds=function(E){var C=this.stripParens(E);var B=C.split(",");var A=this.strToPoint(B[0]);var D=this.strToPoint(B[2]);return new GLatLngBounds(A,D)};GeoHelper.prototype.strToCentroid=function(E){var C=this.stripParens(E);var B=C.split(",");var A=this.strToPoint(B[0]);var D=this.strToPoint(B[2]);return new GLatLng((A.lat()+D.lat())/2,(A.lng()+D.lng())/2)};GeoHelper.prototype.strToPoly=function(E){var F=E.indexOf("(")+2;var C=E.slice(F,E.length-2);var B=C.split(",");var D=[];for(var A=0;A<B.length;A++){D.push(this.strToPoint(B[A]))}return new GPolyline(D,POLY_COLOR,POLY_WEIGHT,POLY_OPACITY)};function mouseMove(A){polyMgr.update(A)}function PolyManager(B,A){this.map=B;this.area=A;this.polys=[];this.polyToNhbd=[];this.nhbdToPolys=[];this.prevPoly=null;this.prevNhbd=-1;this.prevHSlice=-1;this.prevVSlice=-1;this.activeSet=[];appEvents.addListener("selectNhbd",this.showNhbd,this)}PolyManager.prototype.init=function(){for(var A=0;A<this.polys.length;A++){this.map.addOverlay(this.polys[A]);this.polys[A].hide()}this.buildSlices()};PolyManager.prototype.currentNhbdIdx=function(){return this.prevNhbd};PolyManager.prototype.indexPolys=function(A,B,D,H){var C=[];if(D==1){C.push(this.polys.length);this.polys.push(new GPolyline.fromEncoded({color:POLY_COLOR,weight:POLY_WEIGHT,opacity:POLY_OPACITY,points:A,levels:B,zoomFactor:32,numLevels:4}));this.polyToNhbd.push(H)}else{var G=A.split(" ");var F=B.split(" ");for(var E=0;E<D;E++){C.push(this.polys.length);this.polys.push(new GPolyline.fromEncoded({color:POLY_COLOR,weight:POLY_WEIGHT,opacity:POLY_OPACITY,points:G[E],levels:F[E],zoomFactor:32,numLevels:4}));this.polyToNhbd.push(H)}}this.nhbdToPolys.push(C);return C};PolyManager.prototype.buildSlices=function(){if(this.area.isEmpty()){alert("city bounds defined in wrong point order")}this.hSlices=[];this.vSlices=[];this.hSlicePolys=[];this.vSlicePolys=[];var K=this.area.getNorthEast().lat();var P=this.area.getNorthEast().lng();var H=this.area.getSouthWest().lat();var D=this.area.getSouthWest().lng();var I=P-D;var F=K-H;var B=I/NUM_SLICES;var A=F/NUM_SLICES;for(var J=0;J<NUM_SLICES;J++){var L=new GLatLngBounds(new GLatLng(H+A*J,D),new GLatLng(H+A*(J+1),P));var O=new GLatLngBounds(new GLatLng(H,D+B*J),new GLatLng(K,D+B*(J+1)));this.hSlices.push(L);this.vSlices.push(O);var C=[];var M=[];for(var G=0;G<this.polys.length;G++){if(L.intersects(this.polys[G].getBounds())){C.push(G)}if(O.intersects(this.polys[G].getBounds())){M.push(G)}}this.hSlicePolys.push(C);this.vSlicePolys.push(M)}};PolyManager.prototype.update=function(H){if(this.prevPoly!=null&&this.prevPoly.getBounds().contains(H)&&this.prevPoly.contains(H)){return }var E=null;var F=null;for(var C=0;C<NUM_SLICES;C++){if(this.hSlices[C].contains(H)){E=C}if(this.vSlices[C].contains(H)){F=C}}if(E==null||F==null){this.deselectAll();return }if(E!=this.prevHSlice||F!=this.prevVSlice){this.prevHSlice=E;this.prevVSlice=F;var G=this.hSlicePolys[E];var I=this.vSlicePolys[F];if(I.length>G.length){var D=G;G=I;I=D}this.activeSet=[];for(var C=0;C<G.length;C++){for(var B=0;B<I.length;B++){if(G[C]==I[B]){this.activeSet.push(G[C])}}}}for(var C=0;C<this.activeSet.length;C++){var A=this.polys[this.activeSet[C]];if(A.getBounds().contains(H)&&A.contains(H)){this.prevPoly=this.polys[this.activeSet[C]];this.showNhbdInternal(this.polyToNhbd[this.activeSet[C]]);appEvents.fireEvent(null,"selectNhbd",[this.polyToNhbd[this.activeSet[C]]]);return }}this.deselectAll()};PolyManager.prototype.showNhbdInternal=function(B){if(this.prevNhbd!=-1){var A=this.nhbdToPolys[this.prevNhbd];for(var C=0;C<A.length;C++){this.polys[A[C]].hide()}}var A=this.nhbdToPolys[B];for(var C=0;C<A.length;C++){this.polys[A[C]].show()}this.prevNhbd=B};PolyManager.prototype.showNhbd=function(A){if(A!=this.prevNhbd&&A>-1&&A<this.nhbdToPolys.length){this.showNhbdInternal(A)}};PolyManager.prototype.deselectAll=function(){if(this.prevNhbd!=-1){var A=this.nhbdToPolys[this.prevNhbd];for(var B=0;B<A.length;B++){this.polys[A[B]].hide()}this.prevNhbd=-1;this.prevPoly=null;appEvents.fireEvent(null,"selectCity",[])}};GPolygon.prototype.contains=function(J){var C=0;var H=false;var I=J.lng();var F=J.lat();var E=this.getVertexCount();for(var D=0;D<E;D++){C++;if(C==E){C=0}var A=this.getVertex(D).lat();var B=this.getVertex(D).lng();var G=this.getVertex(C).lat();if(((A<F)&&(G>=F))||((G<F)&&(A>=F))){if(B+(F-A)/(G-A)*(this.getVertex(C).lng()-B)<I){H=!H}}}return H};GPolyline.prototype.contains=GPolygon.prototype.contains;function showLayers(C,B){gridLayer1.myLayers=B;var D=[G_NORMAL_MAP.getTileLayers()[0],gridLayer1];var A=[G_SATELLITE_MAP.getTileLayers()[0],G_HYBRID_MAP.getTileLayers()[1],gridLayer1];streetMapType=new GMapType(D,G_SATELLITE_MAP.getProjection(),"Streets",G_SATELLITE_MAP);hybridMapType=new GMapType(A,G_SATELLITE_MAP.getProjection(),"Satellite",G_SATELLITE_MAP);C.removeMapType(C.getMapTypes()[0]);C.addMapType(streetMapType);C.removeMapType(C.getMapTypes()[0]);C.addMapType(hybridMapType)}function BboxFromMap(){var A=map1.getBounds();var B=[A.getSouthWest().x,A.getSouthWest().y,A.getNorthEast().x,A.getNorthEast().y];return B.join(",")}var FORMAT_DEFAULT="image/png";function dd2MercMetersLng(A){return A*20037508.34/180}function dd2MercMetersLat(B){var A=Math.log(Math.tan((90+B)*Math.PI/360))/(Math.PI/180);A=A*20037508.34/180;return A}function CustomGetTileUrl(A,C){var B="http://tilecache.walkscore.com.s3.amazonaws.com/1.0.0/ws/";return B+C+"/"+A.x+"/"+A.y+".png"}function customOpacity(){return this.myOpacity}function showWalkscoreAt(C){var B="&";var A=C.split("?");if(A.length!=5){alert("celeb location missing data: "+C)}document.location="/get-score.php?street="+A[0]+B+"loc="+A[1]+B+"lat="+A[4]+B+"lng="+A[3]};