﻿var LocationSearch={Map:{}};
LocationSearch.Map.MapManager=function(a,c){this._map=new google.maps.Map(a,{center:c,backgroundColor:"White",zoom:15,mapTypeId:google.maps.MapTypeId.ROADMAP,streetViewControl:!0});this._svPano=this._map.getStreetView();this._svServ=new google.maps.StreetViewService;this._geocoder=new google.maps.Geocoder;this._clusterer=new MarkerClusterer(this._map,[],{gridSize:35,styles:[{url:"Images/cluster1.png",height:53,width:53},{url:"Images/cluster2.png",height:56,width:56},{url:"Images/cluster3.png",height:66,
width:66},{url:"Images/cluster4.png",height:78,width:78},{url:"Images/cluster5.png",height:90,width:90}]});this._markerLib=new LocationSearch.Map.MarkerLibrary;this._markers={};this._popups={};this._controls=[];this._overlays={};this._userGeolocation={marker:new google.maps.Marker({icon:new google.maps.MarkerImage("Images/geopin.png",new google.maps.Size(16,37),new google.maps.Point(0,0),new google.maps.Point(7,36))}),circle:new google.maps.Circle({clickable:!1,strokeColor:"#3a6ea5",strokeOpacity:0.75,
strokeWeight:3,fillColor:"#3a6ea5",fillOpacity:0.25})};this.getMap=function(){return this._map};this.getPanorama=function(){return this._svPano};this.addListener=google.maps.event.addListener;this.addControl=function(b){this._controls.push(b)};this.loadControls=function(){var b=this;$.each(this._controls,function(a,e){b._map.controls[google.maps.ControlPosition.TOP_RIGHT].push(e)})};this.addMarkerSet=function(b,a,e){this._markerLib.addSet(b,a,e)};this.addMarkerVariant=function(b,a,e){this._markerLib.addVariant(b,
a,e)};this.pinMarker=function(b,a,e,c,d,g){var h=this._markerLib.buildMarker(a,e);h.setPosition(c);d&&h.setTitle(d);if(g){this._popups[b]=new google.maps.InfoWindow({content:g});var j=this;this.addListener(h,"click",function(){j._popups[b].open(j._map,h)})}this._markers[b]=h};this.clusterMarkers=function(b,a){this._clusterer.clearMarkers();var e={};$.each(this._markers,function(c,d){b?a(c)&&(e[c]=d):e[c]=d});this._clusterer.addMarkers(e)};this.getInfoWindowContent=function(b){return this._popups[b].getContent()};
this.addPolyToOverlay=function(b,a,c,f){this._overlays[b]||(this._overlays[b]=new LocationSearch.Map.OverlayPolySet(this._map));this._overlays[b].addPoly(a,c,f)};this.setOverlayVisibility=function(b,a){this._overlays[b]&&this._overlays[b].setVisible(a)};this.hasOverlay=function(b){return!!this._overlays[b]};this.ifStreetView=function(b,a,c){b instanceof Array&&(b=new google.maps.LatLng(b[0],b[1]));this._svServ.getPanoramaByLocation(b,50,function(b,d){d==google.maps.StreetViewStatus.OK?a():c&&c()})};
this.openStreetView=function(b){b instanceof Array&&(b=new google.maps.LatLng(b[0],b[1]));var a=this._svPano;this._svServ.getPanoramaByLocation(b,50,function(c,f){if(f==google.maps.StreetViewStatus.OK){var d=c.location.latLng,g=b,d=Math.atan2(Math.sin(g.lng()-d.lng())*Math.cos(g.lat()),Math.cos(d.lat())*Math.sin(g.lat())-Math.sin(d.lat())*Math.cos(g.lat())*Math.cos(g.lng()-d.lng()))*180/Math.PI;a.setVisible(!0);a.setPano(c.location.pano);a.setPov({heading:d,pitch:0,zoom:1})}else alert("A Street View panorama is not available for this location.")})};
this.closeStreetView=function(){this._svPano.setVisible(!1)};this.geocode=function(b,a){b instanceof Array||b instanceof google.maps.LatLng?this._geocoder.geocode({latLng:b instanceof Array?new google.maps.LatLng(b[0],b[1]):b},a):typeof b=="string"&&this._geocoder.geocode({address:b},a)};this.goTo=function(b,a){if(b instanceof Array||b instanceof google.maps.LatLng)a&&this._map.setZoom(a),this._map.panTo(b instanceof Array?new google.maps.LatLng(b[0],b[1]):b);else if(typeof b=="string"){var c=this._map;
this.geocode(b,function(f,d){d==google.maps.GeocoderStatus.OK?(a&&c.setZoom(a),c.panTo(f[0].geometry.location)):d==google.maps.GeocoderStatus.ZERO_RESULTS?alert('The address "'+b+'" could not be found on the map. Please edit your entry and try your search again.'):alert("We were not able to process your request. Our attempt to turn the address into a latitude and longitude on the map resulted in the following error from Google:\n\n"+d)})}};this.geolocateUser=function(){if(!navigator.geolocation||
!navigator.geolocation.watchPosition)return!1;var b=this,a=navigator.geolocation.watchPosition(function(c){var f=new google.maps.LatLng(c.coords.latitude,c.coords.longitude);b.goTo(f);b._userGeolocation.marker.setPosition(f);b._userGeolocation.marker.setMap(b._map);c.coords.accuracy<1610&&(b._userGeolocation.circle.setRadius(c.coords.accuracy),b._userGeolocation.circle.setCenter(f),b._userGeolocation.circle.setMap(b._map));navigator.geolocation.clearWatch(a)},function(){alert("The application is unable to geolocate your position at this time.");navigator.geolocation.clearWatch(a)},
{enableHighAccuracy:!0,maximumAge:3E4,timeout:27E3})}};LocationSearch.Map.MarkerLibrary=function(){this._markerSets={};this.addSet=function(a,c,b){this._markerSets[a]=new LocationSearch.Map.MarkerSet(c,b)};this.addVariant=function(a,c,b){this._markerSets[a]&&this._markerSets[a].addVariant(c,b)};this.buildMarker=function(a,c){return this._markerSets[a]?this._markerSets[a].buildMarker(c):null}};
LocationSearch.Map.MarkerSet=function(a,c){this._shape=a;this._shadow=c;this._variants={};this.addVariant=function(b,a){this._variants[b]=a};this.buildMarker=function(b){return new google.maps.Marker({icon:this._variants[b],shadow:this._shadow,shape:this._shape})}};
LocationSearch.Map.OverlayPolySet=function(a){this._map=a;this._polys={};this._visible=!0;this.addPoly=function(a,b,i){var e=[];$.each(b,function(b,a){e.push(new google.maps.LatLng(a[0],a[1]))});this._polys[a]=new google.maps.Polygon({paths:e,strokeColor:i,strokeOpacity:0.75,strokeWeight:3,fillColor:i,fillOpacity:0.25});this._visible&&this._polys[a].setMap(this._map)};this.setVisible=function(a){if(this._visible==a)return!1;this._visible=a;var b=this;$.each(this._polys,function(i,e){var f=null;if(a)f=
b._map;e.setMap(f)})}};
LocationSearch.SynchManager=function(a,c){this._calling=null;this._callPending=!1;this._call=a;this._idleFunc=c;this._reprompt=null;this.requestCall=function(a){this._calling===null?this.call():(this._callPending=!0,this._reprompt=a,this.evalCallState())};this.setCallback=function(a){this._callback=a};this.call=function(){if(!this._calling)this._calling=!0,this._call()};this.release=function(){this._calling=!1;this.evalCallState()};this.evalCallState=function(){this._callPending&&!this._calling?(this._callPending=
!1,this._reprompt()):!this._callPending&&this._idleFunc&&this._idleFunc()}};
LocationSearch.Filter=function(){this._state={_active:!0,_category:{active:!0,value:1},_beds:{active:!1,value:1,compare:1},_baths:{active:!1,value:1,compare:1,fullOnly:!1},_price:{active:!1,minvalue:0,maxvalue:0},_sqft:{active:!1,minvalue:0,maxvalue:0},_acres:{active:!1,minvalue:0,maxvalue:0},_listdate:{active:!1,value:0},_radius:1};this._location={_latitude:0,_longitude:0};this.loadFilter=function(a){state=a};this.setLocation=function(a,c){this._location._latitude=a;this._location._longitude=c};
this.meetsCriteria=function(a){if(!this._state._active)return!0;a=appState.properties[a];if(this._state._category.active&&a.category!=this._state._category.value)return!1;if(this._state._category.active){if(this._state._category.value==1){if(this._state._beds.active)switch(this._state._beds.compare){case -1:if(a.num_beds>this._state._beds.value)return!1;case 0:if(a.num_beds!=this._state._beds.value)return!1;case 1:if(a.num_beds<this._state._beds.value)return!1}if(this._state._baths.active){var c=
this._state._baths.fullOnly?a.num_baths_full:a.num_baths_full+a.num_baths_half;switch(this._state._baths.compare){case -1:if(c>this._state._baths.value)return!1;case 0:if(c!=this._state._baths.value)return!1;case 1:if(c<this._state._baths.value)return!1}}}if(this._state._price.active)if(this._state._price.maxvalue==-1){if(a.list_price<this._state._price.minvalue)return!1}else if(a.list_price<this._state._price.minvalue||a.list_price>this._state._price.maxvalue)return!1;if(this._state._sqft.active&&
(this._state._category.value==1||this._state._category.value==4))if(this._state._sqft._sqft.maxvalue==-1){if(a.sqft<this._state._sqft.minvalue)return!1}else if(a.sqft<this._state._sqft.minvalue||a.sqft>this._state._sqft.maxvalue)return!1;if(this._state._acres.active)if(this._state._acres.maxvalue==-1){if(a.acreage<this._state._acres.minvalue)return!1}else if(a.acreage<this._state._acres.minvalue||a.acreage>this._state._acres.maxvalue)return!1;if(this._state._listdate.active&&(c=new Date,c.setDate((new Date).getDay()-
this._state._listdate.value),a.list_date<c))return!1}return!0};this.setFilter=function(a,c){this._state["_"+a]=c};this.getFilter=function(a){return this._state["_"+a]};this.getSerializedState=function(){return JSON.stringify(this._state)}};
