function MarkerClusterer(n,t,i){var r,u;this.extend(MarkerClusterer,google.maps.OverlayView);this.map_=n;this.markers_=[];this.clusters_=[];this.sizes=[53,56,66,78,90];this.styles_=[];this.ready_=!1;r=i||{};this.gridSize_=r.gridSize||60;this.minClusterSize_=r.minimumClusterSize||2;this.maxZoom_=r.maxZoom||null;this.styles_=r.styles||[];this.imagePath_=r.imagePath||this.MARKER_CLUSTER_IMAGE_PATH_;this.imageExtension_=r.imageExtension||this.MARKER_CLUSTER_IMAGE_EXTENSION_;this.zoomOnClick_=!0;r.zoomOnClick!=undefined&&(this.zoomOnClick_=r.zoomOnClick);this.averageCenter_=!1;r.averageCenter!=undefined&&(this.averageCenter_=r.averageCenter);this.setupStyles_();this.setMap(n);this.prevZoom_=this.map_.getZoom();u=this;google.maps.event.addListener(this.map_,"zoom_changed",function(){var n=u.map_.getZoom();u.prevZoom_!=n&&(u.prevZoom_=n,u.resetViewport())});google.maps.event.addListener(this.map_,"idle",function(){u.redraw()});t&&t.length&&this.addMarkers(t,!1)}function Cluster(n){this.markerClusterer_=n;this.map_=n.getMap();this.gridSize_=n.getGridSize();this.minClusterSize_=n.getMinClusterSize();this.averageCenter_=n.isAverageCenter();this.center_=null;this.markers_=[];this.bounds_=null;this.clusterIcon_=new ClusterIcon(this,n.getStyles(),n.getGridSize())}function ClusterIcon(n,t,i){n.getMarkerClusterer().extend(ClusterIcon,google.maps.OverlayView);this.styles_=t;this.padding_=i||0;this.cluster_=n;this.center_=null;this.map_=n.getMap();this.div_=null;this.sums_=null;this.visible_=!1;this.setMap(this.map_)}function bootstrap(){angular.bootstrap(rootAppElement,["findSchoolApp"])}MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_PATH_="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/images/m";MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_EXTENSION_="png";MarkerClusterer.prototype.extend=function(n,t){return function(n){for(var t in n.prototype)this.prototype[t]=n.prototype[t];return this}.apply(n,[t])};MarkerClusterer.prototype.onAdd=function(){this.setReady_(!0)};MarkerClusterer.prototype.draw=function(){};MarkerClusterer.prototype.setupStyles_=function(){if(!this.styles_.length)for(var n=0,t;t=this.sizes[n];n++)this.styles_.push({url:this.imagePath_+(n+1)+"."+this.imageExtension_,height:t,width:t})};MarkerClusterer.prototype.fitMapToMarkers=function(){for(var r=this.getMarkers(),n=new google.maps.LatLngBounds,t=0,i;i=r[t];t++)n.extend(i.getPosition());this.map_.fitBounds(n)};MarkerClusterer.prototype.setStyles=function(n){this.styles_=n};MarkerClusterer.prototype.getStyles=function(){return this.styles_};MarkerClusterer.prototype.isZoomOnClick=function(){return this.zoomOnClick_};MarkerClusterer.prototype.isAverageCenter=function(){return this.averageCenter_};MarkerClusterer.prototype.getMarkers=function(){return this.markers_};MarkerClusterer.prototype.getTotalMarkers=function(){return this.markers_.length};MarkerClusterer.prototype.setMaxZoom=function(n){this.maxZoom_=n};MarkerClusterer.prototype.getMaxZoom=function(){return this.maxZoom_};MarkerClusterer.prototype.calculator_=function(n,t){for(var i=0,u=n.length,r=u;r!==0;)r=parseInt(r/10,10),i++;return i=Math.min(i,t),{text:u,index:i}};MarkerClusterer.prototype.setCalculator=function(n){this.calculator_=n};MarkerClusterer.prototype.getCalculator=function(){return this.calculator_};MarkerClusterer.prototype.addMarkers=function(n,t){for(var i=0,r;r=n[i];i++)this.pushMarkerTo_(r);t||this.redraw()};MarkerClusterer.prototype.pushMarkerTo_=function(n){if(n.isAdded=!1,n.draggable){var t=this;google.maps.event.addListener(n,"dragend",function(){n.isAdded=!1;t.repaint()})}this.markers_.push(n)};MarkerClusterer.prototype.addMarker=function(n,t){this.pushMarkerTo_(n);t||this.redraw()};MarkerClusterer.prototype.removeMarker_=function(n){var t=-1,i,r;if(this.markers_.indexOf)t=this.markers_.indexOf(n);else for(i=0;r=this.markers_[i];i++)if(r==n){t=i;break}return t==-1?!1:(n.setMap(null),this.markers_.splice(t,1),!0)};MarkerClusterer.prototype.removeMarker=function(n,t){var i=this.removeMarker_(n);return!t&&i?(this.resetViewport(),this.redraw(),!0):!1};MarkerClusterer.prototype.removeMarkers=function(n,t){for(var f,i=!1,r=0,u;u=n[r];r++)f=this.removeMarker_(u),i=i||f;if(!t&&i)return this.resetViewport(),this.redraw(),!0};MarkerClusterer.prototype.setReady_=function(n){this.ready_||(this.ready_=n,this.createClusters_())};MarkerClusterer.prototype.getTotalClusters=function(){return this.clusters_.length};MarkerClusterer.prototype.getMap=function(){return this.map_};MarkerClusterer.prototype.setMap=function(n){this.map_=n};MarkerClusterer.prototype.getGridSize=function(){return this.gridSize_};MarkerClusterer.prototype.setGridSize=function(n){this.gridSize_=n};MarkerClusterer.prototype.getMinClusterSize=function(){return this.minClusterSize_};MarkerClusterer.prototype.setMinClusterSize=function(n){this.minClusterSize_=n};MarkerClusterer.prototype.getExtendedBounds=function(n){var t=this.getProjection(),e=new google.maps.LatLng(n.getNorthEast().lat(),n.getNorthEast().lng()),o=new google.maps.LatLng(n.getSouthWest().lat(),n.getSouthWest().lng()),r=t.fromLatLngToDivPixel(e),i,u,f;return r.x+=this.gridSize_,r.y-=this.gridSize_,i=t.fromLatLngToDivPixel(o),i.x-=this.gridSize_,i.y+=this.gridSize_,u=t.fromDivPixelToLatLng(r),f=t.fromDivPixelToLatLng(i),n.extend(u),n.extend(f),n};MarkerClusterer.prototype.isMarkerInBounds_=function(n,t){return t.contains(n.getPosition())};MarkerClusterer.prototype.clearMarkers=function(){this.resetViewport(!0);this.markers_=[]};MarkerClusterer.prototype.resetViewport=function(n){for(var r,i,t=0;r=this.clusters_[t];t++)r.remove();for(t=0;i=this.markers_[t];t++)i.isAdded=!1,n&&i.setMap(null);this.clusters_=[]};MarkerClusterer.prototype.repaint=function(){var n=this.clusters_.slice();this.clusters_.length=0;this.resetViewport();this.redraw();window.setTimeout(function(){for(var t=0,i;i=n[t];t++)i.remove()},0)};MarkerClusterer.prototype.redraw=function(){this.createClusters_()};MarkerClusterer.prototype.distanceBetweenPoints_=function(n,t){if(!n||!t)return 0;var i=(t.lat()-n.lat())*Math.PI/180,r=(t.lng()-n.lng())*Math.PI/180,u=Math.sin(i/2)*Math.sin(i/2)+Math.cos(n.lat()*Math.PI/180)*Math.cos(t.lat()*Math.PI/180)*Math.sin(r/2)*Math.sin(r/2),f=2*Math.atan2(Math.sqrt(u),Math.sqrt(1-u));return 6371*f};MarkerClusterer.prototype.addToClosestCluster_=function(n){for(var r,u,t,f=4e4,i=null,o=n.getPosition(),e=0;t=this.clusters_[e];e++)r=t.getCenter(),r&&(u=this.distanceBetweenPoints_(r,n.getPosition()),u<f&&(f=u,i=t));i&&i.isMarkerInClusterBounds(n)?i.addMarker(n):(t=new Cluster(this),t.addMarker(n),this.clusters_.push(t))};MarkerClusterer.prototype.createClusters_=function(){var i,r,t,n;if(this.ready_)for(i=new google.maps.LatLngBounds(this.map_.getBounds().getSouthWest(),this.map_.getBounds().getNorthEast()),r=this.getExtendedBounds(i),t=0;n=this.markers_[t];t++)!n.isAdded&&this.isMarkerInBounds_(n,r)&&this.addToClosestCluster_(n)};Cluster.prototype.isMarkerAlreadyAdded=function(n){if(this.markers_.indexOf)return this.markers_.indexOf(n)!=-1;for(var t=0,i;i=this.markers_[t];t++)if(i==n)return!0;return!1};Cluster.prototype.addMarker=function(n){var t,r;if(this.isMarkerAlreadyAdded(n))return!1;if(this.center_){if(this.averageCenter_){var i=this.markers_.length+1,u=(this.center_.lat()*(i-1)+n.getPosition().lat())/i,f=(this.center_.lng()*(i-1)+n.getPosition().lng())/i;this.center_=new google.maps.LatLng(u,f);this.calculateBounds_()}}else this.center_=n.getPosition(),this.calculateBounds_();if(n.isAdded=!0,this.markers_.push(n),t=this.markers_.length,t<this.minClusterSize_&&n.getMap()!=this.map_&&n.setMap(this.map_),t==this.minClusterSize_)for(r=0;r<t;r++)this.markers_[r].setMap(null);return t>=this.minClusterSize_&&n.setMap(null),this.updateIcon(),!0};Cluster.prototype.getMarkerClusterer=function(){return this.markerClusterer_};Cluster.prototype.getBounds=function(){for(var n=new google.maps.LatLngBounds(this.center_,this.center_),r=this.getMarkers(),t=0,i;i=r[t];t++)n.extend(i.getPosition());return n};Cluster.prototype.remove=function(){this.clusterIcon_.remove();this.markers_.length=0;delete this.markers_};Cluster.prototype.getSize=function(){return this.markers_.length};Cluster.prototype.getMarkers=function(){return this.markers_};Cluster.prototype.getCenter=function(){return this.center_};Cluster.prototype.calculateBounds_=function(){var n=new google.maps.LatLngBounds(this.center_,this.center_);this.bounds_=this.markerClusterer_.getExtendedBounds(n)};Cluster.prototype.isMarkerInClusterBounds=function(n){return this.bounds_.contains(n.getPosition())};Cluster.prototype.getMap=function(){return this.map_};Cluster.prototype.updateIcon=function(){var f=this.map_.getZoom(),t=this.markerClusterer_.getMaxZoom(),n,i,r,u;if(t&&f>t){for(n=0;i=this.markers_[n];n++)i.setMap(this.map_);return}if(this.markers_.length<this.minClusterSize_){this.clusterIcon_.hide();return}r=this.markerClusterer_.getStyles().length;u=this.markerClusterer_.getCalculator()(this.markers_,r);this.clusterIcon_.setCenter(this.center_);this.clusterIcon_.setSums(u);this.clusterIcon_.show()};ClusterIcon.prototype.triggerClusterClick=function(){var n=this.cluster_.getMarkerClusterer();google.maps.event.trigger(n,"clusterclick",this.cluster_);n.isZoomOnClick()&&this.map_.fitBounds(this.cluster_.getBounds())};ClusterIcon.prototype.onAdd=function(){var n,t,i;this.div_=document.createElement("DIV");this.visible_&&(n=this.getPosFromLatLng_(this.center_),this.div_.style.cssText=this.createCss(n),this.div_.innerHTML=this.sums_.text);t=this.getPanes();t.overlayMouseTarget.appendChild(this.div_);i=this;google.maps.event.addDomListener(this.div_,"click",function(){i.triggerClusterClick()})};ClusterIcon.prototype.getPosFromLatLng_=function(n){var t=this.getProjection().fromLatLngToDivPixel(n);return t.x-=parseInt(this.width_/2,10),t.y-=parseInt(this.height_/2,10),t};ClusterIcon.prototype.draw=function(){if(this.visible_){var n=this.getPosFromLatLng_(this.center_);this.div_.style.top=n.y+"px";this.div_.style.left=n.x+"px"}};ClusterIcon.prototype.hide=function(){this.div_&&(this.div_.style.display="none");this.visible_=!1};ClusterIcon.prototype.show=function(){if(this.div_){var n=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(n);this.div_.style.display=""}this.visible_=!0};ClusterIcon.prototype.remove=function(){this.setMap(null)};ClusterIcon.prototype.onRemove=function(){this.div_&&this.div_.parentNode&&(this.hide(),this.div_.parentNode.removeChild(this.div_),this.div_=null)};ClusterIcon.prototype.setSums=function(n){this.sums_=n;this.text_=n.text;this.index_=n.index;this.div_&&(this.div_.innerHTML=n.text);this.useStyle()};ClusterIcon.prototype.useStyle=function(){var t=Math.max(0,this.sums_.index-1),n;t=Math.min(this.styles_.length-1,t);n=this.styles_[t];this.url_=n.url;this.height_=n.height;this.width_=n.width;this.textColor_=n.textColor;this.anchor_=n.anchor;this.textSize_=n.textSize;this.backgroundPosition_=n.backgroundPosition};ClusterIcon.prototype.setCenter=function(n){this.center_=n};ClusterIcon.prototype.createCss=function(n){var t=[],i,r,u;return t.push("background-image:url("+this.url_+");"),i=this.backgroundPosition_?this.backgroundPosition_:"0 0",t.push("background-position:"+i+";"),typeof this.anchor_=="object"?(typeof this.anchor_[0]=="number"&&this.anchor_[0]>0&&this.anchor_[0]<this.height_?t.push("height:"+(this.height_-this.anchor_[0])+"px; padding-top:"+this.anchor_[0]+"px;"):t.push("height:"+this.height_+"px; line-height:"+this.height_+"px;"),typeof this.anchor_[1]=="number"&&this.anchor_[1]>0&&this.anchor_[1]<this.width_?t.push("width:"+(this.width_-this.anchor_[1])+"px; padding-left:"+this.anchor_[1]+"px;"):t.push("width:"+this.width_+"px; text-align:center;")):t.push("height:"+this.height_+"px; line-height:"+this.height_+"px; width:"+this.width_+"px; text-align:center;"),r=this.textColor_?this.textColor_:"black",u=this.textSize_?this.textSize_:11,t.push("cursor:pointer; top:"+n.y+"px; left:"+n.x+"px; color:"+r+"; position:absolute; font-size:"+u+"px; font-family:Arial,sans-serif; font-weight:bold"),t.join("")};window.MarkerClusterer=MarkerClusterer;MarkerClusterer.prototype.addMarker=MarkerClusterer.prototype.addMarker;MarkerClusterer.prototype.addMarkers=MarkerClusterer.prototype.addMarkers;MarkerClusterer.prototype.clearMarkers=MarkerClusterer.prototype.clearMarkers;MarkerClusterer.prototype.fitMapToMarkers=MarkerClusterer.prototype.fitMapToMarkers;MarkerClusterer.prototype.getCalculator=MarkerClusterer.prototype.getCalculator;MarkerClusterer.prototype.getGridSize=MarkerClusterer.prototype.getGridSize;MarkerClusterer.prototype.getExtendedBounds=MarkerClusterer.prototype.getExtendedBounds;MarkerClusterer.prototype.getMap=MarkerClusterer.prototype.getMap;MarkerClusterer.prototype.getMarkers=MarkerClusterer.prototype.getMarkers;MarkerClusterer.prototype.getMaxZoom=MarkerClusterer.prototype.getMaxZoom;MarkerClusterer.prototype.getStyles=MarkerClusterer.prototype.getStyles;MarkerClusterer.prototype.getTotalClusters=MarkerClusterer.prototype.getTotalClusters;MarkerClusterer.prototype.getTotalMarkers=MarkerClusterer.prototype.getTotalMarkers;MarkerClusterer.prototype.redraw=MarkerClusterer.prototype.redraw;MarkerClusterer.prototype.removeMarker=MarkerClusterer.prototype.removeMarker;MarkerClusterer.prototype.removeMarkers=MarkerClusterer.prototype.removeMarkers;MarkerClusterer.prototype.resetViewport=MarkerClusterer.prototype.resetViewport;MarkerClusterer.prototype.repaint=MarkerClusterer.prototype.repaint;MarkerClusterer.prototype.setCalculator=MarkerClusterer.prototype.setCalculator;MarkerClusterer.prototype.setGridSize=MarkerClusterer.prototype.setGridSize;MarkerClusterer.prototype.setMaxZoom=MarkerClusterer.prototype.setMaxZoom;MarkerClusterer.prototype.onAdd=MarkerClusterer.prototype.onAdd;MarkerClusterer.prototype.draw=MarkerClusterer.prototype.draw;Cluster.prototype.getCenter=Cluster.prototype.getCenter;Cluster.prototype.getSize=Cluster.prototype.getSize;Cluster.prototype.getMarkers=Cluster.prototype.getMarkers;ClusterIcon.prototype.onAdd=ClusterIcon.prototype.onAdd;ClusterIcon.prototype.draw=ClusterIcon.prototype.draw;ClusterIcon.prototype.onRemove=ClusterIcon.prototype.onRemove;var rootAppElement=document.getElementById("findaSchool"),$cleanCopy=$(rootAppElement).clone();angular.module("findSchoolApp",[]).controller("FindSchoolController",["$scope","$q","$http","$rootScope","$sce",function(n,t,r){function pt(){f=rootAppElement&&rootAppElement.dataset.map==="ST"?"st":"isc"}function wt(n,t){google.maps.event.addListener(n,"click",function(){r({method:"GET",url:e[f].endpoints.GetSchoolById,params:{id:t.id}}).success(function(t){var i=f==="st"?gt(t):dt(t);y=!0;p.close();p.setContent(i);p.open(u,n)})})}function st(t){var w,l,v,b,a,y,p;if(w=u.getZoom()>=8?e[f].markers.medium:e[f].markers.small,l=new google.maps.LatLng(t.lt,t.ln),v=l,o.length!=0)for(i=0;i<o.length;i++)if(b=o[i],a=b.getPosition(),l.equals(a)){for(y=0,h.push(a),j=0;j<h.length;j++)h[j].equals(a)&&y++;var s=l.lat(),c=l.lng(),r=(10/3e3/u.getZoom()+(n.findSchoolFilterStates.latitudeNE-n.findSchoolFilterStates.latitudeSW))*.0025;u.getZoom()>=8&&(r=r*9);switch(y){case 1:c=c+r;s=s+r;break;case 2:c=c+r;s=s-r;break;case 3:c=c-r;s=s-r;break;case 4:c=c-r;s=s+r}v=new google.maps.LatLng(s,c)}p=new google.maps.Marker({position:v,map:u,title:t.nm,icon:w});wt(p,t);o.push(p)}function bt(){for(var t=u.getZoom()>=8?e[f].markers.medium:e[f].markers.small,n=0;n<o.length;n++)o[n].icon!=t&&(o[n].icon=t)}function kt(){n.findSchoolFilterStates=JSON.parse($("#schoolStates").val());n.findSchoolFilterOptions=JSON.parse($("#filterOptions").val());w=!0;n.findSchoolFilterStates.locationName="";var t=$(".drop-down-link h3");t.each(function(){$(this).next("div").hide()});t.off().on("click",function(){$(this).next("div").toggle()});$(".drop-down-link h3 + div").on("mouseleave",function(n){$(n.currentTarget).hide()});$(".click-me").on("click",function(){$(this).next(".tool-tip").toggle()});$(".close").on("click",function(){$(this).parent().toggle()});a()}function ht(){for(var n=0;n<o.length;n++)o[n].setMap(null);o.length=0}function d(n){if(n)return n.filter(function(n){return n.isChecked==!0}).map(function(n){return n.id})}function g(n,t){t!=undefined&&$.each(n,function(){this.isChecked=t.indexOf(this.id)>-1})}function dt(n){var t="<div>";return t+="<h3>"+n.Name+"<\/h3>",t+="<pre>"+n.FullAddress+"<\/pre>",(n.GenderProfile||n.PupilCount||n.DayBoardingType||n.ReligiousAffiliation)&&(t+="<ul>",n.GenderProfile&&(t+="<li>"+n.GenderProfile+"<\/li>"),n.PupilCount&&(t+="<li>"+n.PupilCount+" pupils<\/li>"),n.DayBoardingType&&(t+="<li>"+n.DayBoardingType+"<\/li>"),n.ReligiousAffiliation&&(t+="<li>"+n.ReligiousAffiliation+"<\/li>"),t+="<\/ul>"),t+='<a href="'+n.Url+'">View school details<\/a>',t+"<\/div>"}function gt(n){var t="<div>";return t+="<h3>"+n.Name+"<\/h3>",t+='<div class="base__padded--box bg--grey"><p>'+n.FullAddress+"<\/p><\/div>",n.HasCensusData&&(t+='<div class="census-data base__padded--box bg--grey">',t+="<p>"+n.StateSchoolBenefited+" state school partners<\/p>",t+="<p>"+n.StateSchoolPupilBenefited+" state school pupils involved<\/p>",t+="<p>"+n.StaffHoursGiven+" staff hours given",t+="<\/div>"),t+='<div class="base__padded--box bg--grey u-text-center"><p><span class="stat">'+n.CaseStudiesCount+"<\/span> Case studies<\/p><\/div>",n.Url&&(t+='<a href="'+n.Url+'" class="button-link button-link--block">View school profile<i class="fas fa-arrow-right abs__right--middle"><\/i><\/a>'),t+"<\/div>"}function ct(){var r=JSON.parse($("#schoolStates").val()),u=JSON.parse($("#filterOptions").val()),t;n.findSchoolFilterOptions=u;t=ai();n.findSchoolFilterStates=t!=null?t:r;g(n.findSchoolFilterOptions.residencyTypes,n.findSchoolFilterStates.residencyTypes);g(n.findSchoolFilterOptions.examinations,n.findSchoolFilterStates.examinations);g(n.findSchoolFilterOptions.financialAssistances,n.findSchoolFilterStates.financialAssistances);g(n.findSchoolFilterOptions.caseStudyCategories,n.findSchoolFilterStates.caseStudyCategories);var i=window.location.href;i.indexOf("?scholarship-and-bursary=")!==-1&&($(".sab-checkbox").attr("checked","checked"),$(".sab-checkbox").prop("checked",!0),n.findSchoolFilterStates.scholarshipsAndBurseries=!0);i.indexOf("?sen=")!==-1&&($(".sen-checkbox").attr("checked","checked"),$(".sen-checkbox").prop("checked",!0),n.findSchoolFilterStates.specialNeeds=!0)}function ni(){var i=54.00366,r=-2.547855,f=5,t;n.findSchoolFilterStates.savedBounds!=undefined&&n.findSchoolFilterStates.savedBounds&&(t=n.findSchoolFilterStates.center,t.lat!=undefined&&t.lng!=undefined&&n.findSchoolFilterStates.zoom!=undefined&&(i=t.lat,r=t.lng,f=n.findSchoolFilterStates.zoom));u=new google.maps.Map(document.getElementById("findSchoolMap"),{center:new google.maps.LatLng(i,r),zoom:f,streetViewControl:!1,maxZoom:17});k=!0;p=new google.maps.InfoWindow}function ti(){var n=v.getItem(e[f].cookies.autocomplete),t;if(n)try{t=JSON.parse(n);yt(t);a();v.removeItem(e[f].cookies.autocomplete)}catch(i){console.log("Could not restore location from search")}}function ii(){var n=document.getElementById("schools-searchbox");c=new google.maps.places.Autocomplete(n);c.setFields(["business_status","formatted_address","geometry","icon","name","business_status","photos","place_id","plus_code","types"]);c.bindTo("bounds",u)}function ri(t,i,r){w=!0;nt(t,i,r,n.findSchoolFilterOptions.residencyTypes);nt(t,i,r,n.findSchoolFilterOptions.examinations);nt(t,i,r,n.findSchoolFilterOptions.financialAssistances);nt(t,i,r,n.findSchoolFilterOptions.caseStudyCategories);n.findSchoolFilterStates.residencyTypes=d(n.findSchoolFilterOptions.residencyTypes);n.findSchoolFilterStates.examinations=d(n.findSchoolFilterOptions.examinations);n.findSchoolFilterStates.financialAssistances=d(n.findSchoolFilterOptions.financialAssistances);n.findSchoolFilterStates.caseStudyCategories=d(n.findSchoolFilterOptions.caseStudyCategories);i==="Gender Groups"&&ft(t,i,n.findSchoolFilterOptions.genderGroups[n.findSchoolFilterStates.genderGroup-1]);i==="Age Range"&&ft(t,i,n.findSchoolFilterOptions.ageRanges[n.findSchoolFilterStates.ageRange-1]);i==="Religious Affiliation"&&ft(t,i,n.findSchoolFilterOptions.religiousAffiliations[n.findSchoolFilterStates.religiousAffiliation-1]);a()}function ft(n,t,i){i&&i.label&&lt(n,t,i.label)}function nt(n,t,i,r){var f,e,u;if(window.ga!=null&&r)for(f=0,e=r.length;f<e;f++)u=r[f],u.isChecked&&!u.hasSentGaEvent?(lt(n,t,i),u.hasSentGaEvent=!0):u.isChecked||(u.hasSentGaEvent=!1)}function lt(n,t,i){window.ga!=null&&ga("send","event",{eventCategory:n,eventAction:t,eventLabel:i})}function ui(){var t,i,r,f;for(y=!0,t=new google.maps.LatLngBounds,i=0;i<o.length;i++)t.extend(o[i].getPosition());n.isArea>0&&n.findSchoolFilterStates.viewport&&o.length<10&&(r=n.findSchoolFilterStates.viewport.getSouthWest(),f=n.findSchoolFilterStates.viewport.getNorthEast(),t.extend(r),t.extend(f));u.fitBounds(t);bt()}function tt(){var t=u.getBounds(),i,r;t&&(i=t.getSouthWest(),r=t.getNorthEast(),n.findSchoolFilterStates.savedBounds=!0,n.findSchoolFilterStates.latitudeSW=i.lat(),n.findSchoolFilterStates.longitudeSW=i.lng(),n.findSchoolFilterStates.latitudeNE=r.lat(),n.findSchoolFilterStates.longitudeNE=r.lng(),n.findSchoolFilterStates.zoom=u.getZoom(),n.findSchoolFilterStates.center=u.getCenter())}function fi(t){for(var u=[{id:1,name:"City of London",fileName:"london"},{id:2,name:"City of Westminster",fileName:"westminster"},{id:3,name:"London Borough of Barking and Dagenham",fileName:"barking_and_dagenham"},{id:4,name:"London Borough of Barnet",fileName:"barnet"},{id:5,name:"London Borough of Bexley",fileName:"bexley"},{id:6,name:"London Borough of Brent",fileName:"brent"},{id:7,name:"London Borough of Bromley",fileName:"bromley"},{id:8,name:"London Borough of Camden",fileName:"camden"},{id:9,name:"London Borough of Croydon",fileName:"croydon"},{id:10,name:"London Borough of Ealing",fileName:"ealing"},{id:11,name:"London Borough of Enfield",fileName:"enfield"},{id:12,name:"Royal Borough of Greenwich",fileName:"greenwich"},{id:13,name:"London Borough of Hackney",fileName:"hackney"},{id:14,name:"London Borough of Hammersmith and Fulham",fileName:"hammersmith_and_fulham"},{id:15,name:"London Borough of Haringey",fileName:"haringey"},{id:16,name:"London Borough of Harrow",fileName:"harrow"},{id:17,name:"London Borough of Havering",fileName:"havering"},{id:18,name:"London Borough of Hillingdon",fileName:"hillingdon"},{id:19,name:"London Borough of Hounslow",fileName:"hounslow"},{id:20,name:"London Borough of Islington",fileName:"islington"},{id:32,name:"Royal Borough of Kensington and Chelsea",fileName:"kensington_and_chelsea"},{id:33,name:"Royal Borough of Kingston upon Thames",fileName:"kingston_upon_thames"},{id:21,name:"London Borough of Lambeth",fileName:"lambeth"},{id:22,name:"London Borough of Lewisham",fileName:"lewisham"},{id:23,name:"London Borough of Merton",fileName:"merton"},{id:24,name:"London Borough of Newham",fileName:"newham"},{id:25,name:"London Borough of Redbridge",fileName:"redbridge"},{id:26,name:"London Borough of Richmond upon Thames",fileName:"richmond_upon_thames"},{id:27,name:"London Borough of Southwark",fileName:"southwark"},{id:28,name:"London Borough of Sutton",fileName:"sutton"},{id:29,name:"London Borough of Tower Hamlets",fileName:"tower_hamlets"},{id:30,name:"London Borough of Waltham Forest",fileName:"waltham_forest"},{id:31,name:"London Borough of Wandsworth",fileName:"wandsworth"}],e=0,f="",i={},r=0;r<u.length;r++)i[u[r].name]=u[r];i[t]&&(e=i[t].id,f=i[t].fileName);n.findSchoolFilterStates.londonBoroughID=e;f&&at(f,"LondonBoroughs")}function et(t){var i=0;switch(t){case"England":i=1;break;case"Scotland":i=2;break;case"Wales":i=3;break;case"Northern Ireland":i=4;break;case"Ireland":i=5;break;default:i=0}n.findSchoolFilterStates.contactCountryID=i}function ot(t){for(var u=[{id:1,name:"Bedfordshire",fileName:"bedfordshire"},{id:2,name:"Berkshire",fileName:"berkshire"},{id:4,name:"Buckinghamshire",fileName:"buckinghamshire"},{id:5,name:"Cambridgeshire",fileName:"cambridgeshire"},{id:7,name:"Cheshire",fileName:"Cheshire"},{id:8,name:"Cornwall",fileName:"cornwall"},{id:13,name:"County Durham",fileName:"countydurham"},{id:3,name:"City of Bristol",fileName:"countyofbristol"},{id:9,name:"Cumbria",fileName:"cumbria"},{id:10,name:"Derbyshire",fileName:"derbyshire"},{id:11,name:"Devon",fileName:"Devon"},{id:12,name:"Dorset",fileName:"dorset"},{id:46,name:"East Riding of Yorkshire",fileName:"eastridingofyorkshire"},{id:38,name:"East Sussex",fileName:"eastsussex"},{id:14,name:"Essex",fileName:"essex"},{id:15,name:"Gloucestershire",fileName:"gloucestershire"},{id:25,name:"Greater London",fileName:"greaterlondon"},{id:64,name:"Greater Manchester",fileName:"greatermanchester"},{id:16,name:"Hampshire",fileName:"hampshire"},{id:17,name:"Herefordshire",fileName:"herefordshire"},{id:18,name:"Hertfordshire",fileName:"hertfordshire"},{id:20,name:"Isle of Wight",fileName:"isleofwight"},{id:21,name:"Kent",fileName:"kent"},{id:22,name:"Lancashire",fileName:"lancashire"},{id:218,name:"Leicestershire",fileName:"leicestershire"},{id:24,name:"Lincolnshire",fileName:"lincolnshire"},{id:27,name:"Merseyside",fileName:"merseyside"},{id:28,name:"Norfolk",fileName:"norfolk"},{id:29,name:"Northamptonshire",fileName:"northamptonshire"},{id:30,name:"Northumberland",fileName:"northumberland"},{id:47,name:"North Yorkshire",fileName:"northyorkshire"},{id:31,name:"Nottinghamshire",fileName:"nottinghamshire"},{id:32,name:"Oxfordshire",fileName:"oxfordshire"},{id:134,name:"Pembrokeshire",fileName:"pembrokeshire"},{id:219,name:"Rutland",fileName:"rutland"},{id:33,name:"Shropshire",fileName:"shropshire"},{id:34,name:"Somerset",fileName:"somerset"},{id:48,name:"South Yorkshire",fileName:"southyorkshire"},{id:35,name:"Staffordshire",fileName:"staffordshire"},{id:36,name:"Suffolk",fileName:"suffolk"},{id:37,name:"Surrey",fileName:"surrey"},{id:41,name:"Tyne and Wear",fileName:"tyneandwear"},{id:42,name:"Warwickshire",fileName:"warwickshire"},{id:43,name:"West Midlands",fileName:"westmidlands"},{id:39,name:"West Sussex",fileName:"westsussex"},{id:49,name:"West Yorkshire",fileName:"westyorkshire"},{id:44,name:"Wiltshire",fileName:"wiltshire"},{id:45,name:"Worcestershire",fileName:"worcestershire"},{id:130,name:"Blaenau Gwent",fileName:"blaenau_gwent"},{id:124,name:"Bridgend",fileName:"bridgend"},{id:128,name:"Caerphilly",fileName:"caerphilly"},{id:129,name:"Cardiff",fileName:"cardiff"},{id:133,name:"Carmarthenshire",fileName:"carmarthenshire"},{id:135,name:"Ceredigion",fileName:"ceredigion"},{id:141,name:"Conwy",fileName:"conwy"},{id:140,name:"Denbighshire",fileName:"denbighshire"},{id:139,name:"Flintshire",fileName:"flintshire"},{id:137,name:"Gwynedd",fileName:"gwynedd"},{id:142,name:"Isle of Anglesey",fileName:"isle_of_anglesey"},{id:127,name:"Merthyr Tydfil",fileName:"merthyr_tydfil"},{id:100,name:"Monmouthshire",fileName:"monmouthshire"},{id:123,name:"Neath Port Talbot",fileName:"neath_port_talbot"},{id:132,name:"Newport",fileName:"newport"},{id:136,name:"Powys",fileName:"powys"},{id:125,name:"Rhondda Cynon Taff",fileName:"rhondda_cynon_taff"},{id:122,name:"Swansea",fileName:"swansea"},{id:131,name:"Torfaen",fileName:"torfaen"},{id:126,name:"Vale of Glamorgan",fileName:"vale_of_glamorgan"},{id:138,name:"Wrexham",fileName:"wrexham"},{id:77,name:"Antrim",fileName:"antrim"},{id:98,name:"Armagh",fileName:"armagh"},{id:78,name:"County Down",fileName:"county_down"},{id:82,name:"Fermanagh",fileName:"fermanagh"},{id:182,name:"Derry",fileName:"derry"},{id:79,name:"Tyrone",fileName:"tyrone"},{id:220,name:"Aberdeen City",fileName:"aberdeen"},{id:196,name:"Aberdeenshire",fileName:"aberdeenshire"},{id:73,name:"Angus",fileName:"angus"},{id:74,name:"Argyll and Bute",fileName:"argyll_and_bute"},{id:93,name:"Clackmannanshire",fileName:"clackmannanshire"},{id:197,name:"Dumfries and Galloway",fileName:"dumfries_and_galloway"},{id:198,name:"Dundee City",fileName:"dundee_city"},{id:200,name:"East Ayrshire",fileName:"east_ayrshire"},{id:201,name:"East Dunbartonshire",fileName:"east_dunbartonshire"},{id:203,name:"East Lothian",fileName:"east_lothian"},{id:205,name:"East Renfrewshire",fileName:"east_renfrewshire"},{id:206,name:"Edinburgh",fileName:"edinburgh"},{id:208,name:"Falkirk",fileName:"falkirk"},{id:83,name:"Fife",fileName:"fife"},{id:99,name:"Glasgow City",fileName:"glasgow"},{id:209,name:"Highland",fileName:"highland"},{id:84,name:"Inverclyde",fileName:"inverclyde"},{id:88,name:"Midlothian",fileName:"midlothian"},{id:210,name:"Moray",fileName:"moray"},{id:211,name:"North Ayrshire",fileName:"north_ayrshire"},{id:213,name:"North Lanarkshire",fileName:"north_lanarkshire"},{id:89,name:"Perth and Kinross",fileName:"perthshire_and_kinross"},{id:217,name:"Renfrewshire",fileName:"renfrewshire"},{id:75,name:"Scottish Borders",fileName:"scottish_borders"},{id:212,name:"South Ayrshire",fileName:"south_ayrshire"},{id:214,name:"South Lanarkshire",fileName:"south_lanarkshire"},{id:91,name:"Stirling",fileName:"stirling"},{id:202,name:"West Dunbartonshire",fileName:"west_dunbartonshire"},{id:204,name:"West Lothian",fileName:"west_lothian"},{id:6,name:"Channel Islands",fileName:""},],e=0,f="",i={},r=0;r<u.length;r++)i[u[r].name]=u[r];i[t]&&(e=i[t].id,f=i[t].fileName);n.findSchoolFilterStates.contactCountyID=e;f&&at(f,"Counties")}function at(n,t){var i=$.getJSON("/scripts/ISC/"+t+"/"+n+".json");i.then(function(n){u.data.addGeoJson(n)});u.data.setStyle({strokeColor:e[f].colours.primary,strokeOpacity:.5,strokeWeight:1,fillColor:e[f].colours.primary,fillOpacity:.2})}function a(){ei();hi();tt()}function vt(){n.listState=s.LOADING;r({method:"POST",url:e[f].endpoints.FindSchoolListResults,params:{skip:n.schoolListResults.length,take:20},data:n.findSchoolFilterStates}).then(function(t){n.listOfSchoolIds=n.listOfSchoolIds.concat(t.data.ID);n.schoolListResults=n.schoolListResults.concat(t.data);n.listState=s.LOADED;n.revealmore=t.data.length<20?!0:!1})}function ei(){n.findSchoolFilterStates.filterByBounds=Boolean(rt&&!l&&!b||ut||w||k);n.mapState=s.LOADING;k&&(k=!1);var i=t.defer();return r({method:"POST",url:e[f].endpoints.FindSchoolMapResults,data:n.findSchoolFilterStates}).then(function(t){var r;if(n.mapState=s.LOADED,n.schoolMapResults=t.data,n.listOfSchoolIds=n.listOfSchoolIds.concat(t.data.ID),ht(),h=[],t.data.length>0){for(r=0;r<t.data.length;r++)st(t.data[r]);if((l||b)&&(ui(),h.length))for(ht(),h=[],r=0;r<t.data.length;r++)st(t.data[r])}else l&&u.setZoom(8);l=!1;b=!1;ut=!1;rt=!1;w=!1;i.resolve()}),i.promise}function oi(){vt()}function si(n,t){u.panTo(new google.maps.LatLng(n,t))}function yt(t){var i=t||c.getPlace(),e,f;if(i&&i.types){l=!0;n.findSchoolFilterStates.contactCountyID=0;n.findSchoolFilterStates.contactCountryID=0;n.findSchoolFilterStates.londonBoroughID=0;n.findSchoolFilterStates.distanceInMiles===0&&(n.findSchoolFilterStates.distanceInMiles=20);e=i.types[0];window.ga!=null&&ga("send","event","Find a school","Location",i.formatted_address);n.findSchoolFilterStates.locationName=i.formatted_address;n.locationSet=!0;u.data.forEach(function(n){u.data.remove(n)});n.isArea=0;switch(e){case"country":et(i.name);break;case"administrative_area_level_1":et(i.name);break;case"administrative_area_level_2":ot(i.name);break;case"colloquial_area":ot(i.name);break;case"administrative_area_level_3":fi(i.name);break;case"natural_feature":i.name.toLowerCase()==="ireland"?et(i.name):ot(i.name)}n.isArea=n.findSchoolFilterStates.contactCountyID+n.findSchoolFilterStates.contactCountryID+n.findSchoolFilterStates.londonBoroughID;try{var r=i.geometry.location,o=typeof r.lat=="function"?r.lat():r.lat||0,s=typeof r.lng=="function"?r.lng():r.lng||0;n.findSchoolFilterStates.locationLatitude!=o&&n.findSchoolFilterStates.locationLongitude!=s&&(n.findSchoolFilterStates.locationLatitude=o,n.findSchoolFilterStates.locationLongitude=s,f=i.geometry.viewport,f&&(n.findSchoolFilterStates.viewport=f),si(n.findSchoolFilterStates.locationLatitude,n.findSchoolFilterStates.locationLongitude));tt()}catch(h){console.log("Could not get lat/lng and save to state")}}}function hi(){n.schoolListResults=[];n.listOfSchoolIds=[];vt()}function ci(){b=!0;a()}function li(){v.setItem(e[f].cookies.filter,JSON.stringify(n.findSchoolFilterStates),2592e3,"/")}function ai(){var n=v.getItem(e[f].cookies.filter);return n!=undefined?JSON.parse(n):null}function vi(){window.onbeforeunload=function(){tt();li()}}var v={getItem:function(n){return n&&decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(n).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null},setItem:function(n,t,i,r,u,f){if(!n||/^(?:expires|max\-age|path|domain|secure)$/i.test(n))return!1;var e="";if(i)switch(i.constructor){case Number:e=i===1/0?"; expires=Fri, 31 Dec 9999 23:59:59 GMT":"; max-age="+i;break;case String:e="; expires="+i;break;case Date:e="; expires="+i.toUTCString()}return document.cookie=encodeURIComponent(n)+"="+encodeURIComponent(t)+e+(u?"; domain="+u:"")+(r?"; path="+r:"")+(f?"; secure":""),!0},removeItem:function(n,t,i){return!!this.hasItem(n)&&(document.cookie=encodeURIComponent(n)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT"+(i?"; domain="+i:"")+(t?"; path="+t:""),!0)},hasItem:function(n){return!(!n||/^(?:expires|max\-age|path|domain|secure)$/i.test(n))&&new RegExp("(?:^|;\\s*)"+encodeURIComponent(n).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(document.cookie)},keys:function(){for(var n=document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g,"").split(/\s*(?:\=[^;]*)?;\s*/),i=n.length,t=0;t<i;t++)n[t]=decodeURIComponent(n[t]);return n},clear:function(n,t){for(var r=this.keys(),u=r.length,i=0;i<u;i++)this.removeItem(r[i],n,t)}},e={isc:{endpoints:{GetSchoolById:"/Umbraco/Api/FindSchoolApi/GetSchoolById",FindSchoolListResults:"/Umbraco/Api/FindSchoolApi/FindSchoolListResults",FindSchoolMapResults:"/Umbraco/Api/FindSchoolApi/FindSchoolMapResults"},markers:{small:"/images/map-pin-7px.png",medium:"/images/map-pin-16px.png"},colours:{primary:"#ff5a00"},cookies:{filter:"iscFilterStates",autocomplete:"iscMapSearch"}},st:{endpoints:{GetSchoolById:"/Umbraco/Api/StFindSchoolApi/StGetSchoolById",FindSchoolListResults:"/Umbraco/Api/StFindSchoolApi/StFindSchoolListResults",FindSchoolMapResults:"/Umbraco/Api/StFindSchoolApi/StFindSchoolMapResults"},markers:{small:"/images/map-pin-7px-st.png",medium:"/images/map-pin-16px-st.png"},colours:{primary:"#c52a26"},cookies:{filter:"stFilterStates",autocomplete:"stMapSearch"}}},s={LOADING:"LOADING",LOADED:"LOADED"},y=!1,u={},o=[],c={},p={},h=[],it=!1,rt=!1,l=!1,w=!1,b=!1,ut=!1,k=!1,f="isc";n.initFilters=ct;n.clearFilters=kt;n.onFiltersChange=ri;n.loadMore=oi;n.schoolMapResults=[];n.listOfSchoolIds=[];n.schoolListResults=[];n.findSchoolFilterStates={filterByBounds:!1,contactCountyID:0,contactCountryID:0,londonBoroughID:0};n.setDistance=ci;n.locationSet=!1;n.isArea=0;n.mapState=s.LOADING;n.listState=s.LOADING;pt();ct();ni();ii();ti();vi();google.maps.event.addListener(u,"idle",function(){if(!it){if(y){y=!1;return}a()}});google.maps.event.addListener(u,"dragstart",function(){it=!0});google.maps.event.addListener(u,"dragend",function(){it=!1;ut=!0});google.maps.event.addListener(c,"place_changed",function(){yt()});google.maps.event.addListener(u,"zoom_changed",function(){rt=!0;tt()});n.sendDetailsToSchool=function(){for(var u,f,i=n.schoolMapResults,r=[],t=0;t<i.length;t++)u=i[t].id,r.push(u);f="/contact-form?schoolId="+r;window.location.href=f};n.trackEmailGA=function(n,t,i){window.ga!=null&&ga("send","event","Email clicks - Find a school page","Clicked on "+n+" "+t+" "+i)}}])