var a;if(!Ports)var Ports={};Function.prototype.bind=function(b){var c=this;return function(){return c.apply(b,arguments)}};
Ports.BingMap=function(){this.mapLoaded=0;this.mapId=this.mapLoadTimer=null;this.layers=[];this.defaultView=this.map=null;var b=new Ports.BingMap.Layer("PAREA");b.colour="sea";this.AddLayer(b);b=new Ports.BingMap.Layer("PARIS");b.colour="purple";this.AddLayer(b);b=new Ports.BingMap.Layer("INSTN");b.colour="green";this.AddLayer(b);b=new Ports.BingMap.Layer("RELIG");b.colour="blue";this.AddLayer(b);b=new Ports.BingMap.Layer("SCHOO");b.colour="yellow";this.AddLayer(b);b=new Ports.BingMap.Layer("MASSC");
b.colour="red";this.AddLayer(b);b=new Ports.BingMap.Layer("GENOR");b.colour="grey";this.AddLayer(b)};a=Ports.BingMap.prototype;a.GetLayerById=function(b){for(var c=0;c<this.layers.length;c++)if(this.layers[c].id==b)return this.layers[c];return null};a.OnLoad=function(){};a.OnPostLoad=function(){};
a.Render=function(b){this.mapId=b;if(this.mapLoaded==0){$("body").append('<script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2" type="text/javascript"> <\/script>');this.mapLoadedTimer=setTimeout(function(){this.OnLoaded()}.bind(this),1E3)}};
a.GetContainingView=function(){for(var b=null,c=null,e=null,h=null,i,f=0;f<this.layers.length;f++)if(i=this.layers[f].GetContainingView()){if(!b||i.TopLeftLatLong.Latitude<b)b=i.TopLeftLatLong.Latitude;if(!c||i.BottomRightLatLong.Longitude<c)c=i.BottomRightLatLong.Longitude;if(!e||i.BottomRightLatLong.Latitude>e)e=i.BottomRightLatLong.Latitude;if(!h||i.TopLeftLatLong.Longitude>h)h=i.TopLeftLatLong.Longitude}return b?new VELatLongRectangle(new VELatLong(b,h),new VELatLong(e,c)):null};
a.AddLayer=function(b){b.map=this;this.layers.push(b)};a.OnLoaded=function(){try{this.map=new VEMap(this.mapId);this.map.LoadMap(new VELatLong(50.5,-1.38),7,VEMapStyle.Road);this.map.HideDashboard()}catch(b){this.mapLoadedTimer=setTimeout(function(){this.OnLoaded()}.bind(this),1E3);return}this.mapLoaded=1;for(var c=0;c<this.layers.length;c++)this.layers[c].OnLoaded();this.OnAddShapes&&this.OnAddShapes();for(c=0;c<this.layers.length;c++)this.layers[c].AddShapes();this.OnPostLoad&&this.OnPostLoad()};
a.SetViewAsDefault=function(){this.defaultView=this.map.GetMapView()};a.ResetView=function(){this.defaultView&&this.map.SetMapView(this.defaultView)};a.ZoomIn=function(){this.map.ZoomIn()};a.ZoomOut=function(){this.map.ZoomOut()};a.ClearShapes=function(){for(var b=0;b<this.layers.length;b++){this.layers[b].mapLayer.DeleteAllShapes();this.layers[b].shapes=[]}this.map.Clear()};
a.LoadBoundaries=function(){this.map.EnableShapeDisplayThreshold(false);this.map.SetFailedShapeRequest(VEFailedShapeRequest.DrawInaccurately);this.PastoralAreaLayer=new VEShapeLayer;this.PastoralAreaLayer.Source=new VEShapeSourceSpecification(VEDataType.GeoRSS,"/directory/furniture/map/pastoralareas.xml",this.PastoralAreaLayer);this.map.ImportShapeLayerData(this.PastoralAreaLayer.Source,function(b){for(var c,e=0;e<b.GetShapeCount();e++){c=b.GetShapeByIndex(e);c.SetLineWidth(2);c.SetLineColor(new VEColor(0,
150,100,0.5));c.SetFillColor(new VEColor(0,150,100,0.05));c.HideIcon();c.SetDescription("Zoom in to see more detail");c.SetMaxZoomLevel(11)}},0);this.BoundaryLayer=new VEShapeLayer;this.BoundaryLayer.Source=new VEShapeSourceSpecification(VEDataType.GeoRSS,"/directory/furniture/map/boundary.xml",this.BoundaryLayer);this.map.ImportShapeLayerData(this.BoundaryLayer.Source,function(b){for(var c,e=0;e<b.GetShapeCount();e++){c=b.GetShapeByIndex(e);c.SetLineWidth(3);c.SetLineColor(new VEColor(0,150,100,
0.5));c.HideIcon()}},0);this.map.AttachEvent("onmouseover",function(b){if(b.elementID&&this.map.GetShapeByID(b.elementID).GetType()==VEShapeType.Polygon&&this.map.GetZoomLevel()<=9){this.map.HideInfoBox();this.map.ShowInfoBox(this.map.GetShapeByID(b.elementID));this.map.GetShapeByID(b.elementID).SetFillColor(new VEColor(0,150,100,0.7))}}.bind(this));this.map.AttachEvent("onmouseout",function(b){b.elementID&&this.map.GetShapeByID(b.elementID).GetType()==VEShapeType.Polygon&&this.map.GetZoomLevel()<=
9&&this.map.GetShapeByID(b.elementID).SetFillColor(new VEColor(0,150,100,0.05))}.bind(this))};a.OnPostProcessSearchResult=function(){};a.GetPointByAddress=function(b,c,e){if(c){$("#mapThrobber").fadeIn();results=this.map.Find(null,c+", UK",null,null,0,3,false,false,false,false,function(h,i,f){this.ProcessAddressPoint(f,e)}.bind(this))}else if(b){$("#mapThrobber").fadeIn();results=this.map.Find(null,b+", UK",null,null,0,3,false,false,false,false,function(h,i,f){this.ProcessAddressPoint(f,e)}.bind(this))}};
a.ProcessAddressPoint=function(b,c){$("#mapThrobber").fadeOut();if(!(b==null||b.length==0))for(var e=0;e<b.length;e++)if(b[e].LatLong.Latitude>=49.1&&b[e].LatLong.Latitude<=51.8&&b[e].LatLong.Longitude>=-2.6&&b[e].LatLong.Longitude<=0.5&&b[e].MatchConfidence!=VEMatchConfidence.Low){c(b[e].LatLong.Latitude,b[e].LatLong.Longitude);return}c(null,null)};
a.ProcessSearchResult=function(b,c,e){if(c==null||c.length==0){$("#flashNotFound").fadeIn();$("#mapThrobber").fadeOut();return null}for(var h=[],i=0;i<c.length;i++)if(c[i].LatLong.Latitude>=49.1&&c[i].LatLong.Latitude<=51.8&&c[i].LatLong.Longitude>=-2.6&&c[i].LatLong.Longitude<=0.5&&c[i].MatchConfidence!=VEMatchConfidence.Low){h.push(c[i]);break}if(h==null||h.length==0){$("#flashNotFound").fadeIn();$("#mapThrobber").fadeOut();return null}c=new VEShape(VEShapeType.Pushpin,new VELatLong(h[0].LatLong.Latitude,
h[0].LatLong.Longitude));c.SetTitle(b);c.SetCustomIcon("/directory/furniture/map/postcode.gif");this.map.AddShape(c);this.map.GetZoomLevel()<14?this.map.SetCenterAndZoom(h[0].LatLong,14):this.map.SetCenter(h[0].LatLong);$.getJSON("/directory/webscripts/ajax/public.php",{action:"NearestChurches",lat:h[0].LatLong.Latitude,lng:h[0].LatLong.Longitude,distance:e},function(f){if(f.data.churches.length==0){$("#mapThrobber").fadeOut();return null}for(var j=0;j<f.data.churches.length;j++){var k=f.data.churches[j];
this.GetLayerById("MASSC").AddShape(k.id,k.latitude,k.longitude,k.title,(k.district?k.district+", ":"")+k.town)}for(j=0;j<this.layers.length;j++)this.layers[j].AddShapes();if(j=this.GetContainingView()){this.map.SetMapView(j);this.map.GetZoomLevel()>14&&this.map.SetZoomLevel(14);this.SetViewAsDefault()}k="<table>";var g,l;if(f.data.services.vigil){k+="<tr><td style='font-weight:bold; background-color:silver; padding:0.5em; font-size:105%' colspan='3'>Saturday Vigil Masses</td></tr>";for(j=0;j<f.data.services.vigil.length;j++){g=
f.data.services.vigil[j];l=null;for(var d=0;d<f.data.churches.length;d++)if(f.data.churches[d].id==g.id){l=f.data.churches[d];break}d="";if(g.language)d=d+"in "+g.language;if(g.frequency){if(d.length>0)d+="; ";d+=g.frequency}if(g.notes){if(d.length>0)d+="; ";d+=g.notes}k=k+'<tr style="vertical-align:top"><td style="font-weight:bold">'+g.time+'</td><td style="width:30em"><a href="/directory/organisation/'+l.id+'.htm">'+l.title+"</a>, "+l.town+"</td><td><i>"+d+"</i></td></tr>"}}if(f.data.services.earlyMorning){k+=
"<tr><td style='font-weight:bold; background-color:silver; padding:0.5em; font-size:105%' colspan='3'>Sunday early morning Masses</td></tr>";for(j=0;j<f.data.services.earlyMorning.length;j++){g=f.data.services.earlyMorning[j];l=null;for(d=0;d<f.data.churches.length;d++)if(f.data.churches[d].id==g.id){l=f.data.churches[d];break}d="";if(g.language)d=d+"in "+g.language;if(g.frequency){if(d.length>0)d+="; ";d+=g.frequency}if(g.notes){if(d.length>0)d+="; ";d+=g.notes}k=k+'<tr style="vertical-align:top"><td style="font-weight:bold">'+
g.time+'</td><td style="width:30em"><a href="/directory/organisation/'+l.id+'.htm">'+l.title+"</a>, "+l.town+"</td><td><i>"+d+"</i></td></tr>"}}if(f.data.services.lunchtime){k+="<tr><td style='font-weight:bold; background-color:silver; padding:0.5em; font-size:105%' colspan='3'>Sunday late morning and early afternoon Masses</td></tr>";for(j=0;j<f.data.services.lunchtime.length;j++){g=f.data.services.lunchtime[j];l=null;for(d=0;d<f.data.churches.length;d++)if(f.data.churches[d].id==g.id){l=f.data.churches[d];
break}d="";if(g.language)d=d+"in "+g.language;if(g.frequency){if(d.length>0)d+="; ";d+=g.frequency}if(g.notes){if(d.length>0)d+="; ";d+=g.notes}k=k+'<tr style="vertical-align:top"><td style="font-weight:bold">'+g.time+'</td><td style="width:30em"><a href="/directory/organisation/'+l.id+'.htm">'+l.title+"</a>, "+l.town+"</td><td><i>"+d+"</i></td></tr>"}}if(f.data.services.evening){k+="<tr><td style='font-weight:bold; background-color:silver; padding:0.5em; font-size:105%' colspan='3'>Sunday evening Masses</td></tr>";
for(j=0;j<f.data.services.evening.length;j++){g=f.data.services.evening[j];l=null;for(d=0;d<f.data.churches.length;d++)if(f.data.churches[d].id==g.id){l=f.data.churches[d];break}d="";if(g.language)d=d+"in "+g.language;if(g.frequency){if(d.length>0)d+="; ";d+=g.frequency}if(g.notes){if(d.length>0)d+="; ";d+=g.notes}k=k+'<tr style="vertical-align:top"><td style="font-weight:bold">'+g.time+'</td><td style="width:30em"><a href="/directory/organisation/'+l.id+'.htm">'+l.title+"</a>, "+l.town+"</td><td><i>"+
d+"</i></td></tr>"}}k+="</table>";$("#tabcontainer-t-services").append(k);this.OnPostProcessSearchResult&&this.OnPostProcessSearchResult();return null}.bind(this));return null};
a.MakeDraggable=function(b){this.map.AttachEvent("onmousemove",this.dragMouseMoveHandler.bind(this));this.map.AttachEvent("onmousedown",this.dragMouseDownHandler.bind(this));this.map.AttachEvent("onmouseup",this.dragMouseUpHandler.bind(this));this.map.AttachEvent("onendpan",this.SetPanBounds.bind(this));this.map.AttachEvent("onendzoom",this.SetPanBounds.bind(this));this.map.AttachEvent("oninitmode",this.SetPanBounds.bind(this));this.SetPanBounds();this.dragCallback=b};
a.SetPanBounds=function(){var b=this.map.GetMapView(),c=this.map.LatLongToPixel(b.TopLeftLatLong),e=this.map.LatLongToPixel(b.BottomRightLatLong),h=c.x+30;b=e.x-30;e=e.y-30;c=c.y+30;c=this.map.PixelToLatLong(new VEPixel(h,c));b=this.map.PixelToLatLong(new VEPixel(b,e));this.viewBounds={};this.viewBounds.NorthBound=c.Latitude;this.viewBounds.SouthBound=b.Latitude;this.viewBounds.WestBound=c.Longitude;this.viewBounds.EastBound=b.Longitude};
a.dragMouseDownHandler=function(b){if(b.rightMouseButton&&b.elementID){this.moving=true;this.movingShape=this.map.GetShapeByID(b.elementID);this.map.vemapcontrol.EnableGeoCommunity(true);document.getElementById(this.mapId).style.cursor="Move"}};
a.dragMouseMoveHandler=function(b){if(this.moving){b=this.map.PixelToLatLong(new VEPixel(b.mapX,b.mapY));var c=0,e=0,h="";this.map.HideInfoBox(this.movingShape);this.movingShape.SetPoints(b);if(this.previousLoc){c=b.Latitude-this.previousLoc.Latitude;e=b.Longitude-this.previousLoc.Longitude;if(c>0)h="north";else if(c<0)h="south";if(e>0)h="east";else if(e<0)h="west"}b.Latitude<this.viewBounds.SouthBound&&h=="south"&&this.map.Pan(0,10);b.Latitude>this.viewBounds.NorthBound&&h=="north"&&this.map.Pan(0,
-10);b.Longitude<this.viewBounds.WestBound&&h=="west"&&this.map.Pan(-10,0);b.Longitude>this.viewBounds.EastBound&&h=="east"&&this.map.Pan(10,0);this.previousLoc=b}};a.dragMouseUpHandler=function(b){if(this.moving&&b.rightMouseButton){this.moving=false;this.map.vemapcontrol.EnableGeoCommunity(false);document.getElementById(this.mapId).style.cursor="";b=this.movingShape.Latitude;var c=this.movingShape.Longitude;this.movingShape=null;this.dragCallback&&this.dragCallback(b.toFixed(4),c.toFixed(4))}};
Ports.BingMap.Layer=function(b){this.id=b;this.colour="grey";this.mapLayer=null;this.visible=true;this.shapes=[]};a=Ports.BingMap.Layer.prototype;a.OnLoaded=function(){this.mapLayer=new VEShapeLayer;this.map.map.AddShapeLayer(this.mapLayer)};a.OnAddShapes=function(){};a.Show=function(){this.visible=true;this.mapLayer.Show()};a.Hide=function(){this.visible=false;this.mapLayer.Hide()};
a.AddShape=function(b,c,e,h,i,f){c=new VEShape(VEShapeType.Pushpin,new VELatLong(c,e));f==true?c.SetTitle('<a href="/directory/organisation/'+b+'.htm">'+h+"</a>"):c.SetTitle(h);c.SetCustomIcon("/directory/furniture/map/"+this.colour+".gif");i&&c.SetDescription(i);this.shapes.push(c)};a.AddShapes=function(){this.mapLayer.AddShape(this.shapes)};
a.GetContainingView=function(){if(this.mapLayer.GetShapeCount()==0)return null;for(var b=null,c=null,e=null,h=null,i,f=0;f<this.mapLayer.GetShapeCount();f++){i=this.mapLayer.GetShapeByIndex(f).GetPoints(0)[0];if(!b||i.Latitude<b)b=i.Latitude;if(!c||i.Longitude<c)c=i.Longitude;if(!e||i.Latitude>e)e=i.Latitude;if(!h||i.Longitude>h)h=i.Longitude}return new VELatLongRectangle(new VELatLong(b,h),new VELatLong(e,c))};
a.CreateLayerButton=function(b){if(this.mapLayer.GetShapeCount()>0){b='<div class="d-toolbar-button d-toolbar-button-selected" id="btnMapLayer'+this.id+'"><img src="/directory/furniture/button-'+this.colour+'.gif" alt="Show/hide '+b+'" title="Show/hide '+b+'" style="vertical-align:middle"/> '+b+"</div>";$("#tabcontainer-t-map-toolbar").append(b);$("#btnMapLayer"+this.id).click(function(){if(this.visible){this.Hide();$("#btnMapLayer"+this.id).removeClass("d-toolbar-button-selected");$("#btnMapLayer"+
this.id).removeClass("d-toolbar-button-selected-hover");$("#btnMapLayer"+this.id).addClass("d-toolbar-button-hover")}else{this.Show();$("#btnMapLayer"+this.id).addClass("d-toolbar-button-selected");$("#btnMapLayer"+this.id).addClass("d-toolbar-button-selected-hover");$("#btnMapLayer"+this.id).removeClass("d-toolbar-button-hover")}}.bind(this));$("#btnMapLayer"+this.id).mouseenter(function(){$(this).hasClass("d-toolbar-button-selected")?$(this).addClass("d-toolbar-button-selected-hover"):$(this).addClass("d-toolbar-button-hover")});
$("#btnMapLayer"+this.id).mouseleave(function(){$(this).hasClass("d-toolbar-button-selected")?$(this).removeClass("d-toolbar-button-selected-hover"):$(this).removeClass("d-toolbar-button-hover")})}};