Cwo.RegisterNamespace("Cwo.Maps");Cwo.Maps=new function(){var a=true;this.IsScriptLoaded=function(){return a}};Cwo.RegisterNamespace("Cwo.Maps.Mini");Cwo.Maps.Mini=function(j,x,o,a,v,p,l,s,i){var n=this,e=null,w=null,d=j,k=x,t=o,r=a,m=v,u=p,b=l,g=$("#"+k),q=$("#"+u),c=$("#"+b),y="Selected",h=i,f=$("#BingMapKey").val();this.LoadMap=function(){if(w===null){w=new Cwo.MapProvider(f)}e=w.RenderMap(document.getElementById(m),{centerLat:t,centerLong:r,zoom:12});n.MapLoaded();if(Cwo.Common.GetCookie("PropertyWideMapToken")!==""){e.SetClientToken(Cwo.Common.GetCookie("PropertyWideMapToken"))}};this.MapLoaded=function(){e.AddMarker(t,r,{icon:"",typeName:"mapPoint",width:19,height:21})};this.ClickButton=function(){if(g.hasClass(y)){n.HideMap()}else{n.ShowMap()}};this.ShowMap=function(){n.RegisterRoofTopLatLongUseage();$("#"+d+" ul."+y+" li.ShowMiniMap span a").each(function(z){$(this).text("Show Mini Map")});$("#"+d+" ul."+y).each(function(z){$(this).removeClass(y)});g.addClass(y);if($("#"+u).text()==="Show Mini Map"){$("#"+u).text("Hide Mini Map")}if(!Cwo.Maps.IsScriptLoaded()){Cwo.Page.EventController.Subscribe("Maps.BingScriptLoaded",n.LoadMap)}else{n.LoadMap()}};this.HideMap=function(){g.removeClass(y);if($("#"+u).text()==="Hide Mini Map"){q.text("Show Mini Map")}};this.RegisterRoofTopLatLongUseage=function(){Cwo.AjaxCall("/webservices/Map.asmx/RegisterRooftopLatLongUseage",'{"hasRoofTopLatLongs":'+h+"}",function(){},null,true)};q.bind("click",function(z){z.preventDefault();n.ClickButton()});c.bind("click",function(z){z.preventDefault();n.HideMap()})};Cwo.RegisterNamespace("Cwo.Maps.Single");Cwo.Maps.Single=function(j,l,a,i,p,m,q,o){var k=this,d=null,n=l,h=a,f=i,g=j,r=p,c=m,b=q,e=false;this.MapLoaded=function(){if(c){var s="/images/map/singleprop.png";d.AddMarker(n,h,"")}if(r){}};this.LoadMap=function(){var v=new Cwo.MapProvider(o);var t=document.getElementById(g);var s;var u={centerLat:l,centerLong:a,zoom:i};if(r){s=$.extend(u,{mapType:Microsoft.Maps.MapTypeId.birdseye});d=v.RenderMap(t,s)}else{s=$.extend(u,{mapType:Microsoft.Maps.MapTypeId.road});d=v.RenderMap(t,s)}k.MapLoaded();if(Cwo.Common.GetCookie("PropertyWideMapToken")!==""){d.SetClientToken(Cwo.Common.GetCookie("PropertyWideMapToken"))}};if(!Cwo.Maps.IsScriptLoaded()){Cwo.Page.EventController.Subscribe("Maps.ScriptLoaded",k.LoadMap)}else{this.LoadMap()}};Cwo.RegisterNamespace("Cwo.Maps");Cwo.RegisterNamespace("Cwo.MapProvider");Cwo.MapScriptLoadListner=function(e){var c=e,a=null;function d(){return typeof(Microsoft)!=="undefined"&&typeof(Microsoft.Maps)!=="undefined"&&typeof(Microsoft.Maps.Map)!=="undefined"&&typeof(Microsoft.Maps.Polygon)!=="undefined"&&typeof(Microsoft.Maps.Pushpin)!=="undefined"}function b(){if(d()){clearInterval(a);if(typeof(c)==="function"){c()}}}a=setInterval(b,300)};Cwo.MapProvider=function(a){var b=a;this.RenderMap=function(d,c){var e={bingKey:b};$.extend(e,c);return new Cwo.Map(d,e)};this.GetRectFromBounds=function(c){var d=new Microsoft.Maps.LocationRect.fromLocations(c);return d};this.CreatePoint=function(d,c){return new Microsoft.Maps.Location(d,c)}};Cwo.Map=function(l,j){var g={mapType:Microsoft.Maps.MapTypeId.road,disableKeyboardInput:true},d=null,h=l,m=this,c=[],k=null,a=new Array(),b=new Array(),f=null;function i(){a=new Array()}$.extend(g,j);this.getColor=function(o,q,p,n){return new Microsoft.Maps.Color(o,q,p,n)};this.AddMarker=function(r,p,n){var o={toolTip:false,toolTiptext:""};$.extend(o,n);var q=new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(r,p),o);d.entities.push(q);a.push(q);if(o.toolTip){q.ToolTip=o.toolTiptext;Microsoft.Maps.Events.addHandler(q,"mouseover",function(s){if(f===null){var t={htmlContent:"<div class='mapToolTip'>"+s.target.ToolTip+"</div>"};f=new Microsoft.Maps.Infobox(d.tryPixelToLocation(new Microsoft.Maps.Point(s.getX()+10,s.getY()+10)),t);d.entities.push(f)}});Microsoft.Maps.Events.addHandler(q,"mouseout",function(){setTimeout(function(){d.entities.remove(f);f=null},50)})}return q};this.ClearMarkers=function(){for(var n=0;n<a.length;n++){d.entities.removeAt(d.entities.indexOf(a[n]))}i()};this.AddInfoBox=function(s,q,r,p){var o=new Microsoft.Maps.Location(s,q);var t={htmlContent:r};var n=new Microsoft.Maps.Infobox(o,t);b.push(n);d.entities.push(n);return n};this.Remove=function(n){d.entities.remove(n)};this.PixelToLatLong=function(n,o){var p=d.tryPixelToLocation(new Microsoft.Maps.Point(n,o));return{latitude:p.latitude,longitude:p.longitude}};this.LatLongToPixel=function(p,o){var n=d.tryLocationToPixel(new Microsoft.Maps.Location(p,o),Microsoft.Maps.PixelReference.viewport);return{x:n.x,y:n.y}};this.AttachEvent=function(n,o){Microsoft.Maps.Events.addHandler(d,n,o)};this.DrawPolygon=function(o,n){var q={fillColor:new Microsoft.Maps.Color(100,100,0,100),strokeColor:new Microsoft.Maps.Color(200,0,100,100),strokeThickness:1};var p=new Microsoft.Maps.Polygon(o,n);d.entities.push(p);k=d.entities.indexOf(p)};this.ClearPolygon=function(){d.entities.removeAt(k)};this.MoveTo=function(o,n){d.setView({center:new Microsoft.Maps.Location(o,n)})};this.GetTopLeft=function(){return d.getTargetBounds().getNorthwest()};this.GetBottomRight=function(){return d.getTargetBounds().getSoutheast()};this.GetZoom=function(){return Math.round(d.getZoom())};this.SetZoom=function(n){d.setView({zoom:n})};this.DeleteAllShapeLayers=function(){d.entities.clear()};this.GetWidth=function(){return d.getWidth()};this.GetHeight=function(){return d.getHeight()};this.GetBounds=function(){return d.getBounds()};this.SetView=function(n){d.setView({bounds:n})};this.GetCenter=function(){return d.getCenter()};var e=function(){var n;if(g.bounds!==undefined){n={credentials:g.bingKey,mapTypeId:g.mapType,bounds:g.bounds,showScalebar:true,showCopyright:false,showMapTypeSelector:true,showBreadcrumb:false,enableSearchLogo:false,disableKeyboardInput:true}}else{n={credentials:g.bingKey,mapTypeId:g.mapType,center:new Microsoft.Maps.Location(g.centerLat,g.centerLong),showScalebar:true,showCopyright:false,showMapTypeSelector:true,showBreadcrumb:false,enableSearchLogo:false,zoom:g.zoom,disableKeyboardInput:true}}d=new Microsoft.Maps.Map(h,n);Cwo.Page.EventController.FireEvent("Maps.MapRendered")};e()};
