
if(GBrowserIsCompatible()){document.write('<div class="floatright" style="width:320px">\n'+'<div id="map" style="width:320px;height:500px"></div>\n'+'<p class="quiet">Drag the map with your mouse to move it or double-click to centre it. Click on the map to search for sites within a 25-mile radius. Click on a marker or point to the campsite name to identify a campsite.</p>\n'+'</div>\n');window.onload=function(){showMap()};}else{document.write('<div id="map" class="floatright" style="width:270px">\n'+'<p><a href="search"><img src="map" ismap="ismap" width="270" height="490" alt="[UK Map showing Scout campsites]" title="" /></a></p>\n'+'<p class="quiet">UK map based on a Crown copyright image produced from the Ordnance Survey <a href="http://www.getamap.co.uk">Get-a-map</a> service and reproduced with kind permission of <a href="http://www.ordnancesurvey.co.uk/">Ordnance Survey</a> and <a href="http://www.osni.gov.uk/">Ordnance Survey of Northern Ireland.</a></p>'+'</div>\n');}
function mapClickHandler(obj){function setNewLocation(gr){return function(){window.location.href="http://www.glswscouts.org.uk/campsites/search?q="+gr;};}
var clickTimeout=null;function clickHandler(overlay,point){if(point){if(clickTimeout==null){var gr=pointToGrid(point);if(gr.match(/^[A-Z]{2}[0-9]{6}$/)){clickTimeout=window.setTimeout(setNewLocation(gr),500);}}else{clearTimeout(clickTimeout);clickTimeout=null;}}}
if(obj.attachEvent){obj.attachEvent("ondblclick",function(){clearTimeout(clickTimeout);clickTimeout=null;});}
return clickHandler;}
function siteMouseOverHandler(site,marker){function showMarkerContent(){marker.openInfoWindow(marker.csContent);}
var mouseOverTimeout;function mouseOver(){mouseOverTimeout=window.setTimeout(showMarkerContent,500);}
function mouseOut(){clearTimeout(mouseOverTimeout);}
if(site.addEventListener){site.addEventListener("mouseover",mouseOver,false);site.addEventListener("mouseout",mouseOut,false);}else if(site.attachEvent){site.attachEvent("onmouseover",mouseOver);site.attachEvent("onmouseout",mouseOut);}}
function newMarker(x,y,icon,site){var point=new GPoint(x,y);var marker=new GMarker(point,icon);marker.csContent=document.createElement("p");marker.csContent.style.width="12em";marker.csContent.style.paddingLeft="1em";marker.csContent.appendChild(site.cloneNode(true));GEvent.addListener(marker,"click",function(){marker.openInfoWindow(marker.csContent);});var link=site.getElementsByTagName("a");if(link[0]){siteMouseOverHandler(link[0],marker);}
return marker;}
function showMap(){var map=new GMap(document.getElementById("map"));map.addControl(new GLargeMapControl());map.addControl(new GMapTypeControl());map.centerAndZoom(new GPoint(-4.5,55.5),12);GEvent.addListener(map,"click",mapClickHandler(document.getElementById("map")));var icon=new GIcon();icon.image="http://www.glswscouts.org.uk/campsites/tent-marker.png";icon.shadow="http://www.glswscouts.org.uk/campsites/tent-marker-shadow.png";icon.iconSize=new GSize(30,33);icon.shadowSize=new GSize(46,33);icon.iconAnchor=new GPoint(15,33);icon.infoWindowAnchor=new GPoint(15,0);icon.printImage="http://www.glswscouts.org.uk/campsites/tent-marker.gif";icon.mozPrintImage="http://www.glswscouts.org.uk/campsites/tent-marker.png";icon.transparent="http://www.glswscouts.org.uk/campsites/tent-marker-transparent.png";icon.imageMap=new Array(0,32,0,28,11,10,5,0,24,0,19,10,29,28,29,32,0,32);var minX=180,maxX=-180,minY=180,maxY=-180;var marker=new Array();var site=document.getElementsByTagName("span");for(var i=0;i<site.length;i+=1){if(!site[i].id)continue;var id=site[i].id;if(!id.match(/^[g-p]{16,}/))continue;var j,x=0,y=0,z="g".charCodeAt(0);for(j=0;j<8;j+=1)x=x*10+id.charCodeAt(j)-z;x=x/100000-180;if(x<minX)minX=x;if(x>maxX)maxX=x;for(j=8;j<16;j+=1)y=y*10+id.charCodeAt(j)-z;y=y/100000-180;if(y<minY)minY=y;if(y>maxY)maxY=y;marker.unshift(newMarker(x,y,icon,site[i]));map.addOverlay(marker[0]);}
if(minX<=maxX&&minY<=maxY){var span=map.getSpanLatLng(),zoom=map.getZoomLevel();var width=maxX-minX,height=maxY-minY;var centreX=minX+width/2,centreY=minY+height/2;if(width==0&&height==0){zoom=8;}else{width*=1.5;height*=1.5;do{span.width/=2;span.height/=2;if(span.width<width||span.height<height)break;zoom-=1;}while(zoom>8);}
map.centerAndZoom(new GPoint(centreX,centreY),zoom);}
if(marker.length==1)marker[0].openInfoWindow(marker[0].csContent);}
function pointToGrid(point){var deg2rad=Math.PI/180;var rad2deg=180.0/Math.PI;var phip=point.y*deg2rad;var lambdap=point.x*deg2rad;var AXIS=6377563.396;var ECCENTRIC=0.00667054;var LAT_ORIG=49*deg2rad;var LONG_ORIG=-2*deg2rad;var FALSE_EAST=400000.0;var FALSE_NORTH=-100000.0;var SCALE=0.9996012717;var j=(lambdap-LONG_ORIG)*Math.cos(phip);var nsqd=ECCENTRIC*(Math.cos(phip)*Math.cos(phip))/(1-ECCENTRIC);var tsqd=Math.pow(Math.sin(phip)/(Math.cos(phip)),2);var up=AXIS/Math.sqrt(1-(ECCENTRIC*(Math.sin(phip)*Math.sin(phip))));var p=ECCENTRIC/8.0;var a=AXIS*(1-(2*p)-(3*p*p)-(10*p*p*p));var b=AXIS*((6*p)+(12*p*p)+(45*p*p*p))/2;var c=AXIS*((15*p*p)+(90*p*p*p))/4;var mo=(a*LAT_ORIG)-(b*Math.sin(2*LAT_ORIG))+(c*Math.sin(4*LAT_ORIG));var mp=(a*phip)-(b*Math.sin(2*phip))+(c*Math.sin(4*phip));var east=Math.round(0.5+FALSE_EAST+((SCALE*up)*(j+((j*j*j)/6)*(1-tsqd+nsqd))));var north=Math.round(0.5+FALSE_NORTH+(SCALE*(mp-mo))+(SCALE*(up)*((Math.sin(phip))/(Math.cos(phip))))*(((j*j)/2)+((j*j*j*j)/24*(5-tsqd))));var eX=east/500000;var nX=north/500000;var tmp=Math.floor(eX)-5.0*Math.floor(nX)+17.0;nX=5*(nX-Math.floor(nX));eX=20-5.0*Math.floor(nX)+Math.floor(5.0*(eX-Math.floor(eX)));if(eX>7.5)eX=eX+1;if(tmp>7.5)tmp=tmp+1;return String.fromCharCode(tmp+65)+String.fromCharCode(eX+65)+
String(east).slice(-5,-2)+String(north).slice(-5,-2);}