//(c) copyright 2009 veloroutes.org

var city="",cityZip="98102",startLat=40.580585,startLng=-97.646484,mapCity=city,mapState="",dirCity=city,dirState=mapState;function moveMapTo(a,b,c,d){a.setCenter(new GLatLng(b,c),d);window.setTimeout(function(){a.panTo(new GLatLng(b,c))},100)}function showCrossHair(){if(!this.recording){var a=this.map.getCenter();this.centericon&&map.removeOverlay(centericon);this.centericon=new GMarker(a,this.crosshairicon);map.addOverlay(centericon)}} function onLoad(a,b,c){if(a!=true)try{window.setTimeout(function(){loadWeather()},100)}catch(d){}if(GBrowserIsCompatible()){var e=new GControlPosition(G_ANCHOR_BOTTOM_RIGHT,new GSize(7,20)),f=new GMap2(document.getElementById("map"),{googleBarOptions:{style:"new",adsOptions:{client:"pub-0412558566882978",channel:"3025713117",adsafe:"high",language:"en"}},draggableCursor:"crosshair",draggingCursor:"crosshair"});this.map=f;adsManager=new GAdsManager(f,"pub-0412558566882978",{maxAdsOnMap:2,style:"adunit", client:"partner-pub-0412558566882978"});adsManager.enable();f.enableGoogleBar();if(!c){f.addMapType(G_PHYSICAL_MAP);addExtraMaps(f)}if(f!=null){GEvent.addListener(f,"load",function(){showCrossHair()});f.addControl(new GLargeMapControl);f.addControl(new GMapTypeControl);f.addControl(new GOverviewMapControl);f.addControl(new GScaleControl);f.enableScrollWheelZoom();this.crosshairicon=new GIcon;crosshairicon.image="/images/crosshair1.png";crosshairicon.shadow="";crosshairicon.iconSize=new GSize(15, 15);crosshairicon.shadowSize=new GSize(0,0);crosshairicon.iconAnchor=new GPoint(7,7);crosshairicon.infoWindowAnchor=new GPoint(7,7);initClickHandling(f);f.enableContinuousZoom();if(!loadRouteFromURL(location.href))if(loadMapStateFromURL(location.href)){window.setTimeout(function(){b||loadRoutes()},200);window.setTimeout(function(){b||loadMarkers()},300)}else{moveMapTo(f,startLat,startLng,a?4:11);window.setTimeout(function(){b||loadRoutes()},100);window.setTimeout(function(){b||loadMarkers()},100)}GEvent.addListener(f, "moveend",function(){var g=f.getCenter();document.getElementById("latLong").innerHTML="latitude, longitude @ center: "+g.lat().toFixed(6)+", "+g.lng().toFixed(6);showCrossHair()});a=f.getCenter();if(a!=null&&a.lat)document.getElementById("latLong").innerHTML="latitude, longitude @ center of map: "+a.lat().toFixed(6)+", "+a.lng().toFixed(6);if(getElem("localonly")!=null)getElem("localonly").checked=true;this.localSearch=true;if(!c)document.getElementById("elevation").value="-"}}else alert("Either your browswer can't handle Google Maps, or my google API key is wrong...")} function panToSite(a,b){if(this.map==null)GLog.write("ERROR! (map is null)");else{map.setCenter(new GLatLng(a.y,a.x),b);window.setTimeout(function(){map.panTo(new GLatLng(a.y,a.x))},1E3)}}function newRoutesOverlay(){var a=new GGeoXml("http://veloroutes.org/rss/geo.cgi?k=1");if(GBrowserIsCompatible()){var b=new GMap2(document.getElementById("map"));b.addControl(new GLargeMapControl);b.setCenter(new GLatLng(42.496675,-62.65625),3);b.addControl(new GLargeMapControl);b.addOverlay(a)}} function initClickHandling(a){this.map=a;this.route=[];this.recording=false;toggleRecording();if(a=document.getElementById("recording"))a.checked="checked";if(a=document.getElementById("metric"))a.checked=useMetric;if(a=getElem("eleUnit"))a.value=distUnit;if(a=document.getElementById("saveRoute"))a.disabled=true;if(a=document.getElementById("clearRoute"))a.disabled=true;if(a=document.getElementById("deleteLastPoint"))a.disabled=true;if(a=getElem("centerOnClick"))a.checked=false;this.recenterOnClick= false;if(a=getElem("useScrollWheel"))a.checked="checked";this.useScrollWheel=true} function loadRouteJSON(a){try{var b=getElem("json").innerHTML;if((b=eval("("+b+")"))&&b.route){this.route=b.route;var c=b.route.gain,d=b.route.oGain;if(c!=null&&d!=null){this.totalEleGain=parseFloat(c);this.origEleGain=parseFloat(d)}else this.origEleGain=this.totalEleGain=0;this.totalDist=parseFloat(b.route.dist);setVal("feedbackBar",buildSpeedAvgs(this.totalDist));loadRouteFromString(b.route.pts.split("|"),routeColor,0.75,true);var e=b.route.ele.split(",");loadElevationGraphFromString(e);a||loadMileMarkers()}else dbg("no route json-data?!")}catch(f){alert("Error loading route: "+ f)}} function toggleUseMetric(){this.useMetric=!this.useMetric;var a=getElem("elevation").value;this.lastEle=a;if(this.useMetric){distUnit=" km";speedUnit=" kph";eleUnit="m";metricRatio=1.609344;footRatio=0.3048;feetInMile=1E3;if(a>0)getElem("elevation").value=myParseFloat(lastEle*footRatio)}else{distUnit=" mi";speedUnit=" mph";metricRatio=1;feetInMile=5280;if(a>0)getElem("elevation").value=myParseFloat(lastEle/footRatio);footRatio=1;eleUnit="ft"}if(this.totalDist>0){getElem("totalDist").innerHTML=(totalDist* metricRatio).toFixed(2).toString()+" "+distUnit;setVal("feedbackBar",buildSpeedAvgs(this.totalDist))}getElem("eleUnit").innerHTML=eleUnit;this.elevationPts.length>0&&setVal("elevationGraph",buildElevationGraph(this.elevationPts,this.currElevation)+buildEleDetailsString())} function loadRouteFromURL(a){var b=getQuerystringParameter("route",a);if(b.length>0){this.currRouteID=b;this.recording=true;toggleRecording();if(b=document.getElementById("recording"))b.checked="";loadRouteJSON();getElem("export").disabled=false;if(getQuerystringParameter("c",a)){window.location=getGCue();return}return 1}return 0} function loadRouteFromString(a,b,c,d){c=[];this.route.length=0;var e=a.length>500,f=d;for(i in a)if(!e||i%4!=0){f=a[i].split(",");if(f.length==2){f=new GLatLng(parseFloat(f[0]),parseFloat(f[1]));c.push(f)}}if(d)if(c.length>0){a=c[0];a==null&&dbg("???lat=null");getElem("elevationGraph").innerHTML=""}if(c.length>0){this.currPolyline=new GPolyline(c,b,5,0.75);if(d==true){map.setCenter(c[0],13);map.clearOverlays();try{map.panTo(new GLatLng(parseFloat(c[0].y),parseFloat(c[0].x)));var g=new GMarker(c[0], createBikeIcon());map.addOverlay(g)}catch(h){}}map.addOverlay(this.currPolyline);b=this.currPolyline.getBounds();map.setZoom(map.getBoundsZoomLevel(b));map.setCenter(b.getCenter());this._route=c}} function loadElevationGraphFromString(a){try{getElem("elevationGraph").value="";this.maxGrade=this.lastElevation=this.currentElevation=this.currMinEle=this.currMaxEle=0;var b=[],c;this.elevationPts=[];b=this.currMaxEle=0;if(a.length>0){this.currMinEle=a[0];this.lastElevation=a[0]}for(c in a){b=a[c].toString().replace(",","");if(b!=""&&b!=null&&b>=0&&b!=NaN){b=parseFloat(b);if(b>this.currMaxEle)this.currMaxEle=b;if(b<this.currMinEle)this.currMinEle=b;if(b&&parseFloat(b)){this.currentElevation=parseFloat(b); buildEleDetailsString(true);this.ele=b.toFixed(1);this.elevationPts.push(b);this.lastElevation=this.currentElevation}}}}catch(d){alert("error building ele** graph: "+d)}showElevation(null,this.ele);getElem("elevationGraph").innerHTML+='<span class="smallText"><b>total elevation gain:</b> '+this.totalEleGain.toFixed(1)+" ft</span>&nbsp;(raw value: "+this.origEleGain.toFixed(1)+")"} function createPageLink(){var a=map.getCenter(),b=map.getZoom(),c=map.getCurrentMapType().getUrlArg();a=siteURL+"/?x="+a.lng().toFixed(5)+"&y="+a.lat().toFixed(5)+"&z="+b+"&t="+c;setVal("feedbackBar",'<span class="largeText">link: </span><a href="'+a+'">'+a+"</a>")} function loadMapStateFromURL(a){var b=parseFloat(getQuerystringParameter("y",a)),c=parseFloat(getQuerystringParameter("x",a)),d=parseInt(getQuerystringParameter("z",a));a=getQuerystringParameter("t",a);setVal("elevationGraph","");a=a=="m"?G_NORMAL_MAP:a=="k"?G_SATELLITE_MAP:a=="h"?G_HYBRID_MAP:a=="o"||a=="t"?WMS_TOPO_MAP:a=="n"?WMS_NEXRAD_MAP:a=="p"?G_PHYSICAL_MAP:G_NORMAL_MAP;getElem("localonly").checked=false;getElem("addrTB").value="";if(b){map.setCenter(new GLatLng(b,c),d,a);return 1}return 0} function saveRoute(){var a;try{var b=document.getElementById("routeName").value;if(b){document.getElementById("saveRoute").disabled=true;var c=getVal("routeTags"),d=getVal("routeComm"),e=createAjaxObj(),f="";for(point in this.route)f+=toFixedPrecision(route[point])+"|";var g="",h="";for(j in this.elevationPts)if((h=this.elevationPts[j])&&h!=null&&h!="")try{g+=parseFloat(this.elevationPts[j]).toFixed(3)+","}catch(j){}f=f.replace(/[\(\) ]/g,"");a="route_dist="+this.totalDist.toFixed(4).toString()+"&route_points="+ f+"&route_name="+b+"&route_tags="+c+"&route_comments="+d+"&ele_data="+g+"&ele_gain="+this.totalEleGain;var l=1;if(this.editMode==1&&this.currRouteID>0){a+="&route_id="+this.currRouteID;l=0}this.editMode=true;var m=0;e.open("POST","/cgi-bin/save_route3.cgi",true);e.onreadystatechange=function(){try{if(e.readyState==4)if(e.status==200||e.status==302||e.status==304){var k=e.responseXML;if(k&&k.getElementsByTagName("routeID").length==0)alert("Error saving route..."+e.status);else if(k){var n=k.getElementsByTagName("routeID")[0].firstChild.nodeValue; m=parseInt(n);setCurrID(n);setVal("saveRoute","update");var o=siteURL+"/r/"+n.toString();setVal("feedbackBar",'<span class="medText">route saved.</span> link:<br/> <a href="'+o+'">'+o+"</a><p/>The start city of your route will be automatically set, check the homepage.");fadeBlueToWhite("feedbackBar");getElem("export").disabled=false;var p=document.getElementById("asCue");if(p)p.disabled=false;l&&urchinTracker("/bikemaps/save")}else alert("Error! "+k)}else alert("There was a problem saving the route!\nError Code: "+ e.status)}catch(q){alert("Error saving data: "+q)}};setVal("feedbackBar",'<span class="largeText">saving route...</span>');e.send(a)}else alert("Enter a route name (use the textbox on the left side).")}catch(r){alert("ERROR saving route: "+r)}}function setCurrID(a){this.currRouteID=a} function clearRoute(){if(confirm("clear all current route points?")){map.clearOverlays();setVal("totalDist","");this.route=[];getElem("deleteLastPoint").disabled=true;getElem("saveRoute").disabled=true;getElem("clearRoute").disabled=true;setVal("saveRoute","save");setVal("feedbackBar",'<span class="medText">route cleared.</a>');fadeBlueToWhite("feedbackBar");getElem("elevationGraph").innerHTML="";getElem("elevationDetails").innerHTML="";this.totalEleGain=this.currentElevation=this.maxGrade=this.currMinEle= this.currMaxEle=0;this.lastElevation=null;this.elevationPts=[];this.route=[];this.currRouteID=this.totalDist=0}} function toggleRecording(){if(this.recording){this.recording=false;GEvent.clearListeners(map,"click");document.getElementById("saveRoute").disabled=true;document.getElementById("clearRoute").disabled=true;document.getElementById("deleteLastPoint").disabled=true}else{GEvent.addListener(map,"click",clickHandler);this.recording=true;if(this.route.length>0){document.getElementById("saveRoute").disabled=false;document.getElementById("clearRoute").disabled=false;document.getElementById("deleteLastPoint").disabled= false}}}function clickHandler(a,b){if(!a)if(b)if(route==null||route.length==0)startRoute(b);else if(route[route.length-1].x!=b.x||route[route.length-1].y!=b.y){route.push(b);addPointToRoute(route)}}function myParseFloat(a){if(!a)return 0;return parseFloat(a).toFixed(2)} function buildSpeedAvgs(a){var b=[];b.push((10*metricRatio).toFixed(1));b.push((13*metricRatio).toFixed(1));b.push((16*metricRatio).toFixed(1));b.push((19*metricRatio).toFixed(1));b.push((22*metricRatio).toFixed(1));var c="";for(spd in b){var d=(a*metricRatio/b[spd]).toFixed(4),e=d.toString().split(".");c+="at "+b[spd]+speedUnit+" ";c+=d!="0"&&a*metricRatio>=b[spd]?"<b>"+e[0]+" hr"+(e[0]==1?" ":"s ")+(e[1]*0.0060).toFixed(2)+" mins.</b><br>":"<b>"+(e[1]*0.0060).toFixed(2)+" min(s)</b><br>"}return c} function toggleRecenter(){this.recenterOnClick=!this.recenterOnClick} function startRoute(a){this.route=[];route.push(a);getElem("elevationGraph").innerHTML="";getElem("elevationDetails").innerHTML="";getElem("routeName").value="";getElem("routeComm").value="";getElem("routeTags").value="";this.currMaxEle=0;this.elevationPts=[];setVal("feedbackBar",'<span class="medText">route started.</span> remember to click save when done. Please note that when you save your route it will be available for anyone to view.');map.clearOverlays();this.totalEleGain=this.currElevation= this.lastElevation=this.currRouteID=this.currMaxEle=this.currMinEle=this.totalDist=0;addPointToRoute(route)} function addPointToRoute(a){getElem("saveRoute").disabled=false;getElem("clearRoute").disabled=false;var b=a.length-1,c;if(b>0){this.currSegDist=calcDist(a[b-1].lng(),a[b-1].lat(),a[b].lng(),a[b].lat());this.totalDist+=this.currSegDist;getElem("totalDist").innerHTML=(totalDist*metricRatio).toFixed(2).toString()+" "+distUnit;setVal("feedbackBar",buildSpeedAvgs(this.totalDist));c=new GPoint(a[b].lng(),a[b].lat())}else{getElem("totalDist").innerHTML="0 "+distUnit;c=new GPoint(a[0].lng(),a[0].lat())}this.recenterOnClick&& map.panTo(a[b]);drawPolyline(c);showElevation(a[b]);getElem("deleteLastPoint").disabled=false} function deleteLastPoint(){if(this.currMarker){map.clearOverlays();var a=this.route.length-1;if(a>0){var b=calcDist(route[a-1].lng(),route[a-1].lat(),route[a].lng(),route[a].lat());if(b>=0){this.totalDist-=b;setVal("totalDist",totalDist.toFixed(4)+" "+eleUnit);this.setVal("feedbackBar",buildSpeedAvgs(totalDist))}}route.pop();if(a>0){this.currPolyline=new GPolyline(route);drawPolyline(route[a-1],1);if(route.length>=1){a=new GMarker(route[0],createBikeIcon());map.addOverlay(a)}}a=this.elevationPts.length; if(a>=1){var c=this.elevationPts[a-1];if(a>1){b=this.elevationPts[a-2];b=c-b;this.totalEleGain-=b}}var d;if(a>0){this.elevationPts.pop();d=this.elevationPts.pop()}if(this.route.length>0){document.getElementById("saveRoute").disabled=false;if(this.route.length==1){document.getElementById("deleteLastPoint").disabled=true;this.totalGain=this.totalEleGain=0;this.lastElevation=this.currMaxEle=this.currMinEle=d}}else document.getElementById("deleteLastPoint").disabled=true;a>1&&showElevation(route[route.length- 1],d)}}function drawPolyline(a,b){var c=createBikeIcon();if(this.route.length==1){a=new GMarker(a,c);map.addOverlay(a);this.currMarker=a}getElem("getEle").disabled=true;getElem("getEle").disabled=false;a=[];route.length>1&&a.push(route[route.length-2]);a.push(route[route.length-1]);this.currPolyline=new GPolyline(b?route:a,routeColor,4,1);map.addOverlay(this.currPolyline)}function showElevation(a,b){this.done=false;getElevationGraph(a,"elevationGraph",b)} function getElevationGraph(a,b,c){try{if(c)buildEleGraph(c,true);else{var d=createAjaxObj();d.onreadystatechange=function(){if(d.readyState==4)if(d.status==200||d.status==302||d.status==304){var f=d.responseXML;if(!f||f.getElementsByTagName("string").length==0)getElem(b).value="ERROR: "+d.responseText;else{f=f.getElementsByTagName("string")[0].firstChild.nodeValue;if(f<0)f=0;buildEleGraph(f);urchinTracker("/bikemaps/elevation_query")}}else alert("There was a problem with the request: "+d.status)}}if(!c&& a){setVal("elevationDetails",'<img src="/images/loading.gif" alt="loading..."/ width="16" height="16"/> <b style="background:white;font-color:black;" class="medText">Loading elevation...');d.open("GET","/perl/get_elevation.cgi?latLong="+a.lat().toFixed(6)+","+a.lng().toFixed(6),true);d.send(null)}}catch(e){alert("Error building elevation graph: "+e)}this.done=true} function buildEleGraph(a,b){this.currElevation=a=parseFloat(a);var c="";if(a>currMaxEle)currMaxEle=a;else if(a<this.currMinEle)this.currMinEle=a;a&&elevationPts.push(a);if(elevationPts.length>0){if(elevationPts.length==1)this.currMinEle=a;c=buildElevationGraph(elevationPts,a)+buildEleDetailsString(b);getElem("elevationGraph").innerHTML=c}if(this.currElevation>0)this.lastElevation=this.currElevation} function buildEleDetailsString(a){if(this.totalEleGain==null)this.totalEleGain=0;if(this.maxGrade==null)this.maxGrade=0;var b=this.elevationPts.length,c="<br>",d=0;if(this.lastElevation!=null&&this.lastElevation!=0&&this.currElevation!=0)d=this.currElevation-this.lastElevation;if(d>0&&b>1)this.totalEleGain+=d;if(!a&&b>1){c+="<b>change:</b> "+parseInt(d*this.footRatio)+" "+eleUnit;c+=" <b>total gain:</b> "+parseInt(this.totalEleGain*footRatio)+" "+eleUnit}if(!a&&b>1){a=Math.abs(this.currElevation- this.lastElevation)/(this.currSegDist*this.feetInMile);a=parseInt(Math.tan(Math.asin(a))*100);if(a>this.maxGrade&&a<=30)this.maxGrade=a;c+=a<=30?" <b>grade:</b> "+a+"%":" <b>grade:</b> 30+%";if(this.maxGrade)c+=" <b>max grade:</b> "+parseInt(this.maxGrade)+"%"}return c}function buildElevationGraph(a,b){return buildGraph(a,100,b)} function buildGraphImage(){var a="http://veloroutes.org/cgi-bin/get_elevationgraph.cgi";if(this.currRouteID<=0){var b=this.elevationPts,c=b.length,d=null;d="smooth&min-m=true&max-m=true&upper="+parseInt(this.currMaxEle)+"&below-color=blue";a+="?type="+d+"&step="+(10).toString()+"&limits="+parseInt(this.currMinEle)+","+parseInt(this.currMaxEle)+"&height=150&dist="+this.totalDist.toFixed(2)+"&d=";for(i=0;i<c;i++)if(b[i]!=null)a+=i==0?parseInt(b[i]).toString():","+parseInt(b[i]).toString()}else{a+="?id="+ this.currRouteID;if(this.useMetric)a+="&m=1"}return a} function buildGraph(a,b,c){b="";getElem("elevationDetails").innerHTML='<span class="smallText"><b>min:</b> '+(this.currMinEle*footRatio).toFixed(1)+" "+eleUnit+" <b>max:</b> "+(this.currMaxEle*footRatio).toFixed(1)+" "+eleUnit+" <b>last:</b> "+(c*footRatio).toFixed(1)+" "+eleUnit+"&nbsp;&nbsp;&nbsp;<b>total dist:</b> "+(totalDist*metricRatio).toFixed(1)+" "+distUnit+'&nbsp;&nbsp;<b><a href="#" onclick=\'window.location="'+buildGraphImage()+'"\'>get elevation image</a>&nbsp;&nbsp;&nbsp;<a href="#" onclick="toggleEleGraph();">[close]</a></b></span><br/><br/>';if(a.length== 0)dbg("points list is empty.");else{var d,e=0;c=a.length;var f=4;if(c>=300)f=c>=350?2:3;var g=null;for(d=d=0;d<c;d++)if(a[d]!=null){if(g==null)g=this.route[d];e=Math.round(a[d]*100/currMaxEle);if(e<=0)e=1;b+=e==100?'<img align="bottom" src="/images/redline.png" width="'+(f+1)+'" height="'+0.5*e+'" >':'<img align="bottom" src="/images/blueline.png" width="'+f+'" height="'+0.5*e%100+'" >'}return b+"<br/>"}}function setMapCenter(a,b){this.map&&this.map.setCenter(new GLatLng(a,b))} function toggleEleGraph(){var a=getElem("_eleGraph");if(this.eleHidden){a.style.display="";a=getElem("showEle");a.style.display="none";this.eleHidden=false}else{a.style.display="none";a=getElem("showEle");a.style.display="";this.eleHidden=true}}function createBikeIcon(){if(!this.bikeIcon){var a=new GIcon;a.image="/images/bike_icon.png";a.iconSize=new GSize(18,14);a.iconAnchor=new GPoint(6,6);a.infoWindowAnchor=new GPoint(36,32);bikeIcon=a}return this.bikeIcon} function deleteMarker(a){var b=this.route[a];if(b){map.removeOverlay(b);route.splice(a,1)}}function calcDist(a,b,c,d){return 3963*Math.acos(Math.sin(b/57.2958)*Math.sin(d/57.2958)+Math.cos(b/57.2958)*Math.cos(d/57.2958)*Math.cos(c/57.2958-a/57.2958))} function getQuerystringParameter(a,b){var c="";b=new String(b);a=new String(a);a=a.toLowerCase();if(b.indexOf("?")>-1){b=b.split("?");if(b[1].length>0){b=b[1].split("&");for(i=0;i<=b.length-1;i++){var d=b[i],e=new String(b[i]);e=e.toLowerCase();e=e.split("=")[0];if(a==e){c=unescape(d.substr(e.length+1));break}}}}return c} function loadMileMarkers(){var a=0,b=0,c,d,e,f=0;f=0;for(var g=1;g<this._route.length;g++){if(f==100)break;c||(c=this._route[g-1]);d=this._route[g];b=calcDist(c.lng(),c.lat(),d.lng(),d.lat());a+=b;b=Math.floor(a);if(a-b<=0.19999999999999)if(b>0&&b!=e)if(f++%3==0){c=new GIcon;c.image="/images/markers/marker"+b+".png";c.iconSize=new GSize(32,36);c.infoWindowAnchor=new GPoint(32,36);c.iconAnchor=new GPoint(16,36);c=new GMarker(d,c);c!=null?this.map.addOverlay(c):dbg("marker was null.")}c=d;e=b}} function removeMileMarkers(){(new GMap2(document.getElementById("map"))).clearOverlays();this.loadRouteJSON(true)}function toggleMileMarkers(){this.showMileMarkers?removeMileMarkers():loadMileMarkers();this.showMileMarkers=!this.showMileMarkers}function toggleScrollWheel(){if(this.useScrollWheel)this.map?map.disableScrollWheelZoom():dbg("no map?");else this.map?map.enableScrollWheelZoom():dbg("no map?");this.useScrollWheel=!this.useScrollWheel} function getGCue(){var a=eval("("+getElem("json").innerHTML+")");this._route=a=a.route.pts.split("|");var b=this._route[0];b=this._route[a.length-2];var c="http://maps.google.com/maps?f=d&dirflg=w&q=from:",d=20;if(a.length<50)d=5;for(var e=0,f=parseInt(a.length/d),g;e<d;){g=a[e*f];c+=" "+g+" to: ";e++}c+=" "+b;if(this.useMetric)c+="&doflg=ptk";urchinTracker("/bikemaps/cuesheet");return c} function exportRoute(){var a=getElem("exportList");if(a)a=a.selectedIndex;else alert("?");if(a>=0){a=getElem("exportList")[a].text;if(a!=""&&this.currRouteID>0){if(a=="Simple"){window.location="http://veloroutes.org/s/"+this.currRouteID.toString();return;}if(a=="Google Earth (KML)")a="KML";if(a=="Spreadsheet (CSV)")a="CSV";if(a=="Garmin (TCX)")a="tcx";if(a=="Google Maps")a="gmaps";if(a=="Cuesheet (Google Maps)")window.location=getGCue();else{if(a=="Bing Maps")a="bing";window.location="http://veloroutes.org/cgi-bin/route_to_"+a.toLowerCase()+".cgi?route_id="+this.currRouteID}}}}var mkrList=[]; function getElevation(){var a=map.getCenter();getElevationAtLatLng(a,"elevation")} function getElevationAtLatLng(a,b){try{document.getElementById(b).value="loading...";document.getElementById("getEle").disabled=true;this.ajaxObj=createAjaxObj();ajaxObj.onreadystatechange=function(){if(ajaxObj.readyState==4){if(ajaxObj.status==200||ajaxObj.status==302||ajaxObj.status==304){var d=ajaxObj.responseXML;if(d.getElementsByTagName("string").length==0)document.getElementById(b).value="ERROR: "+ajaxObj.responseText;else{d=d.getElementsByTagName("string")[0].firstChild.nodeValue;if(d<0)d= "0.0";document.getElementById(b).value=parseInt(d*footRatio)}}else alert("There was a problem with the request: "+ajaxObj.status);document.getElementById("getEle").disabled=false}};ajaxObj.open("GET","/perl/get_elevation.cgi?latLong="+a.lat().toFixed(6)+","+a.lng().toFixed(6));ajaxObj.send(null)}catch(c){alert("ERROR getting elevation: "+c)}}function doIconSizeChange(a,b,c){}function getZoomIconMagicNum(a){var b=-16;if(a<=9){if(a<=4)b-=8;b-=2}return b+a} function geoCodeTable(a,b,c){var d=getLatLongTable(),e=new GIcon;if(c==0){e.image="/images/s_cam.png";e.iconSize=new GSize(27,31);e.infoWindowAnchor=new GPoint(27,31)}else if(c==1){e.image="/images/warning.png";e.iconSize=new GSize(11,11);e.infoWindowAnchor=new GPoint(11,11)}else if(c==2){e.image="/images/cycle_hill.png";e.iconSize=new GSize(25,25);e.infoWindowAnchor=new GPoint(25,25)}else if(c==3){e.image="/images/slr_cam.png";e.iconSize=new GSize(27,23);e.infoWindowAnchor=new GPoint(27,23)}else if(c== 4){e.image="/images/video.png";e.iconSize=new GSize(30,20);e.infoWindowAnchor=new GPoint(30,20)}else if(c==5){e.image="/images/graph.png";e.iconSize=new GSize(27,14);e.infoWindowAnchor=new GPoint(27,14)}e.iconAnchor=new GPoint(16,16);if(this.mkrList.length>0)this.mkrList=[];var f;for(var g in b){f=createWebCamMarker(d[g],g,b[g],e,c);this.mkrList.push(f);f!=null&&a.addOverlay(f)}}function showHideMarkers(){if(this.markersShown){this.map.clearOverlays();this.markersShown=false}else loadMarkers()} function loadMarkers(){this.markersShown=true;geoCodeTable(map,getWebCamData(),0);geoCodeTable(map,getWarningSites(),1);geoCodeTable(map,getHills(),2);geoCodeTable(map,getInfoData(),3);geoCodeTable(map,getVideos(),4);geoCodeTable(map,getHighPoints(),5)}function loadRoutes(){drawRoute(map,getNoGoRoutes(),badRouteColor,0.75);drawRoute(map,getTrails(),trailColor,1)}function drawRoute(a,b,c){for(var d in b)loadRouteFromString(b[d].toString().split("|"),c)} function hideShowInfoBar(){if(this.infoBarShown==false){this.infoBarShown=true;showInfoBar()}else{this.infoBarShown=false;hideInfoBar()}}function showInfoBar(){document.getElementById("infoBar").addChild(this.infoBarCopy)}function hideInfoBar(){var a=getElem("infoBar"),b=getElem("childDiv");a.removeChild(b);getElem("map").style.left="2px";getElem("map").style.width="100%"}function toggleLocalSearch(){this.localSearch=!this.localSearch} function createWebCamMarker(a,b,c,d,e){if(a==null||a=="null")return null;var f;if(e<2&&imgRegex.test(c))f='<HTML><IMG HEIGHT="300" WIDTH="320" SRC="'+c+'"></IMG></HTML>';else if(e==0)f='<HTML><A TARGET="about:blank" HREF="'+c+'">'+b+"</A>&nbsp;&nbsp;</HTML>";else if(e==1||e==4||e==5)f="<HTML>"+c+"</HTML>";else if(e==2||e==3)f="<HTML>"+c+"&nbsp;&nbsp;</HTML>";var g=new GMarker(a,d);GEvent.addListener(g,"click",function(){g.openInfoWindowHtml(f)});return g} function showKCMap(){var a=new TPhoto;a.id="king_county_bike_map";if(this.kcmap){this.kcmap=false;document.getElementById("kcmap").value="show";map.removeTPhoto(a)}else{map.clearOverlays();a.src="http://veloroutes.googlepages.com/King_County_North.jpg";a.percentOpacity=65;a.anchorTopLeft=new GLatLng(47.782481174472856,-122.4814224243164);a.anchorBottomRight=new GLatLng(47.38858773975688,-121.63169860839844);map.addTPhoto(a);document.getElementById("kcmap").value="hide";this.kcmap=true}} function showPugetSpeedMap(){var a=new TPhoto;a.id="speed_map";if(this.speedmap){this.speedmap=false;document.getElementById("speedmap").value="show";map.removeTPhoto(a)}else{a.src="/bikemaps/tiles/pugetspeed.png";a.percentOpacity=75;var b=new GLatLng(47.883197,-122.096558);panToSite(b,10);a.anchorTopLeft=new GLatLng(48.24525380784484,-122.50648498535156);a.anchorBottomRight=new GLatLng(47.469878,-121.661224);map.addTPhoto(a);document.getElementById("speedmap").value="hide";this.speedmap=true}} function showWASpeedMap(){var a=new TPhoto;a.id="waspeed_map";if(this.waspeedmap){this.waspeedmap=false;document.getElementById("waspeedmap").value="show";map.removeTPhoto(a)}else{a.src="/bikemaps/tiles/wa_speed_map.png";a.percentOpacity=55;var b=new GLatLng(47.23449,-120.509033);panToSite(b,7);a.anchorTopLeft=new GLatLng(49.04867,-124.881592);a.anchorBottomRight=new GLatLng(45.269088,-116.820374);map.addTPhoto(a);document.getElementById("waspeedmap").value="hide";this.waspeedmap=true}} function showSnohomishMap(){var a=new TPhoto;a.id="sno_county_bike_map";if(this.snomap){this.snomap=false;document.getElementById("snomap").value="show";map.removeTPhoto(a)}else{a.src="http://veloroutes.googlepages.com/snohomish_county.jpg";a.percentOpacity=75;a.anchorTopLeft=new GLatLng(48.263884,-122.401257);a.anchorBottomRight=new GLatLng(47.79286140021344,-121.91116333007812);panToSite(new GLatLng(48.04595573996009,-122.15423583984375),11);map.addTPhoto(a);document.getElementById("snomap").value= "hide";this.snomap=true}}function addExtraMaps(a){a.addMapType(WMS_TOPO_MAP);a.addMapType(WMS_NEXRAD_MAP);a.addControl(new RoutesControl)} function WMSGetTileUrl(a,b){var c=new GPoint(a.x*256,(a.y+1)*256);a=new GPoint((a.x+1)*256,a.y*256);c=G_NORMAL_MAP.getProjection().fromPixelToLatLng(c,b);b=G_NORMAL_MAP.getProjection().fromPixelToLatLng(a,b);a=this.transparent?"&TRANSPARENT=TRUE":"";return this.baseUrl+"?VERSION=1.1.1&REQUEST=GetMap&LAYERS="+this.layer+"&STYLES=&SRS=EPSG:4326&BBOX="+(c.lng()+","+c.lat()+","+b.lng()+","+b.lat())+"&WIDTH=256&HEIGHT=256&FORMAT="+this.format+"&BGCOLOR=0xCCCCCC&EXCEPTIONS=INIMAGE"+a} var WMS_TOPO_MAP=CreateMap("Elevation","Images by USGS / Service by TerraServer","http://www.terraserver-usa.com/ogcmap6.ashx","DRG","image/jpeg",false,4,17,[],"o"),WMS_NEXRAD_MAP=CreateMap("Radar","Data by NWS / Service by Iowa U. Ag. Dept.","http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi","nexrad-n0r","image/png",true,4,10,G_SATELLITE_MAP.getTileLayers(),"n"); function CreateMap(a,b,c,d,e,f,g,h,j,l){g=new GTileLayer(new GCopyrightCollection(b),g,h);g.baseUrl=c;g.layer=d;g.format=e;g.transparent=f;g.getTileUrl=WMSGetTileUrl;g.getCopyright=function(){return{prefix:"",copyrightTexts:[b]}};c=[];for(var m in j)c.push(j[m]);c.push(g);return new GMapType(c,G_SATELLITE_MAP.getProjection(),a,{errorMessage:false,urlArg:l})}function RoutesControl(){}RoutesControl.prototype=new GControl; RoutesControl.prototype.initialize=function(a){var b=document.createElement("div"),c=document.createElement("div");this.setButtonStyle_(c);b.appendChild(c);c.appendChild(document.createTextNode("Routes"));GEvent.addDomListener(c,"click",function(){a.clearOverlays();var d=new GGeoXml("http://veloroutes.org/rss/?n=100&l=1");a.addOverlay(d)});a.getContainer().appendChild(b);return b};RoutesControl.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(7,37))}; RoutesControl.prototype.setButtonStyle_=function(a){a.style.textDecoration="underline";a.style.color="#0000cc";a.style.backgroundColor="white";a.style.font="small Arial";a.style.border="1px solid black";a.style.padding="1px";a.style.marginBottom="2px";a.style.textAlign="center";a.style.width="6em";a.style.cursor="pointer"};


