var Between={Loaders:[],addLoader:function(f){
this.Loaders.push(f);
},load:function(){
for(var i=0;i<this.Loaders.length;i++){
this.Loaders[i]();
}
this.Loaders=[];
},Unloaders:[],addUnloader:function(f){
this.Unloaders.push(f);
},unload:function(){
for(var i=0;i<this.Unloaders.length;i++){
this.Unloaders[i]();
}
this.Unloaders=[];
},debugging:false,tracker:null,trackConfigure:function(_5){
if(!this.debugging){
this.tracker=_gat._getTracker(_5);
this.tracker._setAllowLinker(true);
}
},trackPageview:function(){
if(this.tracker!=null&&!this.debugging){
this.tracker._trackPageview();
}else{
this.console("pageview: "+document.location);
}
},trackEvent:function(_6,_7,_8){
if(this.tracker!=null&&!this.debugging){
var u="/"+_6+"/"+_7+(_8?("?"+_8):"");
this.tracker._trackPageview(u);
}else{
this.console("event: cat="+_6+",act="+_7+(_8?",label="+_8:""));
}
},console:function(s){
if(console&&console.info){
console.info(s);
}
},ft_to_mi:function(ft){
return ft/5280;
},max:function(a,b){
return (a>b)?a:b;
},min:function(a,b){
return (a<b)?a:b;
},normalize:function(c){
while(c<0){
c+=360;
}
while(c>=360){
c-=360;
}
return c;
},denormalize:function(c){
while(c<-180){
c+=360;
}
while(c>=180){
c-=360;
}
return c;
}};
Between.Map=function(_12){
if(_12){
this.options=_12;
}else{
this.options={};
}
if(!this.options.mapid){
this.options.mapid="google-map";
}
this.gmap=null;
};
Between.Map.prototype.load=function(){
if(!GBrowserIsCompatible()){
return;
}
Between.InputWithDefault("address");
$("address").focus();
var _13=document.getElementById(this.options.mapid);
if(!_13){
return;
}
this.us_center={lat:42.52677220056902,lng:-71.773681640625};
this.us_zoom=3;
this.gmap=new GMap2(_13);
this.centerToDefault();
var _14="http://maps.google.com/mapfiles/ms/icons/";
this.locationIcon=Between.Icon(_14+"blue-dot.png");
this.betweenIcon=Between.Icon(_14+"green-dot.png");
this.searchIcon=Between.Icon(_14+"yellow-dot.png");
GSearch.getBranding(document.getElementById("branding"));
this.geocoder=new GClientGeocoder();
this.localSearcher=new GlocalSearch();
this.localSearcher.setResultSetSize(GSearch.SMALL_RESULTSET);
this.localSearcher.setSearchCompleteCallback(this,Between.Map.prototype.onLocalSearch);
this.locations=[];
this.localSearchResults=[];
this.GeoReasons={};
this.GeoReasons[G_GEO_SUCCESS]="Success";
this.GeoReasons[G_GEO_MISSING_ADDRESS]="Missing Address: The address was either missing or had no value.";
this.GeoReasons[G_GEO_UNKNOWN_ADDRESS]="Unknown Address: No corresponding geographic location could be found for the specified address.";
this.GeoReasons[G_GEO_UNAVAILABLE_ADDRESS]="Unavailable Address: The geocode for the given address cannot be returned due to legal or contractual reasons.";
this.GeoReasons[G_GEO_BAD_KEY]="Bad Key: The API key is either invalid or does not match the domain for which it was given";
this.GeoReasons[G_GEO_TOO_MANY_QUERIES]="Too Many Queries: The daily geocoding quota for this site has been exceeded.";
this.GeoReasons[G_GEO_SERVER_ERROR]="Server error: The geocoding request could not be successfully processed.";
this.gmap.addControl(new GLargeMapControl());
this.gmap.addControl(new GMapTypeControl());
this.gmap.addControl(new GScaleControl());
this.gmap.enableContinuousZoom();
this.addScrollWheel();
this.initializeElements();
};
Between.Map.prototype.unload=function(){
try{
GUnload();
}
catch(e){
}
};
Between.Map.prototype.reset=function(){
this.resetSearch();
this.gmap.clearOverlays();
};
Between.Map.prototype.resetSearch=function(){
document.getElementById("results").innerHTML="";
for(var i=0;i<this.localSearchResults.length;i++){
this.gmap.removeOverlay(this.localSearchResults[i].marker());
}
this.localSearchResults=[];
};
Between.Map.prototype.centerToDefault=function(){
this.gmap.setCenter(new GLatLng(this.us_center.lat,this.us_center.lng),this.us_zoom);
};
Between.Map.prototype.geocode=function(_16,f){
var obj=this;
Between.trackEvent("map","geocode");
this.geocoder.getLocations(_16,function(_19){
if(_19.Status.code==G_GEO_SUCCESS){
f(_19.Placemark[0]);
}else{
var _1a="Code "+_19.Status.code;
if(obj.GeoReasons[_19.Status.code]){
_1a=obj.GeoReasons[_19.Status.code];
}
Between.trackEvent("map","geocode-error");
alert("Could not find: \""+_16+"\"\n"+_1a);
}
});
};
Between.Map.prototype.between=function(){
var _1b=$("address");
var _1c=_1b.value;
if(_1c&&(_1c!=_1b.defaultValue)){
this.addLocation(_1c);
}else{
Between.trackEvent("map","geocode-empty");
}
};
Between.Map.prototype.addLocations=function(_1d){
var obj=this;
var _1f=_1d.shift();
if(_1f){
this.geocode(_1f,function(_20){
var _21=new Between.Location(_1f,_20);
Element.hide($("addresstip"));
var _22=_21.marker(obj.locationIcon);
obj.gmap.addOverlay(_22);
var _23=document.getElementById("locations");
_23.appendChild(_21.html());
obj.locations.push(_21);
var _24=document.getElementById("address");
_24.clear();
_24.focus();
obj.addLocations(_1d);
});
}else{
this.search();
}
};
Between.Map.prototype.addLocation=function(_25){
this.addLocations([_25]);
};
Between.Map.prototype.removeLocation=function(_26){
this.gmap.removeOverlay(_26.marker());
Element.remove(_26.element_id);
var _27=document.getElementById("address");
_27.focus();
_27.value=_26.rawinput();
_27.select();
this.locations.splice(this.locations.indexOf(_26),1);
this.search();
};
Between.Map.prototype.search=function(){
this.resetSearch();
if(this.locations.length>0){
var _28=this.computeCenter(this.locations);
var _29=new GLatLng(_28.lat,_28.lng);
this.placeCenterMarker(_29);
var _2a=this.computeZoom(this.computeSpans(_28,this.locations));
this.gmap.setCenter(_29,_2a);
this.searchAtCoordinate(_29);
}else{
this.removeCenterMarker();
this.centerToDefault();
Element.show($("addresstip"));
Element.show($("locationtip"));
}
this.updatePermalink();
};
Between.Map.prototype.searchAtCoordinate=function(_2b){
this.localSearcher.setCenterPoint(_2b);
var _2c=this.searchTerm();
Between.trackEvent("map","search","term="+_2c);
this.localSearcher.execute(_2c);
};
Between.Map.prototype.removeCenterMarker=function(){
this.gmap.removeOverlay(this.cmarker_);
this.cmarker_=null;
};
Between.Map.prototype.placeCenterMarker=function(_2d){
var obj=this;
if(this.cmarker_){
this.cmarker_.setPoint(_2d);
}else{
this.cmarker_=Between.Marker(_2d,{icon:this.betweenIcon,markup:"a.placebetween.us<br/>Drag me to refine results.",draggable:true,bouncy:true});
this.gmap.addOverlay(this.cmarker_);
GEvent.bind(this.cmarker_,"dragend",this,function(){
Between.trackEvent("map","drag");
obj.searchAtCoordinate(obj.cmarker_.getPoint());
});
}
};
Between.Map.prototype.searchTerm=function(){
searchInput=document.getElementById("search");
if(!searchInput.value){
searchInput.value="coffee";
}
return searchInput.value;
};
Between.Map.prototype.updatePermalink=function(){
searchInput=document.getElementById("search").value;
url=location.protocol+"//"+location.host+location.pathname+"?"+encodeURIPair("search",searchInput)+"&"+this.locations.map(function(e,i,arr){
return encodeURIPair("address"+(i+1),e.rawinput());
}).join("&");
document.getElementById("permalink").href=url;
};
Between.Map.prototype.initializeElements=function(){
var _32=location.search.toQueryParams();
var _33=/^address[0-9]+$/;
var obj=this;
var _35=[];
Object.keys(_32).sort().each(function(arg){
var _37=_32[arg];
if(arg=="search"){
document.getElementById("search").value=_37;
}else{
if(_33.test(arg)){
_35.push(_37);
}
}
});
if(_35.length>0){
Between.trackEvent("map","permalink");
this.addLocations(_35);
}
};
Between.Map.prototype.addScrollWheel=function(){
var obj=this.gmap;
function handle(_39){
if(_39<0){
obj.zoomOut();
}else{
obj.zoomIn();
}
}
function wheel(_3a){
var _3b=0;
if(!_3a){
_3a=window.event;
}
if(_3a.wheelDelta){
_3b=_3a.wheelDelta/120;
if(window.opera){
_3b=-_3b;
}
}else{
if(_3a.detail){
_3b=-_3a.detail/3;
}
}
if(_3b){
handle(_3b);
}
if(_3a.preventDefault){
_3a.preventDefault();
}
_3a.returnValue=false;
}
var div=this.gmap.getContainer();
GEvent.addDomListener(div,"DOMMouseScroll",wheel);
GEvent.addDomListener(div,"mousewheel",wheel);
};
Between.Map.prototype.scales={17:{miles:Between.ft_to_mi(200),pixels:69},16:{miles:Between.ft_to_mi(500),pixels:86},15:{miles:Between.ft_to_mi(1000),pixels:86},14:{miles:Between.ft_to_mi(2000),pixels:86},13:{miles:1,pixels:114},12:{miles:2,pixels:114},11:{miles:2,pixels:57},10:{miles:5,pixels:71},9:{miles:10,pixels:71},8:{miles:20,pixels:71},7:{miles:50,pixels:89},6:{miles:100,pixels:89},5:{miles:200,pixels:89},4:{miles:500,pixels:111},3:{miles:1000,pixels:111},2:{miles:2000,pixels:111},1:{miles:2000,pixels:55},0:{miles:5000,pixels:68}};
Between.Map.prototype.computeZoom=function(_3d){
var dim=Element.getDimensions(this.options.mapid);
var _3f=dim.height/2;
var _40=dim.width/2;
_3f-=20;
_40-=20;
lat_zoom=this.zoomForDimension(_3f,_3d.lat_span);
lng_zoom=this.zoomForDimension(_40,_3d.lng_span);
return (lat_zoom<lng_zoom)?lat_zoom:lng_zoom;
};
Between.Map.prototype.zoomForDimension=function(_41,_42){
for(var i=17;i>=0;--i){
var _44=(_41/this.scales[i].pixels)*this.scales[i].miles;
if(_42<_44){
return i;
}
}
return 0;
};
Between.Map.prototype.radiusOfEarthInMi=3960.718;
Between.Map.prototype.radiusOfEarthInKm=6372.795;
Between.Map.prototype.radiusOfEarthInNMi=3438.461;
Between.Map.prototype.radiusOfEarth=function(){
return this.radiusOfEarthInMi;
};
Between.Map.prototype.radians=function(d){
return d*Math.PI/180;
};
Between.Map.prototype.degrees=function(r){
return r*180/Math.PI;
};
Between.Map.prototype.distance=function(p1,p2){
var _49=this.radians(p1.lat);
var _4a=this.radians(p1.lng);
var _4b=this.radians(p2.lat);
var _4c=this.radians(p2.lng);
return (this.radiusOfEarth()*Math.acos((Math.sin(_49)*Math.sin(_4b))+(Math.cos(_49)*Math.cos(_4b)*Math.cos(_4c-_4a))));
};
Between.Map.prototype.lat_distance=function(p1,p2){
return this.distance(p1,{lat:p2.lat,lng:p1.lng});
};
Between.Map.prototype.lng_distance=function(p1,p2){
return this.distance(p1,{lat:p1.lat,lng:p2.lng});
};
Between.Map.prototype.computeSpans=function(_51,_52){
var _53=0;
var _54=0;
for(var i=0;i<_52.length;++i){
var _56=this.lat_distance(_51,_52[i]);
_53=Between.max(_56,_53);
var _57=this.lng_distance(_51,_52[i]);
_54=Between.max(_57,_54);
}
return {lat_span:_53,lng_span:_54};
};
Between.Map.prototype.computeCenter=function(_58){
if(_58.length==0){
return this.us_center;
}
var _59=0;
var _5a=360;
var _5b=0;
var _5c=360;
for(var i=0;i<_58.length;++i){
var _5e=_58[i];
var lat=Between.normalize(_5e.lat);
var lng=Between.normalize(_5e.lng);
_59=Between.max(_59,lat);
_5a=Between.min(_5a,lat);
_5b=Between.max(_5b,lng);
_5c=Between.min(_5c,lng);
}
var _61=this.averageAngle([_59,_5a]);
var _62=this.averageAngle([_5b,_5c]);
return {lat:Between.denormalize(_61),lng:Between.denormalize(_62)};
};
Between.Map.prototype.averageAngle=function(_63){
var _64=0;
var _65=0;
for(var i=0;i<_63.length;++i){
var _67=_63[i];
var r=this.radians(_67);
var x=Math.cos(r);
var y=Math.sin(r);
_64+=x;
_65+=y;
}
return this.degrees(Math.atan2(_65,_64));
};
Between.Map.prototype.computeWeightedCenter=function(_6b){
if(_6b.length==0){
return this.us_center;
}
var _6c=0;
var _6d=0;
for(var i=0;i<_6b.length;++i){
_6c+=Between.normalize(_6b[i].lat);
_6d+=Between.normalize(_6b[i].lng);
}
return {lat:Between.denormalize(_6c/_6b.length),lng:Between.denormalize(_6d/_6b.length)};
};
Between.Map.prototype.onLocalSearch=function(_6f,_70){
this.resetSearch();
if(this.localSearcher.results==null||this.localSearcher.results.length==0){
Element.show($("locationtip"));
return;
}
Element.hide($("locationtip"));
resultsElement=document.getElementById("results");
for(var i=0;i<this.localSearcher.results.length;i++){
var _72=new Between.LocalResult(this.localSearcher.results[i]);
this.gmap.addOverlay(_72.marker(this.searchIcon));
this.localSearchResults.push(_72);
resultsElement.appendChild(_72.html());
}
var _73=this.computeCenter(this.locations);
var _74=new GLatLng(_73.lat,_73.lng);
var _75=this.computeZoom(this.computeSpans(_73,[].concat(this.locations,this.localSearchResults)));
this.gmap.setCenter(_74,_75);
};
Between.Icon=function(url){
var _77=new GIcon();
_77.image=url;
_77.iconSize=new GSize(32,32);
_77.iconAnchor=new GPoint(16,32);
_77.infoWindowAnchor=new GPoint(9,2);
return _77;
};
Between.Marker=function(_78,_79){
var _7a=new GMarker(_78,_79);
if(_79.markup){
GEvent.bind(_7a,"click",this,function(){
_7a.openInfoWindow(_79.markup);
});
}
return _7a;
};
Between.LocalResult=function(_7b){
this.result_=_7b;
this.lat=parseFloat(this.result_.lat);
this.lng=parseFloat(this.result_.lng);
return this;
};
Between.LocalResult.prototype.marker=function(_7c){
if(this.marker_){
return this.marker_;
}
var _7d=Between.Marker(new GLatLng(this.lat,this.lng),{icon:_7c,markup:this.html()});
this.marker_=_7d;
return _7d;
};
Between.LocalResult.prototype.html=function(){
var _7e=document.createElement("div");
_7e.className="result gsc-result gsc-localResult";
_7e.appendChild(this.result_.html.cloneNode(true));
var _7f=this.location();
var _80=map.locations.map(function(_81){
saddr=_81.rawinput();
url="http://maps.google.com/maps?"+encodeURIPair("saddr",saddr)+"&"+encodeURIPair("daddr",_7f);
return "<a href='"+url+"'>"+_81.label()+"</a>";
});
var _82=document.createElement("div");
_82.className="directions";
_82.innerHTML="Directions from: "+_80.join(", ");
_7e.appendChild(_82);
return _7e;
};
Between.LocalResult.prototype.location=function(){
return (this.address()||this.coordinates());
};
Between.LocalResult.prototype.address=function(){
var _83=[];
var _84=["streetAddress","city","region","country"];
for(i=0;i<_84.length;i++){
if(this.result_[_84[i]]){
_83.push(this.result_[_84[i]]);
}
}
return _83.join(", ");
};
Between.LocalResult.prototype.coordinates=function(){
return [this.lat,this.lng].join(", ");
};
Between.Location=function(_85,_86){
this.rawinput_=_85;
this.place_=_86;
var _87=this.place_.Point.coordinates;
this.lat=_87[1];
this.lng=_87[0];
this.alt=_87[2];
this.id=Between.Location.NextId++;
this.element_id="location"+this.id;
return this;
};
Between.Location.NextId=1;
Between.Location.prototype.rawinput=function(){
return this.rawinput_;
};
Between.Location.prototype.label=function(){
var _88=64+this.id;
return String.fromCharCode(_88);
};
Between.Location.prototype.html=function(){
if(this.html_){
return this.html_;
}
row=document.createElement("tr");
row.id=this.element_id;
row.userLocation=this;
left=document.createElement("td");
left.vAlign="top";
left.className="label";
row.appendChild(left);
left.innerHTML=this.label();
middle=document.createElement("td");
middle.vAlign="top";
middle.className="address";
row.appendChild(middle);
middle.innerHTML=this.address();
right=document.createElement("td");
right.vAlign="top";
right.className="action";
row.appendChild(right);
var obj=this;
var r=document.createElement("a");
r.innerHTML="remove";
r.href="#";
r.className="remove";
r.title="Stop using this address to find a place between.";
r.onclick=function(){
map.removeLocation(obj);
return false;
};
right.appendChild(r);
this.html_=row;
return this.html_;
};
Between.Location.prototype.address=function(){
if(this.address_){
return this.address_;
}
function buildThoroughfare(_8b){
if(_8b&&_8b.ThoroughfareName){
return _8b.ThoroughfareName;
}else{
return null;
}
}
function buildLocality(_8c){
if(_8c){
var _8d=(_8c.LocalityName||"locality");
var _8e=buildThoroughfare(_8c.Thoroughfare);
if(_8e){
return _8e+"<br/>"+_8d;
}else{
return _8d;
}
}else{
return null;
}
}
function joiner(_8f,_90,_91){
if(_91==null){
_91=", ";
}
if(_8f){
return _8f+_91+_90;
}else{
return _90;
}
}
function buildSubAdministrativeArea(_92){
var _93=buildLocality(_92.Locality);
return _93;
}
function buildAdministrativeArea(_94){
var _95=null;
if(_94.SubAdministrativeArea){
_95=buildSubAdministrativeArea(_94.SubAdministrativeArea);
}else{
if(_94.Locality){
_95=buildLocality(_94.Locality);
}
}
return joiner(_95,_94.AdministrativeAreaName);
}
function buildRegion(_96){
var _97=null;
if(_96.AdministrativeArea){
_97=buildAdministrativeArea(_96.AdministrativeArea);
}else{
if(_96.Locality){
_97=buildLocality(_96.Locality);
}
}
return _97;
}
function buildCountry(_98){
var _99=null;
if(_98.CountryName){
_99=_98.CountryName;
}else{
if(_98.CountryNameCode){
_99=_98.CountryNameCode;
}
}
if(_99){
var _9a=buildRegion(_98);
return joiner(_9a,_99);
}else{
return null;
}
}
function buildAddressDetails(_9b){
var _9c=null;
if(_9b&&_9b.Country){
_9c=buildCountry(_9b.Country);
}
return _9c?_9c:"";
}
this.address_=buildAddressDetails(this.place_.AddressDetails);
return this.address_;
};
Between.Location.prototype.addressDetailsHtml=function(){
return this.rawinput_;
};
Between.Location.prototype.marker=function(_9d){
if(this.marker_){
return this.marker_;
}
this.marker_=Between.Marker(new GLatLng(this.lat,this.lng),{icon:_9d,markup:this.address()});
return this.marker_;
};
Between.InputWithDefault=function(_9e){
this.element=$(_9e);
Object.extend(this.element,Between.InputWithDefault.PreservationMethods);
this.element.initializeDefault();
};
Between.InputWithDefault.PreservationMethods={initializeDefault:function(){
if(this.value){
this.defaultValue=this.value;
}
Event.observe(this,"focus",this.clearDefault.bindAsEventListener(this));
Event.observe(this,"blur",this.replaceDefault.bindAsEventListener(this));
},clearDefault:function(ev){
if(this.value==this.defaultValue){
this.value="";
}
Element.removeClassName(this,"usingdefault");
},replaceDefault:function(ev){
if(this.defaultValue&&!this.value){
Element.addClassName(this,"usingdefault");
this.value=this.defaultValue;
}
}};
if(!Array.prototype.map){
Array.prototype.map=function(fn,obj){
var _a3=obj||window;
var a=[];
for(var i=0,j=this.length;i<j;++i){
a.push(fn.call(_a3,this[i],i,this));
}
return a;
};
}
function encodeURIPair(k,v){
return encodeURIComponent(k)+"="+encodeURIComponent(v);
}


