var VGEO=function(){return{init:function(){try{VGEO.isApple=VGEO.getIsApple();if(!VGEO.isApple)VGEO.isBerry=VGEO.getIsBerry();if(!VGEO.isBerry&&!VGEO.isApple&&(!window.google||!google.gears)){var a=VGEO.getUA(),b="";if(a)if(a.match(/android|linux/i))b="linux";else if(a.match(/mac[\s\S]+safari/i))b="mac-safari";else if(a.match(/mac[\s\S]+firefox/i))b="mac-firefox";else if(a.match(/iemobile/i))b="wince";else if(a.match(/windows/i))b="win";VGEO.doUrch("/outgoing/googlegears/"+b);if(b!=""){if(confirm("Auto-location requires Google Gears."))location.href= "http://gears.google.com/?platform="+b}else if(confirm("Auto-location requires Google Gears."))location.href="http://gears.google.com/?action=install&return="+escape("http://veloroutes.org/m/lbs/")+"&icon_src="+escape("http://veloroutes.org/favicon.ico")+"&name="+escape(name)}if(VGEO.isApple)VGEO.geo=navigator.geolocation?navigator.geolocation:window.geolocation;else if(!VGEO.isBerry)if(!this.geo)if(google&&google.gears)VGEO.geo=google.gears.factory.create("beta.geolocation",null)}catch(c){alert("ERROR: "+ c);VGEO.doUrch("/m/lbs/init/error/",c)}},getIsBerry:function(){return window.blackberry},getIsApple:function(){var a=false,b=VGEO.getUA();if(b.match(/iphone/i)||b.match(/ipod/i))a=true;return a},getUA:function(){if(navigator)return navigator.userAgent;return""},doUrch:function(a,b){urchinTracker(a+(b?b.message.replace(/ /g,"+"):""))},getMyLocation:function(a){try{var b=VGEO.geo;if(b){function c(h){if(VGEO.isBerry){if(!blackberry.location.latitude||!blackberry.location.longitude)alert("Error: could not get GPS location."); VGEO.setCenter(blackberry.location.latitude,blackberry.location.longitude);blackberry.location.removeLocationUpdate()}else VGEO.setCenter(h.coords.latitude,h.coords.longitude)}function e(h){var f=VGEO.getElem("feedback");if(f)f.innerHTML="Error during geolocation: "+h.message}if(a)VGEO.term=a;var g=VGEO.getElem("feedback");if(g)g.innerHTML="Acquiring location...";a={gearsRequestAddress:true,enableHighAccuracy:false};if(VGEO.isApple)b&&b.getCurrentPosition(c,e);else if(VGEO.isBerry)if(blackberry.location.GPSSupported){blackberry.location.onLocationUpdate(c); blackberry.location.setAidMode(2);blackberry.location.refreshLocation()}else alert("Error: Your BlackBerry's GPS functionality must be enabled.");else if(b)b.getCurrentPosition(c,e,a);else{VGEO.setCenter(0,0);if(g)g.innerHTML="Error getting location."}}}catch(d){alert("Error updating location: "+d);VGEO.doUrch("/m/lbs/updateLocation/error",d)}},setSearchCenter:function(a){VGEO.getLS().setCenterPoint(a)},getLS:function(){if(!VGEO.ls && google.search){var a=new google.search.LocalSearch;a.setSearchCompleteCallback(VGEO, VGEO.searchCB);VGEO.ls=a}return VGEO.ls},doSearch:function(){var a=VGEO.getElem("sel");(a=a.options[a.selectedIndex])&&VGEO.setSearch(a.value)},setSearch:function(a){if(a.match(/bike/i))a="bicycle shop";else if(a.match(/food1/i))a="convenience store";else if(a.match(/food2/i))a="food";else if(a.match(/gas/i))a="gas station";else if(a.match(/hotel/i))a="lodging";VGEO.term=a;VGEO.getLS();VGEO.ls.execute(a)},searchCB:function(){var a="/images/",b=VGEO.term;a+=b&&b.match(/bicycle|bike/)?"bike":b&&b.match(/conven/)? "food":b&&b.match(/food/)?"rfood":b&&b.match(/gas/)?"gas":b&&b.match(/lodging/)?"hotel":b&&b.match(/coffee/)?"coffee":b&&b.match(/pizza/)?"pizza":"biz";a+=".png";b=0;var c="",e=VGEO.getElem("map_canvas");e.height=e.offsetHeight;e=new google.maps.LatLngBounds;e.extend(VGEO.currLoc);var g=VGEO.getLS();for(b in g.results){var d=g.results[b],h=new google.maps.LatLng(d.lat,d.lng);e.extend(h);var f=VGEO.calcDist(VGEO.currLoc.lat(),VGEO.currLoc.lng(),d.lat,d.lng);f=f?f.toFixed(1):"?";f='<div><a target="about:blank" href="'+ d.url+'">'+d.titleNoFormatting+"</a> ("+f+" miles)<br/>"+d.addressLines[0];var j=VGEO.currLoc.lat()+","+VGEO.currLoc.lng(),k=d.phoneNumbers[0].number;f+='<br/><a href="tel:'+k+'">'+k+"</a>";f+='<br/><a target="about:blank" href="http://maps.google.com/maps?f=d&dirflg=w&daddr='+escape(d.addressLines[0]+", "+d.addressLines[1])+"&saddr="+escape(j)+'">Directions</a>';f+='&nbsp;&nbsp;<a href="http://maps.google.com/maps?daddr='+escape(d.addressLines[0]+", "+d.addressLines[1])+"&saddr="+escape(j)+'">(by car)</a>'; f+="</div>";var l=new google.maps.InfoWindow({content:f}),i=new google.maps.Marker({position:h,title:d.titleNoFormatting+" @ "+d.addressLines[0]+" "+d.addressLines[1],map:VGEO.map,icon:a});if(!g.results||!g.results.length)c="No nearby services found.";google.maps.event.addListener(i,"click",function(){l.open(VGEO.map,i)});c+="<hr/>"+f;l.setPosition(i.position)}VGEO.map.fitBounds(e);e=VGEO.getElem("results");e.innerHTML=c},calcDist:function(a,b,c,e){if(a==c&&b==e)return 0;return 3963*Math.acos(Math.sin(b/ 57.2958)*Math.sin(e/57.2958)+Math.cos(b/57.2958)*Math.cos(e/57.2958)*Math.cos(c/57.2958-a/57.2958))},setCenter:function(a,b){if(!VGEO.map)VGEO.map=new google.maps.Map(VGEO.getElem("map_canvas"));var c=new google.maps.LatLng(a,b),e="<b>Your location</b>:<br/><b>Latitude:</b> "+c.lat()+"<br/><b>Longitude:</b> "+c.lng(),g=new google.maps.Marker({position:c,map:VGEO.map,icon:"/images/wifi.png",title:c.lat()+","+c.lng()}),d=new google.maps.InfoWindow({content:e});google.maps.event.addListener(g,"click", function(){d.open(VGEO.map,g)});VGEO.map.setCenter(c);VGEO.setSearchCenter(c);VGEO.currLoc=c;if(!VGEO.term)VGEO.term="bike shops";VGEO.setSearch(VGEO.term);if(c=VGEO.getElem("feedback"))c.innerHTML="Location: "+a+","+b;VGEO.doUrch("/m/lbs/geolocate")},isDef:function(a){return a!="undefined"&&a!="unknown"},getElem:function(a){return VGEO.isDef(typeof document.getElementById)?document.getElementById(a):VGEO.isDef(typeof document.all)?document.all[a]:null}}}();

