Cwo.RegisterNamespace("Cwo.Maps.Search");Cwo.Maps.Search=function(p,n){var j=this;var l=null;var s=null;var h=null;var b=false;var c=p;var k=n;var i=true;function f(){var u=null;var t=null;if(n==="ToLet"){u=Cwo.Search.ToLet.Latitude;t=Cwo.Search.ToLet.Longitude}else{u=Cwo.Search.ForSale.Latitude;t=Cwo.Search.ForSale.Longitude}return new VELatLong(u,t)}function q(z){var t;if(n==="ToLet"){t=Cwo.Search.ToLet.Criteria.Radius}else{t=Cwo.Search.ForSale.Criteria.Radius}var C=new Array();var H=f().Latitude*Math.PI/180;var D=f().Longitude*Math.PI/180;var B=8;var E=0.5;var w=t/3956;for(var G=0;G<=360;G+=10){var A=(G/90)*Math.PI/2;var F=180*(Math.asin(Math.sin(H)*Math.cos(w)+Math.cos(H)*Math.sin(w)*Math.cos(A)))/Math.PI;var u;if(Math.cos(H)===0){u=lonin}else{u=((D-Math.asin(Math.sin(A)*Math.sin(w)/Math.cos(H))+Math.PI)%(2*Math.PI))-Math.PI}u=180*u/Math.PI;var y=new VELatLong(F,u);C.push(y)}if(i){z=true;i=false}if(z){l.SetMapView(C)}var v=new VEShape(VEShapeType.Polyline,C);v.HideIcon();v.SetLineWidth(B);if((l.GetMapStyle()===VEMapStyle.Aerial)||(l.GetMapStyle()===VEMapStyle.Hybrid)){v.SetLineColor(new VEColor(10,10,100,E))}else{v.SetLineColor(new VEColor(50,50,50,E))}s=new VEShape(VEShapeType.Pushpin,f());s.SetCustomIcon("<div class='centerPoint' />");s.SetZIndex(1000);l.AddShape(v);l.AddShape(s);l.CircleID=v.GetID();l.CenterID=s.GetID()}function d(){var t=f();var A=l.GetMapStyle();var x,z,w=null;if(A===VEMapStyle.BirdseyeHybrid){var y=l.GetBirdseyeScene();x=y.GetBoundingRectangle();z=x.TopLeftLatLong;w=x.BottomRightLatLong}else{x=l.GetMapView();z=x.TopLeftLatLong;w=x.BottomRightLatLong}var u="{AskingPriceMin:'"+Cwo.Search.ForSale.Criteria.AskingPriceMin+"',AskingPriceMax:'"+Cwo.Search.ForSale.Criteria.AskingPriceMax+"',BedroomsMin:'"+Cwo.Search.ForSale.Criteria.BedroomsMin+"',BedroomsMax:'"+Cwo.Search.ForSale.Criteria.BedroomsMax+"',ReceptionsMin:'"+Cwo.Search.ForSale.Criteria.ReceptionsMin+"',ReceptionsMax:'"+Cwo.Search.ForSale.Criteria.ReceptionsMax+"',BathroomsMin:'"+Cwo.Search.ForSale.Criteria.BathroomsMin+"',BathroomsMax:'"+Cwo.Search.ForSale.Criteria.BathroomsMax+"',SearchString:'"+Cwo.Search.ForSale.Criteria.SearchString.replace(/['']/g,"\\'")+"',CenterPoint:{Latitude:'"+t.Latitude+"',Longitude:'"+t.Longitude+"'},Radius:'"+Cwo.Search.ForSale.Criteria.Radius+"',TenureTypeID:'"+Cwo.Search.ForSale.Criteria.TenureTypeID+"',PropertyTypeID:'"+Cwo.Search.ForSale.Criteria.PropertyTypeID+"',PromotionID:'"+Cwo.Search.ForSale.Criteria.PromotionID+"',TopLeftVisible:{Latitude:'"+z.Latitude+"',Longitude:'"+z.Longitude+"'},BottomRightVisible:{Latitude:'"+w.Latitude+"',Longitude:'"+w.Longitude+"'},ZoomLevel:'"+l.GetZoomLevel()+"'}";var v=Cwo.Page.AjajCalls.CreateRequest("ForSaleMapSearch");new Cwo.AjaxCall("/webservices/ForSaleSearch.asmx/GetMapPoints",u,function(B){r(B,v)},null,null)}function o(){var t=f();var A=l.GetMapStyle();var x,z,w=null;if(A===VEMapStyle.BirdseyeHybrid){var y=l.GetBirdseyeScene();x=y.GetBoundingRectangle();z=x.TopLeftLatLong;w=x.BottomRightLatLong}else{x=l.GetMapView();z=x.TopLeftLatLong;w=x.BottomRightLatLong}var u="{RentalPriceMin:'"+Cwo.Search.ToLet.Criteria.RentalPriceMin+"',RentalPriceMax:'"+Cwo.Search.ToLet.Criteria.RentalPriceMax+"',BedroomsMin:'"+Cwo.Search.ToLet.Criteria.BedroomsMin+"',BedroomsMax:'"+Cwo.Search.ToLet.Criteria.BedroomsMax+"',FurnishingTypeID:'"+Cwo.Search.ToLet.Criteria.FurnishingTypeID+"',SearchString:'"+Cwo.Search.ToLet.Criteria.SearchString.replace(/['']/g,"\\'")+"',CenterPoint:{Latitude:'"+t.Latitude+"',Longitude:'"+t.Longitude+"'},Radius:'"+Cwo.Search.ToLet.Criteria.Radius+"',PropertyTypeID:'"+Cwo.Search.ToLet.Criteria.PropertyTypeID+"',TopLeftVisible:{Latitude:'"+z.Latitude+"',Longitude:'"+z.Longitude+"'},BottomRightVisible:{Latitude:'"+w.Latitude+"',Longitude:'"+w.Longitude+"'},ZoomLevel:'"+l.GetZoomLevel()+"',PromotionID:'"+Cwo.Search.ToLet.Criteria.PromotionID+"'}";var v=Cwo.Page.AjajCalls.CreateRequest("ToLetMapSearch");new Cwo.AjaxCall("/webservices/ToLetSearch.asmx/GetMapPoints",u,function(B){r(B,v)},null,null)}function r(A,w){if(!Cwo.Page.AjajCalls.IsCurrentSequenceIndex(n+"MapSearch",w)){return}var x=new VEShapeLayer();var y=A.d.ContentContainer.MapPoints;var v=y.length;var u="<span>"+A.d.ContentContainer.ResultCount+"</span> properties ";var t="";if(n==="ToLet"){t=Cwo.Search.ToLet.Criteria.Radius;u+="</span>to let within <span>"+((t===0.5)?"1/2 mile</span> of <span>":(t.toString()+((t>1)?" miles</span> of <span>":" mile</span> of <span>")))+Cwo.Search.ToLet.Criteria.SearchString+"</span>";$("#"+Cwo.Search.ToLet.ControlIDs.ResultsListButton).attr({href:A.d.ContentContainer.SearchURL});Cwo.Search.ToLet.ShowPromotionBanner(A.d.ContentContainer.PromotionBannerHTML)}else{t=Cwo.Search.ForSale.Criteria.Radius;u+="</span>for sale within <span>"+((t===0.5)?"1/2 mile</span> of <span>":(t.toString()+((t>1)?" miles</span> of <span>":" mile</span> of <span>")))+Cwo.Search.ForSale.Criteria.SearchString+"</span>";$("#"+Cwo.Search.ForSale.ControlIDs.ResultsListButton).attr({href:A.d.ContentContainer.SearchURL});Cwo.Search.ForSale.ShowPromotionBanner(A.d.ContentContainer.PromotionBannerHTML)}$("#NumberOfProperties").html(u);for(var z=0;z<v;z++){var B=new VEShape(VEShapeType.Pushpin,new VELatLong(y[z].Latitude,y[z].Longitude));B.IsPopup=false;if(y[z].Type===0){B.InstructionID=-1;B.SetCustomIcon('<div class="clusterPoint">'+y[z].ItemCount+"</div>")}else{B.InstructionID=y[z].ID;B.SetCustomIcon('<div class="mapPoint"><img src="/images/global/clear.gif" title="'+y[z].Summary+'" /></div>')}B.SetZIndex(100);x.AddShape(B)}l.AddShapeLayer(x)}function m(t){if((t.leftMouseButton||t.rightMouseButton||$.browser.opera)&&t.elementID){if(t.elementID.substring(0,l.CenterID.length)===l.CenterID){b=true;l.vemapcontrol.EnableGeoCommunity(true)}}}function g(t){if(b){s.SetPoints(l.PixelToLatLong(new VEPixel(t.mapX,t.mapY)))}}function e(x){if((x.leftMouseButton||x.rightMouseButton||$.browser.opera)&&b){b=false;var w=l.LatLongToPixel(l.GetCenter());var v=new VEPixel(x.mapX,x.mapY);var u=Math.sqrt(Math.pow((w.x-v.x),2)*Math.pow((w.y-v.y),2));var t=l.PixelToLatLong(v);if(n==="ToLet"){Cwo.Search.ToLet.Latitude=t.Latitude;Cwo.Search.ToLet.Longitude=t.Longitude}else{Cwo.Search.ForSale.Latitude=t.Latitude;Cwo.Search.ForSale.Longitude=t.Longitude}l.DeleteAllShapeLayers();l.PanToLatLong(t)}}function a(w){if((w.leftMouseButton||w.rightMouseButton||$.browser.opera)&&w.elementID){if(w.elementID.substring(0,l.CircleID.length)!==l.CircleID){var v=l.GetShapeByID(w.elementID);if(v.IsPopup===undefined){return}if(v.InstructionID===undefined){return}if(!v.IsPopup){var x=null;if(v.InstructionID===-1){var t=l.GetZoomLevel();var u=l.PixelToLatLong(new VEPixel(w.mapX,w.mapY));if(t===19){x="{Latitude:'"+u.Latitude+"',Longitude:'"+u.Longitude+"',ZoomLevel:'19'}";if(n==="ToLet"){new Cwo.AjaxCall("/webservices/ToLetSearch.asmx/GetPropertyPreviews",x,j.ShowAccordian,null,null)}else{new Cwo.AjaxCall("/webservices/ForSaleSearch.asmx/GetPropertyPreviews",x,j.ShowAccordian,null,null)}}else{l.SetCenterAndZoom(u,t+1)}}else{x="{InstructionID:'"+v.InstructionID+"'}";new Cwo.AjaxCall("/webservices/ForSaleSearch.asmx/GetPropertyPreview",x,j.ShowPreview,null,null)}}}}}this.LoadMap=function(){l=new VEMap(p);l.onLoadMap=j.MapLoaded;l.EnableBirdseye=false;if(Cwo.Common.GetCookie("PropertyWideMapToken")!==""){l.SetClientToken(Cwo.Common.GetCookie("PropertyWideMapToken"))}l.LoadMap(f(),12,VEMapStyle.Road,0,VEMapMode.Mode2D,1,false)};this.MapLoaded=function(){j.Update();l.AttachEvent("onmousedown",m);l.AttachEvent("onmousemove",g);l.AttachEvent("onmouseup",e);l.AttachEvent("onchangeview",j.Update);l.AttachEvent("onclick",a)};this.Update=function(){l.DeleteAllShapeLayers();l.vemapcontrol.EnableGeoCommunity(false);q(false);if(n==="ToLet"){o()}else{d()}};this.RadiusChanged=function(){q(true)};this.ShowPreview=function(t){var w=t.d.ContentContainer.PropertyPreviews[0];var v='<ul id="MapSingleContainer">';v+='    <li id="Top">';v+="        <ul>";v+='            <li class="NumberOfProperties">Property Details</li>';v+='            <li class="Close" id="MapPreviewClose">Close</li>';v+="        </ul>";v+="    </li>";v+='    <li id="Middle">';v+="        <ul>";v+='            <li class="Open">'+w.Price;v+='                <div class="Details">';v+='                    <img src="'+w.MainPhotoUrl+'" id="MapPreviewReadMoreFromPhoto" alt="" />';v+="                    <ul>";v+='                        <li class="PropertyType">'+w.Summary+"</li>";v+='                        <li class="ReadMore" id="MapPreviewReadMore"><button>Read More</button></li>';v+='                        <li class="Favourites"><button id="AddToFavourites">Favourite</button></li>';v+="                    </ul>";v+="                </div>";v+="            </li>";v+="        </ul>";v+="    </li>";v+='    <li id="Bottom"></li>';v+="</ul>";if(h!==null){j.ClosePreview()}var u=l.LatLongToPixel(new VELatLong(w.Latitude,w.Longitude),l.GetZoomLevel());if(u.x<7){u.x=7}if(u.x>380){u.x=380}if(u.y<12){u.y=12}if(u.y>470){u.y=470}h=new VEShape(VEShapeType.Pushpin,l.PixelToLatLong(new VEPixel(u.x,u.y)));h.InstructionID=w.InstructionID;h.IsPopup=true;h.URLAliasPath=w.URLAliasPath;h.SetCustomIcon(v);l.AddShape(h);$("#MapPreviewClose").bind("click",j.ClosePreview);$("#MapSingleContainer").bind("dblclick",function(){return false});var x=w.URLAliasPath.replace("&pound;","�");$("#MapPreviewReadMoreFromPhoto").bind("click",function(){Cwo.Page.NavigateWithReferrer(x)});$("#MapPreviewReadMore").bind("click",function(){Cwo.Page.NavigateWithReferrer(x)});new Cwo.Favourites.FavouriteButtonHandler(w.InstructionID,"AddToFavourites","add")};this.ClosePreview=function(){h.Hide()};this.ShowAccordian=function(t){var v=t.d.ContentContainer.PropertyPreviews;var z=t.d.ContentContainer.PropertyPreviews.length;var u='<ul id="MapAccordianContainer">';u+='       <li id="Top">';u+="           <ul>";u+='               <li class="NumberOfProperties">'+z+" Properties</li>";u+='               <li class="Close" id="MapPreviewClose">Close</li>';u+="           </ul>";u+="       </li>";u+='       <li id="Middle">';u+="           <ul>";for(var x=0;x<z;x++){if(x===0){u+='<li class="Open" id="MapPreviewPrice'+v[x].InstructionID+'"><div id="MapPreviewHeaderBar">'+v[x].Price+"</div>"}else{u+='<li class="Closed" id="MapPreviewPrice'+v[x].InstructionID+'"><div id="MapPreviewHeaderBar">'+v[x].Price+"</div>"}u+='    <div class="Details">';u+='       <img src="'+v[x].MainPhotoUrl+'" id="MapPreviewReadMoreFromPhoto'+v[x].InstructionID+'" alt="" />';u+="       <ul>";u+='           <li class="PropertyType">'+v[x].Summary+"</li>";u+='           <li class="ReadMore"><button id="MapPreviewReadMore'+v[x].InstructionID+'">Read More</button></li>';u+='           <li class="Favourites"><button id="AddToFavourites'+v[x].InstructionID+'">Favourites</button></li>';u+="       </ul>";u+="   </div>";u+="</li>"}u+="           </ul>";u+="       </li>";u+='       <li id="Bottom">';u+="       </li>";u+="   </ul>";if(h!==null){j.ClosePreview()}h=new VEShape(VEShapeType.Pushpin,new VELatLong(t.d.ContentContainer.Latitude,t.d.ContentContainer.Longitude));h.IsPopup=true;h.SetCustomIcon(u);l.AddShape(h);$("#MapPreviewClose").bind("click",j.ClosePreview);$("#MapAccordianContainer").bind("dblclick",function(){return false});var w=null;for(var y=0;y<z;y++){j.BindPreviewButton(v[y])}};this.BindPreviewButton=function(t){$("#MapPreviewReadMore"+t.InstructionID).bind("click",function(){Cwo.Page.NavigateWithReferrer(t.URLAliasPath.replace("&pound;","�"))});var u=t.URLAliasPath.replace("&pound;","�");$("#MapPreviewReadMoreFromPhoto"+t.InstructionID).bind("click",function(){Cwo.Page.NavigateWithReferrer(u)});$("li #MapPreviewPrice"+t.InstructionID+" #MapPreviewHeaderBar").bind("click",function(v){j.ExpandCollapsePreview(t,v)});new Cwo.Favourites.FavouriteButtonHandler(t.InstructionID,"AddToFavourites"+t.InstructionID,"add")};this.ExpandCollapsePreview=function(t,u){if($("#MapPreviewPrice"+t.InstructionID).hasClass("Open")){$("#MapAccordianContainer #Middle .Open").removeClass().addClass("Closed")}else{$("#MapAccordianContainer #Middle .Open").removeClass().addClass("Closed");$("#MapPreviewPrice"+t.InstructionID).removeClass().addClass("Open")}};$(document).ready(function(){Cwo.Maps.Search.Start=function(){Cwo.Page.EventController.Subscribe("Maps.BingScriptLoaded",j.LoadMap);Cwo.Page.EventController.Subscribe("ForSaleFilters.CriteriaChanged",j.Update);Cwo.Page.EventController.Subscribe("ForSaleFilters.RadiusChanged",j.RadiusChanged);Cwo.Page.EventController.Subscribe("ToLetFilters.CriteriaChanged",j.Update);Cwo.Page.EventController.Subscribe("ToLetFilters.RadiusChanged",j.RadiusChanged)};if(navigator.userAgent.indexOf("MSIE")>-1){Cwo.Maps.Search.Start();return}try{Cwo.Maps.Search.Start()}catch(t){Cwo.Error.TrackError(t)}})};