TREKSEE=function(){function d(a){return typeof a==="string"?document.getElementById(a):a}function D(a,c,g){var j;j="";if(g!=undefined){j=new Date;j.setTime(j.getTime()+864E5*parseFloat(g));j="; expires="+j.toGMTString()}document.cookie=escape(a)+"="+escape(c||"")+j+"; path=/; domain="+N}function O(a){return(a=document.cookie.match(RegExp("(^|;) ?"+a+"=([^;]*)(;|$)")))?unescape(a[2]):null}function V(){function a(b){for(var e=0;e<p[x].latLngs[b].length;e+=1){var l=z.length+1;B[l].setPosition(p[x].latLngs[b][e]);
!E&&P?B[l].setVisible(true):B[l].setVisible(false);z.push(B[l])}}function c(b){if(b&&!E&&P||!b)for(var e=0;e<z.length;e++)z[e].setVisible(b)}function g(b,e){function l(m,o){var n=Math.PI/360;return 12756274*Math.atan2(Math.sqrt(n=Math.pow(Math.sin((o.lat()-m.lat())*n),2)+Math.cos(m.lat()*n*2)*Math.cos(o.lat()*n*2)*Math.pow(Math.sin((o.lng()-m.lng())*n),2)),Math.sqrt(1-n))}for(var s=0,f=b;f<e;f++)s+=l(k[f],k[f+1]);return s}function j(b){var e=k.length;F.setVisible(false);G.setVisible(false);if(e===
0)H.setPath([]);else{e===1&&H.setPath([]);F.setPosition(k[0]);F.setVisible(true);if(e>1){G.setPosition(k[e-1]);G.setVisible(true);H.setPath(k);Q=g(0,e-1);K=g(e-2,e-1);if(!b){b=e-1;var l=k[b-1],s=k[b],f;for(f in p){p[f].latLngs[b]=[];for(var m=t[f]*K,o=p[f].remainder[b-1]+m,n=Math.floor(o),v=1-p[f].remainder[b-1],u=0;u<n;u+=1){if(p[f].numMarkers>=R)break;var w=l.lat()+v/m*(s.lat()-l.lat()),W=l.lng()+v/m*(s.lng()-l.lng());p[f].latLngs[b].push(new google.maps.LatLng(w,W));p[f].numMarkers+=1;v+=1}p[f].remainder[b]=
o-n}a(e-1)}}}}function r(b){if(!(k.length>0&&k[k.length-1].equals(b))){k.push(b);j()}}function C(){if(k.length===0)return false;c(false);z=[];for(var b in p){p[b].remainder=[0];p[b].latLngs=[null];p[b].numMarkers=0}k=[];F.setVisible(false);G.setVisible(false);H.setPath([]);return true}function A(){function b(u){var w=u<<1;u=u<0?~w:w;for(w="";u>=32;){w+=String.fromCharCode((32|u&31)+63);u>>=5}w+=String.fromCharCode(u+63);return w}var e,l,s,f,m=0,o=0,n="";if(k.length<2)return null;for(var v=0;v<k.length;v++){e=
Math.floor(k[v].lat()*1E5);l=Math.floor(k[v].lng()*1E5);s=e-m;f=l-o;m=e;o=l;n+=b(s)+b(f)}return n}for(var t={mi:6.21371192E-4,km:0.0010},F=new google.maps.Marker({map:h,position:new google.maps.LatLng(0,0),clickable:false,visible:false,icon:new google.maps.MarkerImage("/static/markerstart2.png",new google.maps.Size(44,36),new google.maps.Point(0,0),new google.maps.Point(17,32),new google.maps.Size(44,36))}),G=new google.maps.Marker({map:h,position:new google.maps.LatLng(0,0),clickable:false,visible:false,
icon:new google.maps.MarkerImage("/static/markerend2.png",new google.maps.Size(44,36),new google.maps.Point(0,0),new google.maps.Point(7,32),new google.maps.Size(44,36))}),H=new google.maps.Polyline({map:h,clickable:false,strokeColor:"#3333FF",strokeOpacity:0.5,strokeWeight:6}),R=99,k=[],x="mi",Q=0,K=0,p={mi:{remainder:[0],latLngs:[null],numMarkers:0},km:{remainder:[0],latLngs:[null],numMarkers:0}},P=true,z=[],B=[],I=1;I<=R;I++)B[I]=new google.maps.Marker({map:h,position:new google.maps.LatLng(0,
0),clickable:false,visible:false,icon:new google.maps.MarkerImage("/static/m.png",new google.maps.Size(18,17),new google.maps.Point(18*(I-1),0),new google.maps.Point(8,17))});var E=h.getZoom()<12?true:false;return{addPoint:r,undoPoint:function(){if(k.length===0)return false;if(z.length!==0){for(var b=p[x].latLngs[k.length-1].length,e=0;e<b;e+=1)z.pop().setVisible(false);for(var l in p){p[l].remainder.pop();b=p[l].latLngs.pop().length;p[l].numMarkers-=b}}k.pop();j(true);return true},clearPath:C,flipPath:function(){var b=
k.slice(0).reverse();if(b.length<2)return false;C();for(var e=0;e<b.length;e+=1)r(b[e]);return true},setUnits:function(b){if(b!=x){x=b=="km"?"km":"mi";c(false);z=[];for(b=1;b<k.length;b+=1)a(b)}},getUnits:function(){return x},getPoints:function(){return k.slice(0)},getDistances:function(){if(k.length===0)return null;else if(k.length==1)return{dist:0,lleg:0};return{dist:t[x]*Q,lleg:t[x]*K}},hideDistanceMarkersOnZoom:function(){if(h.getZoom()>=12){E=false;c(true)}else{E=true;c(false)}},encodePath:function(){var b=
null,e="n",l=A();if(l){for(var s in J)if(J[s]==h.getMapTypeId()){e=s;break}b=x+e+l}return b},decodePath:function(b){var e,l,s=new google.maps.LatLngBounds;if(b.length<10)return false;x=b.substring(0,2)=="km"?"km":"mi";l=b.substring(2,3);e=J[l]||google.maps.MapTypeId.ROADMAP;a:{b=b.substring(3);for(var f,m,o,n=0,v=0,u=0,w=[];n<b.length;){o=m=0;do{f=b.charCodeAt(n++)-63;o|=(f&31)<<m;m+=5}while(f>=32);f=o&1?~(o>>1):o>>1;v+=f;o=m=0;do{f=b.charCodeAt(n++)-63;o|=(f&31)<<m;m+=5}while(f>=32);f=o&1?~(o>>1):
o>>1;u+=f;f=v*1.0E-5;m=u*1.0E-5;if(f>90||f<-90||m>180||m<-180){b=[];break a}w.push(new google.maps.LatLng(f,m))}b=w}if(!b)return false;k=[];for(n=0;n<b.length;n++){s.extend(b[n]);r(b[n])}h.setMapTypeId(e);h.fitBounds(s);d("n").className="treksee_button";d("s").className="treksee_button";d("h").className="treksee_button";d("p").className="treksee_button";d(l).className+=" treksee_button_selected";return true}}}function X(){function a(){window.clearTimeout(c);d("dbox").style.display="none";d("mbox").style.display=
"none";d("veil").style.display="none"}var c,g={labelOk:"ok",labelCancel:"cancel",onOk:function(){a()},onCancel:function(){a()}};return{say:function(j,r){a();d("mbox").innerHTML=j;d("mbox").style.display="block";c=window.setTimeout(function(){a()},r||5E3);return this},dlg:function(j,r){var C=r||{},A,t={};for(A in g)t[A]=g[A];for(A in C)t[A]=C[A];a();d("dbtnOk").style.display="none";d("dbtnCancel").style.display="none";d("veil").style.display="block";d("dbox").style.display="block";d("dmsg").innerHTML=
j;if(t&&t.noButtons)return this;d("dmsg").innerHTML+="<br/><br/>";d("dbtnOk").innerHTML=t.labelOk;d("dbtnOk").onclick=t.onOk;d("dbtnOk").style.display="block";if(t&&t.alert)return this;d("dbtnCancel").innerHTML=t.labelCancel;d("dbtnCancel").onclick=t.onCancel;d("dbtnCancel").style.display="block";return this},clr:a}}function y(){var a=q.getDistances(),c=" "+q.getUnits();if(a){d("dist").innerHTML=a.dist.toComma(a.dist>=1E3?0:2)+c;d("lleg").innerHTML=a.lleg.toComma(a.lleg>=1E3?0:2)+c}else{d("dist").innerHTML=
"&#8212;"+c;d("lleg").innerHTML="&#8212;"+c}d("address_input").blur()}function Y(){var a=d("address_input").value;/^\s*$/.test(a)?d("address_input").blur():S.geocode({address:a},function(c,g){if(g==google.maps.GeocoderStatus.OK){h.getZoom()<11&&h.setZoom(11);h.panTo(c[0].geometry.location);i.say("Centered at: "+c[0].formatted_address);d("address_input").value="";d("address_input").blur()}else i.say("Can't find that address. Perhaps you forgot the city or state?")})}function Z(){var a=q.getUnits()==
"mi"?"km":"mi";q.setUnits(a);y()}function $(a){h.setZoom(h.getZoom()+(a==="in"?1:-1));return false}function aa(){D("gojo_a","",-1);D("gojo_b","",-1);D("gojo_a",h.getCenter().lat(),3650);D("gojo_b",h.getCenter().lng(),3650);i.say("Home location set. You will start here the next time you visit.")}function T(){var a=O("gojo_a"),c=O("gojo_b");if(a&&c)return new google.maps.LatLng(a,c);return null}function ba(){var a=T();if(a){h.panTo(a);i.say("Centered at home location.")}else i.say("No home location is set. Click the 'set home' button to set a home location.")}
function ca(){var a=q.undoPoint();y();a||i.say("There's no path to undo! Click the map to draw a path.")}function da(){var a=q.clearPath();y();a?i.say("Path cleared. Click on the map to draw a path."):i.say("There's no path to clear! Click the map to draw a path.")}function ea(){function a(r){if(r>=0){q.addPoint(c[r]);y();window.setTimeout(function(){a(r-1)},200)}else d("invisiveil").style.display="none"}var c=q.getPoints(),g=new google.maps.LatLngBounds;if(c.length<2)i.say("There is no path to retrace! Click on the map to draw a path.");
else{d("invisiveil").style.display="block";for(var j=0;j<c.length;j++)g.extend(c[j]);h.fitBounds(g);window.setTimeout(function(){a(c.length-2)},1E3)}}function fa(){if(q.flipPath()){y();i.say("Path flipped.")}else i.say("There is no path to flip! Click on the map to draw a path.")}function ga(){function a(r){if(r<c.length){q.addPoint(c[r]);y();window.setTimeout(function(){a(r+1)},200)}else d("invisiveil").style.display="none"}var c=q.getPoints(),g=new google.maps.LatLngBounds;if(c.length<2)i.say("There is no path to play! Click on the map to draw a path.");
else{d("invisiveil").style.display="block";q.clearPath();y();for(var j=0;j<c.length;j++)g.extend(c[j]);h.fitBounds(g);window.setTimeout(function(){a(0)},1E3)}}function ha(){function a(j){return"<input onclick='select()' size='30' readonly='readonly' value='http://"+N+"/p/"+j+"'/>"}var c,g=q.encodePath();if(g)if(g.length>999)i.say("There are too many points in the path. Reduce the number of points and try again. ("+g.length+")");else if(c=L[g])i.dlg("Saved!<br/><br/>"+a(c),{alert:true});else{i.dlg("Saving...",
{noButtons:true});window.setTimeout(function(){microAjax("/s",function(j){L[g]=j;i.dlg("Saved!<br/><br/>"+a(j),{alert:true})},"m="+g)},1E3)}else i.say("There's no path to save! Click on the map to draw a path.")}function ia(a){i.dlg("Loading path...",{noButtons:true});microAjax("/l?m="+a,function(c){if(q.decodePath(c)){c=q.encodePath();L[c]=a;y();i.say("Path successfully loaded!")}else i.say("Path failed to load.")})}function ja(){var a="<b style='color:#555'>Feedback form</b><br/><br/>";a+="Do you have feedback?<br/>";
a+="Or have you found a bug?<br/>";a+="Please let me know!<br/><br/>";a+="<textarea id='bug' style='width:200px; height:60px'>";a+="</textarea>";i.dlg(a,{onOk:function(){var c=d("bug").value;c=c.replace(/^\s\s*/,"").replace(/\s\s*$/,"");c=encodeURIComponent(c);if(c=c.substring(0,2E3)){microAjax("/b",function(){},"m="+c);i.say("Thanks for providing feedback.")}else i.clr()}});d("bug").focus()}function ka(){window.scrollTo(0,1)}function M(){var a="376px";if(window.orientation==-90||window.orientation==
90)a="228px";d("map_canvas").style.height=a;window.setTimeout(ka,10)}function la(){var a={zoom:2,minZoom:2,center:new google.maps.LatLng(0,0),mapTypeId:google.maps.MapTypeId.ROADMAP,disableDefaultUI:true,scaleControl:true,draggableCursor:"default",draggingCursor:"default"};if(U){a.scaleControl=false;a.mapTypeControl=true;a.mapTypeControlOptions={style:google.maps.MapTypeControlStyle.DROPDOWN_MENU,position:google.maps.ControlPosition.LEFT_BOTTOM};a.zoomControl=true;a.zoomControlOptions={style:google.maps.ZoomControlStyle.SMALL,
position:google.maps.ControlPosition.RIGHT_BOTTOM}}h=new google.maps.Map(d("map_canvas"),a);S=new google.maps.Geocoder;i=X();q=V();y();google.maps.event.addListener(h,"click",function(c){i.clr();q.addPoint(c.latLng);y()});google.maps.event.addListener(h,"zoom_changed",function(){q.hideDistanceMarkersOnZoom(false)});if((a=window.location.pathname.match(/^\/p\/(.*)/))&&a[1].length>0)ia(a[1]);else{if(a=T()){h.setCenter(a);h.setZoom(13)}i.say("Click on the map to draw your path. The distance will be displayed above.",
3E4)}}var h,i,q,L={},S,U=false,N="treksee.com",J={n:google.maps.MapTypeId.ROADMAP,s:google.maps.MapTypeId.SATELLITE,h:google.maps.MapTypeId.HYBRID,p:google.maps.MapTypeId.TERRAIN};Number.prototype.toComma=function(a){a=this.toFixed(a).split(".");for(var c=a[0],g=/(\d)(\d\d\d\b)/;g.test(c);)c=c.replace(g,"$1,$2");return c+(a.length>1?"."+a[1]:"")};return{i:function(){if(navigator.userAgent.indexOf("iPhone")!=-1){U=true;window.setTimeout(M,1);google.maps.event.addDomListener(document,"touchstart",M);
google.maps.event.addDomListener(document.body,"orientationchange",M)}else if(!(navigator.userAgent.indexOf("Android")!=-1||navigator.userAgent.indexOf("iPad")!=-1))document.body.className="treksee_non_touch";window.setTimeout(la,100)},r:function(){if(h){var a=h.getCenter();google.maps.event.trigger(h,"resize");h.setCenter(a)}},m:function(a,c){h.setMapTypeId(J[c]||google.maps.MapTypeId.ROADMAP);d("n").className="treksee_button";d("s").className="treksee_button";d("h").className="treksee_button";d("p").className=
"treksee_button";a.className+=" treksee_button_selected";return false},f:function(a,c){var g={go:Y,su:Z,zm:$,gh:ba,sh:aa,un:ca,cl:da,re:ea,fl:fa,pl:ga,sv:ha,bg:ja};i.clr();if(g[a])g[a](c);else i.say("I'm sorry, Dave. I can't do that.");return false}}}();google.maps.event.addDomListener(window,"load",TREKSEE.i);google.maps.event.addDomListener(window,"resize",TREKSEE.r);

