if(GBrowserIsCompatible()){var GKey,geocoder,GingerIcon,groups,SearchIcon,map,mapCenter,mapType,mapZoom,markers,mcOptions,mcStyles,i,inputText,results,resultsList,selected,t,tmpTown,tmpDistance,towns;init()}else{alert("Sorry, the Google Maps API is not compatible with this browser")}function init(){GKey="ABQIAAAAEjUlAJsDC2C6xOo9NHy0eRRdozCJlzFpob4pqLNI8k1WDBtOiBQSMJ3ZnXFZe6aBCNKRPFKC_cJtvg";allowedBounds=new GLatLngBounds(new GLatLng(49.5,-10),new GLatLng(59,2.6));mapCenter=new GLatLng(51.5001524,-0.1262362);mapType=G_NORMAL_MAP;mapZoom=7;GingerIcon=new GIcon();GingerIcon={image:"img/icon.png",shadow:"img/shadow.png",iconSize:new GSize(20,20),shadowSize:new GSize(30,20),iconAnchor:new GPoint(10,20),infoWindowAnchor:new GPoint(19,1)};SearchIcon=new GIcon();SearchIcon={image:"img/searchicon.png",shadow:"img/shadow.png",iconSize:new GSize(20,20),shadowSize:new GSize(30,20),iconAnchor:new GPoint(10,20),infoWindowAnchor:new GPoint(19,1)};mcStyles=[{height:20,width:40,opt_anchor:[2,23],opt_textColor:"#292627",url:"img/icon_m.png"},{height:20,width:50,opt_anchor:[2,23],opt_textColor:"#292627",url:"img/icon_l.png"},{height:20,width:60,opt_anchor:[2,23],opt_textColor:"#292627",url:"img/icon_xl.png"}];mcOptions={gridSize:50,maxZoom:10,styles:mcStyles};selected=-1;towns=[];groups=[];markers=[]}function initGMap(){map=new GMap2(document.getElementById("map"));geocoder=new GClientGeocoder();map.setCenter(mapCenter,mapZoom,mapType);map.addControl(new GLargeMapControl3D());map.enableScrollWheelZoom();mt=map.getMapTypes();for(i=0;i<mt.length;i++){mt[i].getMinimumResolution=function(){return 7};mt[i].getMaximumResolution=function(){return 11}}GEvent.addListener(map,"move",function(){checkBounds()})}function checkBounds(){var f,g,e,b,a,d,c;if(allowedBounds.contains(map.getCenter())){return}f=map.getCenter();g=f.lng();e=f.lat();b=allowedBounds.getNorthEast().lng();a=allowedBounds.getNorthEast().lat();d=allowedBounds.getSouthWest().lng();c=allowedBounds.getSouthWest().lat();if(g<d){g=d}if(g>b){g=b}if(e<c){e=c}if(e>a){e=a}map.setCenter(new GLatLng(e,g))}function findNearestGroup(d){var a,c,b;c={id:-1,distance:-1};b=new GLatLng(d.lat,d.lng);for(i=0;i<markers.length;i++){distance=markers[i].getPoint().distanceFrom(b);if(i==0){c.id=i;c.distance=distance}if(distance<c.distance&&distance>0){c.id=i;c.distance=distance}}a=groups[c.id];return{distance:(c.distance/1000).toFixed(2),lat:a.coordinates[1],lng:a.coordinates[0],organisation:a.organisation,city:a.city}}function moveToTown(d){var b,c,a;if(tmpTown&&tmpDistance){map.removeOverlay(tmpTown);map.removeOverlay(tmpDistance)}if(typeof d=="string"){d=(d.split("_"))[1]}switch(towns[d].zoom){case 0:c=7;break;case 1:c=7;break;case 2:c=7;break;case 3:c=8;break;case 4:c=11;break;case 5:c=11;break;case 6:c=11;break;case 7:c=11;break;case 8:c=11;break;case 9:c=11;break;default:c=7;break}map.setCenter(new GLatLng(towns[d].lat,towns[d].lng),c);a=new GLatLng(towns[d].lat,towns[d].lng);nearestGroup=findNearestGroup(towns[d]);b="<h1>"+towns[d].name+"</h1><dl><dt>Nearest Gingerbread Group:</dt><dd>"+nearestGroup.organisation+"</dd><dt>Town:</dt><dd>"+nearestGroup.city+"</dd><dt>Distance:</dt><dd>"+nearestGroup.distance+" km</dd></dl>";tmpTown=createMarker(a,'<div class="info_contents">'+b+'</div><div class="info_bottom"></div>',SearchIcon,true);tmpDistance=new GPolyline([new GLatLng(nearestGroup.lat,nearestGroup.lng),a],"#E36F1D",5,0.6);map.addOverlay(tmpTown);map.addOverlay(tmpDistance)}function mapResize(){var c,b,a;b=$("#header").height();c=5;a=$("body").height();$("#map").css("height",(a-b-c)+"px")}function search(){var d;d=$.trim($(".searchinput").val());if(inputText!=d&&d.length>2){var b,a,c;geocoder.setBaseCountryCode("GB");geocoder.setViewport(allowedBounds);geocoder.getLocations(d,function(e){towns=[];if(e.Status.code=="200"){for(i=0;i<e.Placemark.length;i++){b=e.Placemark[i];if(typeof b.AddressDetails.Country!="undefined"&&b.AddressDetails.Country.CountryNameCode=="GB"){a={name:b.address,lat:b.Point.coordinates[1],lng:b.Point.coordinates[0],zoom:b.AddressDetails.Accuracy};towns.push(a)}}}if(towns.length>0){c="";for(i=0;i<towns.length;i++){li='<li id="result_'+i+'"><a href="#" title="'+towns[i].name+'">'+towns[i].name+"</a></li>";c+=li}$("#results_list").html("<ul>"+c+"</ul>");selected=0;$("#result_"+selected+" a").addClass("active");$("#results_list ul li").bind("click",function(){moveToTown($(this).attr("id"))})}else{li='<li class="none">No places found in the UK. Please try different keywords.</li>';$("#results_list").html("<ul>"+li+"</ul>")}results.show()})}else{results.hide()}}function createMarker(a,e,c,d){var b=new GMarker(a,{icon:c});if(d==true){b.openExtInfoWindow(map,"gbread_info",e,{beakOffset:3})}GEvent.addListener(b,"click",function(){b.openExtInfoWindow(map,"gbread_info",e,{beakOffset:3})});return b}$(document).ready(function(){inputText=$(".searchinput").val();results=$("#results");results.hide();resultsList=$("#results_list");mapResize();$(window).resize(mapResize);$(".searchinput").focus(function(){$(this).removeClass("inactive");if($(this).val()==inputText){$(this).val("");resultsList.empty()}selected=-1}).blur(function(){if($.trim($(this).val())==""){$(this).val(inputText)}if($(this).val()==inputText){$(this).addClass("inactive");resultsList.empty()}selected=-1;$("#results_list ul li a").removeClass("active")}).mouseover(function(){if($("#results_list ul").length>0){results.show()}}).keyup(function(d){var e=13,b=40,a=38,c;c=towns.length;switch(d.keyCode){case e:moveToTown(selected);results.hide();$(".searchinput").blur();break;case b:selected++;if(selected>=c){selected=c-1}break;case a:selected--;if(selected<=-1){selected=0}break;default:search();break}if(selected>-1&&selected<c){results.show();$("#results_list ul li a").removeClass("active");$("#result_"+selected+" a").addClass("active")}});$("#searchform").submit(function(a){a.preventDefault();search()});$("#map").mouseover(function(){results.hide()});$("form.searchbox").submit(function(a){a.preventDefault();search()});$("a.submit").click(function(){search()});initGMap();$.getJSON("groups.json",function(d){var a,f,h,j,g,b,e,c;for(i=0;i<d.groups.length;i++){j=d.groups[i];groups.push(j);e=j.coordinates;b=e[0];g=e[1];c="<h1>"+j.organisation+'</h1><p class="location">'+j.city+(j.county.length>0?", "+j.county:"")+'</p><p class="postcode">In the region of '+j.postcode+'</p><p class="phone">Ask for <span class="name">'+j.forename+'</span> on <span class="number">'+j.phone+"</span></p>";markers.push(createMarker(new GPoint(b,g),'<div class="info_contents">'+c+'</div><div class="info_bottom"></div>',GingerIcon))}h=new MarkerClusterer(map,markers,mcOptions)})});