Tooltip.prototype=new google.maps.OverlayView;function Tooltip(a){this.setValues(a);this.visible=false;this.div=null}Tooltip.prototype.setContent=function(a){this.set("content",a)};Tooltip.prototype.getContent=function(){return this.get("content")};Tooltip.prototype.open=function(a){if(this.div)this.div.style.visibility="visible";this.bindTo("position",a,"position");this.visible=true};
Tooltip.prototype.close=function(){if(this.div)this.div.style.visibility="hidden";this.unbind("position");this.visible=false};Tooltip.prototype.onAdd=function(){this.div=document.createElement("div");this.div.style.position="absolute";this.div.className="tooltip";this.div.style.visibility=this.visible?"visible":"hidden";this.getPanes().floatPane.appendChild(this.div)};
Tooltip.prototype.draw=function(){if(this.div){var a=this.get("position");if(a){a=this.getProjection().fromLatLngToDivPixel(a);var b=this.div;b.style.left=a.x+9+"px";b.style.top=a.y-50+"px";b.innerHTML=this.get("content")}}};Tooltip.prototype.onRemove=function(){this.div.parentNode.removeChild(this.div);this.div=null};Tooltip.prototype.changed=function(a){if(a=="position"||a=="content")this.draw()};
function ControlContainer(){this.controlDiv=document.createElement("div");this.controlDiv.className="gmap-control-container"}ControlContainer.prototype.addControl=function(a){this.controlDiv.appendChild(a.getDiv())};ControlContainer.prototype.setPosition=function(a,b){a.controls[b].push(this.controlDiv)};
function ButtonControl(a,b,c,d){if(arguments.length!=0){this.outer=document.createElement("div");this.outer.className="gmap-control-outer";this.setTitle(b);this.inner=document.createElement("div");this.inner.className="gmap-control-inner";this.setPushed(c);this.setText(a);this.inner.unselectable="on";if(typeof this.inner.onselectstart!="undefined")this.inner.onselectstart=function(){return false};else if(this.inner.style.UserSelect!==undefined)this.inner.style.UserSelect="none";else if(this.inner.style.MozUserSelect!==
undefined)this.inner.style.MozUserSelect="none";else if(this.inner.style.KhtmlUserSelect!==undefined)this.inner.style.KhtmlUserSelect="none";else if(this.inner.style.webkitUserSelect!==undefined)this.inner.style.webkitUserSelect="none";this.outer.appendChild(this.inner);google.maps.event.addDomListener(this.outer,"click",d)}}ButtonControl.prototype.getDiv=function(){return this.outer};ButtonControl.prototype.selectedBorderColor="#777 #ddd #ddd #777";ButtonControl.prototype.unselectedBorderColor="#ddd #777 #777 #ddd";
ButtonControl.prototype.setPushed=function(a){this.inner.style.fontWeight=a?"bold":"normal";this.inner.style.borderColor=a?this.selectedBorderColor:this.unselectedBorderColor};ButtonControl.prototype.setText=function(a){this.inner.innerHTML=a};ButtonControl.prototype.setTitle=function(a){this.outer.title=a};
var myNC={isPushed:false,radius:10,showCircle:false,initialize:function(){this.button=new ButtonControl("Nearest","Find out which clubs are nearest to a location",false,function(){myNC.buttonPushed()});this.button.outer.style.position="absolute";this.divWrapper=document.createElement("div");this.divWrapper.appendChild(this.button.getDiv())},getDiv:function(){return this.divWrapper},buttonPushed:function(){if(this.isPushed=!this.isPushed){if(this.optionsDiv){this.optionsDiv.insertBefore(this.instructions,
this.optionsDiv.firstChild);this.optionsDiv.style.visibility="visible"}else{this.optionsDiv=document.createElement("div");this.optionsDiv.style.marginTop=this.button.outer.offsetHeight+"px";this.optionsDiv.className="gmap-control-nearest";this.optionsDiv.innerHTML='<form id="nearestForm" onsubmit="return false;"><p>Show circle <input id="circle" name="circle" type="checkbox" onclick="myNC.setShowCircle(this.checked);"/> radius <input id="radius" name="radius" value="10" type="text" size="3" maxlength="3" onchange="myNC.radiusChanged(this);"/> mi</p></form>';
this.instructions=document.createElement("p");this.instructions.innerHTML="Click on the map to sort clubs by distance from that point.";this.optionsDiv.insertBefore(this.instructions,this.optionsDiv.firstChild);this.divWrapper.appendChild(this.optionsDiv)}myMap.enableNearest()}else{this.optionsDiv.style.visibility="hidden";myMap.disableNearest()}this.button.setPushed(this.isPushed)},setShowCircle:function(a){this.showCircle=a;myMap.showNearestCircle(a)},radiusChanged:function(a){var b=a.value.replace(/^[\s0]*/,
"").replace(/\s*$/,"");if(b.match(/^\d+$/)){this.radius=a.value=b;myMap.nearestCircleRadiusChanged(b)}else{a.value=this.radius;alert("Invalid value for miles entered")}},markerDropped:function(){this.optionsDiv.firstChild==this.instructions&&this.optionsDiv.removeChild(this.instructions)}},myMap={map:null,mouseover:function(a){this.map&&this.openTooltip(a)},markerMouseover:function(a){this.mouseover(a.idx)},nearestMarkerMouseover:function(){this.lazyTooltip();this.tooltip.setContent(this.nearestMarker.tooltip);
this.tooltip.open(this.nearestMarker)},mouseoutFunction:function(){myMap.mouseout()},mouseout:function(){this.tooltip&&this.tooltip.close()},click:function(a){this.map&&this.openInfoWindow(a,'<br/>Directions: <a href="javascript:void(0);" onclick="myMap.tohere('+a+');return false;">To here</a> - <a href="javascript:void(0);" onclick="myMap.fromhere('+a+');return false;">From here</a>')},markerClick:function(a){this.click(a.idx)},tohere:function(a){var b=this.clubs[a];b='<br/>Directions: <b>To here</b> - <a href="javascript:void(0);" onclick="myMap.fromhere('+
a+');return false;">From here</a><br/>Start address or Postcode:<form action="http://maps.google.co.uk/maps" method="get" target="_blank"><input type="text" size="40" maxlength="40" name="saddr" id="saddr" value="" /><br/><input value="Get Directions" type="submit"/><input type="hidden" name="daddr" value="'+b.latlng.toUrlValue()+"("+b.name+' Lacrosse Club)"/>';this.openInfoWindow(a,b)},fromhere:function(a){var b=this.clubs[a];b='<br/>Directions: <a href="javascript:void(0);" onclick="myMap.tohere('+
a+');return false;">To here</a> - <b>From here</b><br/>End address or Postcode:<form action="http://maps.google.co.uk/maps" method="get"" target="_blank"><input type="text" size="40" maxlength="40" name="daddr" id="daddr" value="" /><br/><input value="Get Directions" type="submit"/><input type="hidden" name="saddr" value="'+b.latlng.toUrlValue()+"("+b.name+' Lacrosse Club)"/>';this.openInfoWindow(a,b)},resetView:function(){this.map&&this.map.fitBounds(this.bounds)},popupLink:function(a){if(!window.focus)return true;
window.open(a.href?a.href:a,"locatorPopup","width=600,height=400,scrollbars=yes");return false},isMaximized:false,toggleMaximized:function(){var a=this.map.getCenter();if(this.isMaximized){this.mapDiv.className="map";this.mapParent.appendChild(this.mapDiv);document.body.appendChild(this.bodyFragment);this.bodyFragment=null;this.isMaximized=false;this.resize();this.maxButton.setText("Maximize");this.maxButton.setTitle("Maximize")}else{this.mapParent=this.mapDiv.parentNode;this.bodyFragment=document.createDocumentFragment();
for(var b=document.body;b.firstChild;)this.bodyFragment.appendChild(b.firstChild);this.mapDiv.style.height="100%";this.mapDiv.className="map-max";b.appendChild(this.mapDiv);this.isMaximized=true;this.map&&google.maps.event.trigger(this.map,"resize");this.maxButton.setText("Minimize");this.maxButton.setTitle("Minimize")}this.map.setCenter(a)},lazyTooltip:function(){if(!this.tooltip)this.tooltip=new Tooltip({map:this.map})},openTooltip:function(a){this.lazyTooltip();a=this.clubs[a];this.tooltip.setContent(a.dist?
a.name+" "+Math.round(a.dist*100)/100+" mi":a.name);this.tooltip.open(a.marker)},openInfoWindow:function(a,b){if(!this.infoWindow)this.infoWindow=new google.maps.InfoWindow;var c=this.clubs[a];this.infoWindow.setContent("<b>"+(c.dist?c.name+" "+Math.round(c.dist*100)/100+" mi":c.name)+"</b><br/>"+c.html+b);this.infoWindow.open(this.map,c.marker)},closeInfoWindow:function(){this.infoWindow&&this.infoWindow.close()},resize:function(){if(!this.isMaximized){var a=this.getWindowHeight()-this.getPosY(this.mapDiv)-
this.footer.offsetHeight-this.mapPaddingAndBorders;if(a<300)a=300;a=Math.round(a)+"px";this.mapDiv.style.height=a;this.keyDiv.style.height=a;this.map&&google.maps.event.trigger(this.map,"resize")}},getPosY:function(a){for(var b=0;a;){b+=a.offsetTop;a=a.offsetParent}return b},getWindowHeight:function(){if(window.self&&self.innerWidth)return self.innerHeight;if(document.documentElement&&document.documentElement.clientHeight)return document.documentElement.clientHeight;return document.body.clientHeight},
initialize:function(a,b,c,d,e,f){this.clubs=a;this.bounds=new google.maps.LatLngBounds(new google.maps.LatLng(d,b),new google.maps.LatLng(e,c));this.iconBase=f?f+"icon":"icon";this.mapDiv=document.getElementById("map");this.keyDiv=document.getElementById("mapkey");this.footer=document.getElementById("footer");this.mapPaddingAndBorders=this.getPosY(this.footer)-this.getPosY(this.mapDiv)-this.mapDiv.clientHeight;a=function(){myMap.resize()};if(window.addEventListener)window.addEventListener("resize",
a,false);else if(window.attachEvent)window.attachEvent("onresize",a);else window.onresize=a;this.resize();a={scaleControl:true,mapTypeControlOptions:{style:google.maps.MapTypeControlStyle.DROPDOWN_MENU},mapTypeId:google.maps.MapTypeId.ROADMAP};this.map=new google.maps.Map(document.getElementById("map"),a);this.resetView();this.shadowImage=new google.maps.MarkerImage("http://www.google.co.uk/mapfiles/shadow50.png",new google.maps.Size(37,34),new google.maps.Point(0,0),new google.maps.Point(10,34));
for(a=this.clubs.length;a--;){b=this.clubs[a];b.idx=a;c={position:b.latlng,map:this.map};if(b.icon){c.icon=new google.maps.MarkerImage(this.iconBase+b.icon+".png",new google.maps.Size(20,34));c.shadow=this.shadowImage}c=new google.maps.Marker(c);this.addListeners(c,b);google.maps.event.addListener(c,"mouseout",this.mouseoutFunction);b.marker=c}this.defaultIcons=!this.clubs[0].icon;a=new ControlContainer;this.maxButton=new ButtonControl("Maximize","Maximize",false,function(){myMap.toggleMaximized()});
a.addControl(this.maxButton);a.addControl(new ButtonControl("Reset","Reset the map to show all clubs",false,function(){myMap.resetView()}));a.setPosition(this.map,google.maps.ControlPosition.TOP_RIGHT);a=new ControlContainer;myNC.initialize();a.addControl(myNC);a.setPosition(this.map,google.maps.ControlPosition.TOP_LEFT)},addListeners:function(a,b){google.maps.event.addListener(a,"click",function(){myMap.markerClick(b)});google.maps.event.addListener(a,"mouseover",function(){myMap.markerMouseover(b)})},
clubsInAlphaOrder:true,enableNearest:function(){this.clickListener=google.maps.event.addListener(this.map,"click",function(a){myMap.dropNearestMarker(a.latLng)})},disableNearest:function(){this.nearestMarker&&this.nearestMarker.setMap(null);this.showNearestCircle(false);if(this.clickListener){google.maps.event.removeListener(this.clickListener);this.clickListener=null}this.clubsInAlphaOrder||this.reorderClubsAlpha()},dropNearestMarker:function(a){if(this.nearestMarker){this.nearestMarker.setMap(this.map);
this.nearestMarker.setPosition(a)}else{this.nearestMarker=new google.maps.Marker({map:this.map,position:a,draggable:true,title:"Drag to sort clubs by distance from this marker"});google.maps.event.addListener(this.nearestMarker,"dragend",function(){myMap.nearestMarkerMoved()});google.maps.event.addListener(this.nearestMarker,"mouseover",function(){myMap.nearestMarkerMouseover()});google.maps.event.addListener(this.nearestMarker,"mouseout",this.mouseoutFunction)}this.showNearestCircle(myNC.showCircle);
this.nearestMarkerMoved();myNC.markerDropped()},nearestMarkerMoved:function(){var a=this.nearestMarker.getPosition();this.nearestMarker.tooltip=Math.round(1E3*a.lat())/1E3+","+Math.round(1E3*a.lng())/1E3;myMap.reorderClubs(a)},showNearestCircle:function(a){if(a){if(this.nearestMarker&&this.nearestMarker.getMap()){if(!this.nearestCircle){this.nearestCircle=new google.maps.Circle({radius:myNC.radius*1609.344});this.nearestCircle.bindTo("center",this.nearestMarker,"position")}this.nearestCircle.setMap(this.map)}}else this.nearestCircle&&
this.nearestCircle.setMap(null)},nearestCircleRadiusChanged:function(a){this.nearestCircle&&this.nearestCircle.setRadius(a*1609.344)},reorderClubs:function(a){for(var b=this.clubs.length;b--;)this.computeDistance(a,this.clubs[b]);this.clubs.sort(function(c,d){return c.dist-d.dist});this.clubsInAlphaOrder=false;this.clubsOrderChanged(false)},reorderClubsAlpha:function(){for(var a=this.clubs.length;a--;)delete this.clubs[a].dist;this.clubs.sort(function(b,c){if(b.name<c.name)return-1;return b.name>
c.name?1:0});this.clubsInAlphaOrder=true;this.clubsOrderChanged(this.defaultIcons)},clubsOrderChanged:function(a){var b=this.clubs.length;this.closeInfoWindow();if(a)for(a=b;a--;){var c=this.clubs[a];c.idx=a;c.marker.setIcon(null);c.marker.setShadow(null);delete c.icon}else for(a=b;a--;){c=this.clubs[a];if(c.idx!=a||!c.icon){c.idx=a;if(c.icon)c.icon=c.icon.substring(0,1)+(a+1);else{c.icon="r"+(a+1);c.marker.setShadow(this.shadowImage)}c.marker.setIcon(new google.maps.MarkerImage(this.iconBase+c.icon+
".png",new google.maps.Size(20,34)))}}if(!this.keyTable)this.keyTable=this.keyDiv.getElementsByTagName("table")[0];var d=this.keyTable.rows;for(a=0;a<b;a++){var e=d[a].cells[1].getElementsByTagName("a")[0];c=this.clubs[a];e.innerHTML=c.dist?c.name+" "+Math.round(c.dist)+" mi":c.name}},computeDistance:function(a,b){var c=this.deg2rad(a.lat()),d=this.deg2rad(b.latlng.lat());b.dist=3959*Math.acos(Math.sin(c)*Math.sin(d)+Math.cos(c)*Math.cos(d)*Math.cos(this.deg2rad(a.lng()-b.latlng.lng())))},deg2rad:function(a){return a*
Math.PI/180}};

