var map,search_url,search_url_hash,active_tab_id='map',map_zoom_level=13,marker_icons=[],places={},search_address_location_mls={},search_data={'cities':{data:{},urls_on_map:[]},'counties':{data:{},urls_on_map:[]},'countries':{data:{},urls_on_map:[]},'list':{},'listings':{data:{},urls_on_map:[]},'states':{data:{},urls_on_map:[]}},activityIndicator={count:0,decrement:function(url){if(jQuery.inArray(url,this.loading)<0){return false;}
this.count--;if(this.count==0){$('#ajax-loader').css('display','none');}},increment:function(url){if(jQuery.inArray(url,this.loading)<0){this.count++;this.loading.push(url);if(this.count==1){$('#ajax-loader').css('display','block');}
return true;}
return false;},loading:[]},infoWindow={close:function(){if(this.cachedWindow){this.cachedWindow.close();}},open:function(_map,_marker,_content){if(!this.cachedWindow){this.cachedWindow=new google.maps.InfoWindow();}
if(_content){this.cachedWindow.setContent(_content);}
this.timeLastOpened=new Date();this.cachedWindow.open(_map,_marker);}},MarkerManager={dequeueReusableMarker:function(){if(this.dequeuedMarkers.length>0){return this.dequeuedMarkers.pop();}
return new google.maps.Marker();},dequeuedMarkers:[],queueReusableMarker:function(marker){marker.setMap(null);this.dequeuedMarkers.push(marker);}};$(document).ready(function(){$('#list-tab').removeClass('first').removeClass('selected').addClass('second');$('#map-tab').removeClass('second').addClass('first').addClass('selected').show();$('#search-folder').append('<div id="map-tab-content"><div id="map"></div></div>');map=new google.maps.Map(document.getElementById('map'),{center:new google.maps.LatLng(33.792416,-118.116674),mapTypeControlOptions:{style:google.maps.MapTypeControlStyle.DROPDOWN_MENU},mapTypeId:google.maps.MapTypeId.ROADMAP,zoom:map_zoom_level});$('#search-folder').append('<div id="list-tab-content"><table id="list-view-results"><thead><tr><th>Address</th><th>Price</th><th>Beds</th><th>Baths</th><th class="status">Status</th></tr></thead><tbody></tbody></table></div>');$('#listings-sort').css('display','none');$('#list-tab-content').hide();$('#content .article').addClass('js');$('#content #list-tab a').click(function(){$('#map-tab-content').hide();$('#map-tab').removeClass('selected');active_tab_id='list';$('#list-tab').addClass('selected');updateListView();$('#listings-sort').css('display','block');$('#list-tab-content').show();updateWindowHistoryState();return false;}).hover(function(){if(active_tab_id!='list'){updateListView();}});$('#content #map-tab a').click(function(){$('#listings-sort').css('display','none');$('#list-tab-content').hide();$('#list-tab').removeClass('selected');active_tab_id='map';$('#map-tab').addClass('selected');updateMapView();$('#map-tab-content').show();google.maps.event.trigger(map,'resize');updateWindowHistoryState();return false;});var map_legend_ul='<ul id="map-legend">';map_legend_ul+='<li><img alt="" height="18" src="'+map_marker_icons[map_marker_icon_types[3]][0]+'" width="20" /> '+map_marker_icons[map_marker_icon_types[3]][1]+'</li>';map_legend_ul+='<li><img alt="" height="18" src="'+map_marker_icons[map_marker_icon_types[1]][0]+'" width="20" /> '+map_marker_icons[map_marker_icon_types[1]][1]+'</li>';map_legend_ul+='<li><img alt="" height="18" src="'+map_marker_icons[map_marker_icon_types[2]][0]+'" width="20" /> '+map_marker_icons[map_marker_icon_types[2]][1]+'</li>';$('#map-tab-content').append(map_legend_ul+'</ul>');$('#map').height($('#search-folder').height()-$('#map-legend').height());$('#list-view-results tbody tr a').live('click',updateWindowLocationHash);$('#info-window-content a').live('click',updateWindowLocationHash);$('#our-brokers-search a').live('click',updateWindowLocationHash);$('#search-folder').append('<div id="search-tools"></div>');$('#search-tools').append($('#listings-sort'));$('#search-tools').append($('#ajax-loader'));var form_controls=['baths-min','beds-min','price-max','price-min'];for(var i=0;form_control=form_controls[i];i++){$('#listings-'+form_control).change(searchDidChange);}
for(var i=0;checkbox=checkboxes[i];i++){$('#listings-'+checkbox).change(searchDidChange);}
for(var i=0;property_type=property_types[i];i++){$('#listings-type-'+property_type).change(searchDidChange);}
$('#listings-sort').change(function(){updateListView();updateWindowHistoryState();});$('input[type="submit"]').each(function(){$(this).click(function(){return false;});});google.maps.event.addListener(map,'idle',function(){if(infoWindow.timeLastOpened&&infoWindow.timeLastOpened>((new Date())-1000)){setTimeout(updateMapView,1000);}else{updateMapView();}
updateWindowHistoryState();});google.maps.event.addListener(map,'maptypeid_changed',updateWindowHistoryState);google.maps.event.addListener(map,'zoom_changed',zoomDidChange);$('#listings-address-location-mls').autocomplete({delay:0,focus:function(event,ui){return false;},minLength:0,search:function(event,ui){if(search_address_location_mls&&search_address_location_mls.label&&$(this).val()!=search_address_location_mls.label){search_address_location_mls={};searchDidChange();}},select:function(event,ui){var place=places[ui.item.value];if(place){search_address_location_mls={label:ui.item.label,type:place.type,uuid:ui.item.value};if(place.latitude&&place.longitude){map.panTo(new google.maps.LatLng(place.latitude,place.longitude));}
if(map.zoom<13){map.setZoom(13);}
searchDidChange();$('#listings-address-location-mls').attr('value',ui.item.label);}
return false;},selectFirst:true,source:function(request,response){if(request.term&&request.term!=''){$.ajax({data:{text:request.term},dataType:'json',success:function(data){if(data&&data.length>0){response($.map(data,function(item){if(!places[item[3]]){places[item[3]]={latitude:item[1],longitude:item[2],name:item[0],type:item[4]};}
return{label:item[0],value:item[3]};}));}else{response([]);}},url:root+'suggestions-address-location-mls.php'});}else{response([]);}}});for(var i=0,map_marker_icon_type;map_marker_icon_type=map_marker_icon_types[i];i++){if(map_marker_icons[map_marker_icon_type][1]!=undefined){var icon=new google.maps.MarkerImage(map_marker_icons[map_marker_icon_type][0],new google.maps.Size(20,18),new google.maps.Point(0,0),new google.maps.Point(9,10));var icon_shadow=new google.maps.MarkerImage(map_marker_icons.shadow,new google.maps.Size(27,18),new google.maps.Point(0,0),new google.maps.Point(9,10));marker_icons.push([icon,icon_shadow]);}}
marker_icons.push([new google.maps.MarkerImage(map_marker_icons.group[0],new google.maps.Size(20,31),new google.maps.Point(0,0),new google.maps.Point(15,20)),new google.maps.MarkerImage(map_marker_icons.group_shadow,new google.maps.Size(29,31),new google.maps.Point(0,0),new google.maps.Point(15,20))]);$(window).bind('hashchange',windowLocationHashDidChange).trigger('hashchange');});function windowLocationHashDidChange(){$('#listings-baths-min').val('');$('#listings-beds-min').val('');$('#listings-price-max').val('');$('#listings-price-min').val('');for(var i=0,checkbox;checkbox=checkboxes[i];i++){$('#listings-'+checkbox).attr('checked',false);}
for(var i=0,property_type;property_type=property_types[i];i++){$('#listings-type-'+property_type).attr('checked',false);}
$('#listings-type-residential-single-family').attr('checked',true);var window_location_hash_array=(window.location.search.slice(1)+window.location.hash.slice(1)).split('&');var view_name;for(var i=0,hash_argument;hash_argument=window_location_hash_array[i];i++){var hash_argument_array=hash_argument.split('=',2);if(hash_argument_array[0]){if(hash_argument_array[0]=='address-location-mls'){$('#listings-address-location-mls').attr('value',unescape(hash_argument_array[1]));search_address_location_mls.label=hash_argument_array[1];}else if(hash_argument_array[0]=='center'){var center_array=hash_argument_array[1].split(',');if(center_array&&center_array[0]&&center_array[1]){map.setCenter(new google.maps.LatLng(parseFloat(center_array[0]),parseFloat(center_array[1])));}}else if(hash_argument_array[0]=='map-type'&&hash_argument_array[1]){if(hash_argument_array[1]=='hybrid'){map.setMapTypeId(google.maps.MapTypeId.HYBRID);}else if(hash_argument_array[1]=='roadmap'){map.setMapTypeId(google.maps.MapTypeId.ROADMAP);}else if(hash_argument_array[1]=='satellite'){map.setMapTypeId(google.maps.MapTypeId.SATELLITE);}else if(hash_argument_array[1]=='terrain'){map.setMapTypeId(google.maps.MapTypeId.TERRAIN);}}else if(hash_argument_array[0]=='sort'){$('#listings-sort option[value='+hash_argument_array[1]+']').attr('selected','selected');}else if(hash_argument_array[0]=='types'){var search_property_types=hash_argument_array[1].split(',');for(var j=0,search_property_type;search_property_type=search_property_types[j];j++){$('#listings-type-'+search_property_type).attr('checked',true);}}else if(hash_argument_array[0]=='view'){view_name=hash_argument_array[1];}else if(hash_argument_array[0]=='zoom'){map.setZoom(parseInt(hash_argument_array[1],10));}else if(jQuery.inArray(hash_argument_array[0],checkboxes)>=0){$('#listings-'+hash_argument_array[0]).attr('checked',true);}else if(jQuery.inArray(hash_argument_array[0],['baths-min','beds-min','price-max','price-min'])>=0){$('#listings-'+hash_argument_array[0]).val(hash_argument_array[1]);}else if(jQuery.inArray(hash_argument_array[0],['area-uuid','city-uuid','county-uuid','listing-uuid','zip-code-uuid'])>=0){var hash_argument_array_0_split=hash_argument_array[0].split('-uuid');search_address_location_mls.type=hash_argument_array_0_split[0];search_address_location_mls.uuid=hash_argument_array[1];}}}
searchDidChange();if(view_name&&(view_name=='list'||view_name=='map')){if(tilesHaveLoaded()){if(view_name=='list'){$('#list-tab a').trigger('click');}else if(view_name=='map'){$('#map-tab a').trigger('click');}}else{google.maps.event.addListenerOnce(map,'tilesloaded',function(){if(view_name=='list'){$('#list-tab a').trigger('click');}else if(view_name=='map'){$('#map-tab a').trigger('click');}});}}}
function addMarkersToViewForNameWithMarkerFunction(name,addMarkerFunction){removeOldSearchDataWithName(name);var states_for_search_url=search_data[name].data[search_url];if(states_for_search_url){if(!states_for_search_url.markers){var markers=[];for(var i=0,state;state=states_for_search_url.data[i];i++){markers.push(addMarkerFunction(state));}
search_data[name].data[search_url].markers=markers;search_data[name].urls_on_map.push(search_url);}}else{fetchData();}}
function addMarkerToMapForCity(city_info){var marker=MarkerManager.dequeueReusableMarker();marker.icon=marker_icons[5][0];marker.position=new google.maps.LatLng(city_info[2],city_info[3]);marker.shadow=marker_icons[5][1];marker.title=city_info[1];marker.setMap(map);google.maps.event.addListener(marker,'click',function(){infoWindow.open(map,marker,city_info[1]);});return marker;}
function addMarkerToMapForCountry(country_info){var marker=MarkerManager.dequeueReusableMarker();marker.icon=marker_icons[5][0];marker.position=new google.maps.LatLng(country_info[2],country_info[3]);marker.shadow=marker_icons[5][1];marker.title=country_info[1];marker.setMap(map);google.maps.event.addListener(marker,'click',function(){infoWindow.open(map,marker,country_info[1]);});return marker;}
function addMarkerToMapForCounty(county_info){var marker=MarkerManager.dequeueReusableMarker();marker.icon=marker_icons[5][0];marker.position=new google.maps.LatLng(county_info[2],county_info[3]);marker.shadow=marker_icons[5][1];marker.title=county_info[1];marker.setMap(map);google.maps.event.addListener(marker,'click',function(){infoWindow.open(map,marker,county_info[1]);});return marker;}
function addMarkerToMapForListing(listing_info,googleMapsLatLngFunction,googleMapsEventAddListenerFunction){var marker=MarkerManager.dequeueReusableMarker();marker.icon=marker_icons[listing_info[14]][0];marker.position=new googleMapsLatLngFunction(listing_info[4],listing_info[5]);marker.shadow=marker_icons[listing_info[14]][1];if(listing_info[11]==undefined){marker.title='';}else{marker.title=listing_info[11];}
marker.setMap(map);googleMapsEventAddListenerFunction(marker,'click',function(){infoWindow.close();var info_window_content='';var address_lines=[];if(listing_info[11]!=undefined){address_lines.push('<span class="street-address">'+listing_info[11]+'</span>');}
var address_lines_location=[];if(listing_info[9]!=undefined){address_lines_location.push('<span class="locality">'+listing_info[9]+'</span>');}
if(listing_info[10]!=undefined){address_lines_location.push('<span class="region">'+listing_info[10]+'</span>');}
if(listing_info[12]!=undefined){address_lines_location.push('<span class="postal-code">'+listing_info[12]+'</span>');}
address_lines.push(address_lines_location.join(', '));info_window_content+='<p><a href="'+getURLWithListingInfo(listing_info)+'">'+address_lines.join('<br />')+'</a></p>';info_window_content+='<ul>';if(listing_info[2]!=undefined){info_window_content+='<li>Price: '+listing_info[2]+'</li>';}
if(listing_info[7]!=undefined){info_window_content+='<li>Beds: '+listing_info[7]+'</li>';}
if(listing_info[6]!=undefined){info_window_content+='<li>Baths: '+listing_info[6]+'</li>';}
if(listing_info[15]!=undefined&&listing_info[15]===true){info_window_content+='<li>Pool</li>';}
if(listing_info[13]!=undefined){info_window_content+='<li>Status: '+listing_info[13]+'</li>';}
if(listing_info[1]!=undefined&&listing_info[1]!=''){info_window_content+='<li>MLS #: '+listing_info[1]+'</li>';}
if(listing_info[8]!=undefined){info_window_content+='<li>MLS Area: '+listing_info[8]+'</li>';}
info_window_content+='</ul>';info_window_content+='<p><a href="'+getURLWithListingInfo(listing_info)+'">Full listing description</a></p>';infoWindow.open(map,marker,'<div id="info-window-content">'+info_window_content+'</div>');});return marker;}
function addMarkerToMapForState(state_info){var marker=MarkerManager.dequeueReusableMarker();marker.icon=marker_icons[5][0];marker.position=new google.maps.LatLng(state_info[2],state_info[3]);marker.shadow=marker_icons[5][1];marker.title=state_info[1];marker.setMap(map);google.maps.event.addListener(marker,'click',function(){infoWindow.open(map,marker,state_info[1]);});return marker;}
function didReceiveCountriesForSearchURL(countries,searchURL){search_data.countries.data[searchURL]={data:countries};updateMapView();}
function didReceiveListForSearchURL(listings,searchURL){search_data.list={listings:listings,searchURL:searchURL};updateListView();}
function didReceiveStatesForSearchURL(states,searchURL){search_data.states.data[searchURL]={data:states};updateMapView();}
function didReceiveTileForSearchURLWithCities(tile,searchURL,cities){search_data.cities.data[searchURL].data[tile]=cities;search_data.cities.data[searchURL].tiles.push(tile);updateMapView();}
function didReceiveTileForSearchURLWithCounties(tile,searchURL,counties){search_data.counties.data[searchURL].data[tile]=counties;search_data.counties.data[searchURL].tiles.push(tile);updateMapView();}
function didReceiveTileForSearchURLWithListings(tile,searchURL,listings){search_data.listings.data[searchURL].data[tile]=listings;search_data.listings.data[searchURL].tiles.push(tile);if(active_tab_id=='list'){updateListView();}else if(active_tab_id=='map'){updateMapView();}}
function fetchData(){if(tilesHaveLoaded()){var base_tile_search_url=search_url+'&search_url='+escape(search_url)+'&';var zoom=map.getZoom();if(zoom<4){base_tile_search_url+='zoom=country';if(search_data.countries.data[search_url]==undefined){getJSONAtURLWithCallbackFunction(base_tile_search_url,function(data){didReceiveCountriesForSearchURL(data.countries,data.search_url);});}}else if(zoom<6){base_tile_search_url+='zoom=state';if(search_data.states.data[search_url]==undefined){getJSONAtURLWithCallbackFunction(base_tile_search_url,function(data){didReceiveStatesForSearchURL(data.states,data.search_url);});}}else if(zoom<10){base_tile_search_url+='zoom=county&tile=';if(search_data.counties.data[search_url]==undefined){search_data.counties.data[search_url]={'data':{},'tile_markers':{},'tiles':[],'tiles_on_map':[]};}
var tiles=getCountyTilesForCurrentBounds();var tile_data=search_data.counties.data[search_url].data;for(var i=0,tile;tile=tiles[i];i++){if(tile_data[tile]==undefined){getJSONAtURLWithCallbackFunction(base_tile_search_url+tile,function(data){didReceiveTileForSearchURLWithCounties(data.tile,data.search_url,data.counties);});}}}else if(zoom<13){base_tile_search_url+='zoom=city&tile=';if(search_data.cities.data[search_url]==undefined){search_data.cities.data[search_url]={'data':{},'tile_markers':{},'tiles':[],'tiles_on_map':[]};}
var tiles=getCityTilesForCurrentBounds();var tile_data=search_data.cities.data[search_url].data;for(var i=0,tile;tile=tiles[i];i++){if(tile_data[tile]==undefined){getJSONAtURLWithCallbackFunction(base_tile_search_url+tile,function(data){didReceiveTileForSearchURLWithCities(data.tile,data.search_url,data.cities);});}}}else{fetchListingDataForTiles(getListingTilesForCurrentBounds());}}else{google.maps.event.addListenerOnce(map,'tilesloaded',fetchData);}}
function fetchListingDataForTiles(tiles){if(search_data.listings.data[search_url]==undefined){search_data.listings.data[search_url]={'data':{},'tile_markers':{},'tiles':[],'tiles_on_map':[]};}
var base_tile_search_url=search_url+'&search_url='+escape(search_url)+'&tile=';var tile_data=search_data.listings.data[search_url].data;for(var i=0,tile;tile=tiles[i];i++){if(tile_data[tile]==undefined){getJSONAtURLWithCallbackFunction(base_tile_search_url+tile,function(data){didReceiveTileForSearchURLWithListings(data.tile,data.search_url,data.listings);});}}}
function formatBaths(baths){var baths_int=parseInt(baths,10);if(baths_int===parseFloat(baths)){return baths_int;}else{return baths_int+'+';}}
function getJSONAtURLWithCallbackFunction(request_url,response_callback_function){if(activityIndicator.increment(request_url)){$.getJSON(request_url,function(data,textStatus){if(textStatus=='success'){response_callback_function(data);}
activityIndicator.decrement(request_url);});}}
function getURLWithListingInfo(listing_info){var url_parts=[];if(listing_info[11]!=undefined){url_parts.push(listing_info[11]);}
if(listing_info[9]!=undefined){url_parts.push(listing_info[9]);}
if(listing_info[10]!=undefined){url_parts.push(listing_info[10]);}
if(listing_info[12]!=undefined){url_parts.push(listing_info[12]);}
return root+'listings/'+listing_info[0]+'-'+replaceTextWithNewTextInString(' ','-',url_parts.join('-'))+'/';}
function getCityTilesForCurrentBounds(){var bounds=map.getBounds();var bottom=Math.floor(bounds.getSouthWest().lat()+90);var left=Math.floor(bounds.getSouthWest().lng()+180);var right=bounds.getNorthEast().lng()+180;var top=bounds.getNorthEast().lat()+90;var tiles=[];for(var a=bottom;a<top;a++){for(var b=left;b<right;b++){tiles.push(2+b+(360*a));}}
return tiles;}
function getCountyTilesForCurrentBounds(){var bounds=map.getBounds();var bottom=Math.floor((bounds.getSouthWest().lat()+90)/10);var left=Math.floor((bounds.getSouthWest().lng()+180)/10);var right=(bounds.getNorthEast().lng()+180)/10;var top=(bounds.getNorthEast().lat()+90)/10;var tiles=[];for(var a=bottom;a<top;a++){for(var b=left;b<right;b++){tiles.push(2+b+(36*a));}}
return tiles;}
function getListingTilesForCurrentBounds(){var bounds=map.getBounds();var bottom=Math.floor(10*(bounds.getSouthWest().lat()+90));var left=Math.floor(10*(bounds.getSouthWest().lng()+180));var right=10*(bounds.getNorthEast().lng()+180);var top=10*(bounds.getNorthEast().lat()+90);var tiles=[];for(var a=bottom;a<top;a++){for(var b=left;b<right;b++){tiles.push(2+b+(3600*a));}}
return tiles;}
function removeAllSearchDataForName(name){var urls=search_data[name].urls_on_map;if(urls.length>0){for(var i=0,url;url=urls[i];i++){if(name=='countries'||name=='states'){removeMarkersOnMapWithNameAndSearchURL(name,url);}else{removeTilesOnMapWithNameAndSearchURL(name,url);}}
search_data[name].urls_on_map=[];}}
function removeMarkersOnMapWithNameAndSearchURL(name,url){var data_for_url=search_data[name].data[url];if(data_for_url){var markers=data_for_url.markers;if(markers&&markers.length>0){for(var i=0,marker;marker=markers[i];i++){MarkerManager.queueReusableMarker(marker);}
delete search_data[name].data[url].markers;}}}
function removeTileWithNameAndSearchURL(tile,name,url){var markers_for_tile=search_data[name].data[url].tile_markers[tile];if(markers_for_tile&&markers_for_tile.length>0){for(var i=0,marker;marker=markers_for_tile[i];i++){MarkerManager.queueReusableMarker(marker);}}
delete search_data[name].data[url].tile_markers[tile];}
function removeTilesNotInViewForCurrentSearchURLWithTilesAndName(tiles,name){var tiles_on_map=search_data[name].data[search_url].tiles_on_map;if(tiles_on_map.length>0){var new_tiles_on_map=[];for(var i=0,tile;tile=tiles_on_map[i];i++){if(jQuery.inArray(tile,tiles)<0){removeTileWithNameAndSearchURL(tile,name,search_url);}else{new_tiles_on_map.push(tile);}}
search_data[name].data[search_url].tiles_on_map=new_tiles_on_map;}}
function removeTilesOnMapWithNameAndSearchURL(name,url){var tiles=search_data[name].data[url].tiles_on_map;if(tiles&&tiles.length>0){for(var i=0,tile;tile=tiles[i];i++){removeTileWithNameAndSearchURL(tile,name,url);}}}
function removeOldSearchDataWithName(name){var urls=search_data[name].urls_on_map;if(urls.length>0){for(var i=0,url;url=urls[i];i++){if(url!=search_url){if(name=='countries'||name=='states'){removeMarkersOnMapWithNameAndSearchURL(name,url);}else{removeTilesOnMapWithNameAndSearchURL(name,url);}}}
search_data[name].urls_on_map=[search_url];}}
function replaceTextWithNewTextInString(textToFind,replacementText,string){if(replacementText===undefined){replacementText='';}
return string.replace(new RegExp('['+textToFind+']','g'),replacementText);}
function searchDidChange(){var search_parameters=[];if(search_address_location_mls&&search_address_location_mls.uuid){if(search_address_location_mls.type=='listing'){search_parameters.push('listing-uuid='+search_address_location_mls.uuid);}else{search_parameters.push(search_address_location_mls.type+'-uuid='+search_address_location_mls.uuid);}}
var price_min=parseInt($('#listings-price-min option:selected').attr('value'),10);if(price_min){search_parameters.push('price-min='+price_min);}
$('#listings-price-max option').each(function(){if(price_min&&parseInt($(this).attr('value'),10)<=price_min){$(this).attr('disabled',true);}else{$(this).removeAttr('disabled');}});var price_max=parseInt($('#listings-price-max option:selected').attr('value'),10);if(price_max){search_parameters.push('price-max='+price_max);}
$('#listings-price-min option').each(function(){if(price_max&&parseInt($(this).attr('value'),10)>=price_max){$(this).attr('disabled',true);}else{$(this).removeAttr('disabled');}});var baths=parseInt($('#listings-baths-min option:selected').attr('value'),10);if(baths){search_parameters.push('baths-min='+baths);}
var beds=parseInt($('#listings-beds-min option:selected').attr('value'),10);if(beds){search_parameters.push('beds-min='+beds);}
for(var i=0;checkbox=checkboxes[i];i++){if($('#listings-'+checkbox).attr('checked')){if(checkbox=='new-within-days'||checkbox=='price-reduced-within-days'){search_parameters.push(checkbox+'=7');}else{search_parameters.push(checkbox+'=yes');}}}
var search_property_types=[];for(var i=0;property_type=property_types[i];i++){if($('#listings-type-'+property_type).attr('checked')){search_property_types.push(property_type);}}
if(search_property_types.length>0){search_parameters.push('types='+search_property_types.join(','));}
var original_search_url=search_url;var search_parameters_joined=search_parameters.join('&');search_url=root+'listings/?'+search_parameters_joined;search_url_hash=search_parameters_joined;if(original_search_url!=search_url){updateWindowHistoryState();$('#list-view-results tbody').empty();if(active_tab_id=='list'){updateListView();}else if(active_tab_id=='map'){infoWindow.close();updateMapView();}}}
function shouldFetchDataAfterAddingTilesToViewForNameWithMarkerFunction(tiles,name,addMarkerFunction){removeOldSearchDataWithName(name);var need_to_fetch_data=false;if(search_data[name].data[search_url]){removeTilesNotInViewForCurrentSearchURLWithTilesAndName(tiles,name);var googleMaps=google.maps;var googleMapsLatLngFunction=googleMaps.LatLng;var googleMapsEventAddListenerFunction=googleMaps.event.addListener;for(var i=0,tile;tile=tiles[i];i++){if(search_data[name].data[search_url].data[tile]){if(!search_data[name].data[search_url].tile_markers[tile]){var markers=[];var marker_data=search_data[name].data[search_url].data[tile];for(var j=0,marker_info;marker_info=marker_data[j];j++){markers.push(addMarkerFunction(marker_info,googleMapsLatLngFunction,googleMapsEventAddListenerFunction));}
search_data[name].data[search_url].tile_markers[tile]=markers;search_data[name].data[search_url].tiles_on_map.push(tile);}}else{need_to_fetch_data=true;}}
if(jQuery.inArray(search_url,search_data[name].urls_on_map)<0){search_data[name].urls_on_map.push(search_url);}}else{need_to_fetch_data=true;}
return need_to_fetch_data;}
function sortListingsByArea(a,b){if(a[8]==b[8]){return sortListingsByPrice(a,b);}
return((a[8]<b[8])?-1:((a[8]>b[8])?1:0));}
function sortListingsByBeds(a,b){if(a[7]==b[7]){return a[6]-b[6];}
if(!a[7]&&b[7]){return-1;}else if(a[7]&&!b[7]){return 1;}
return a[7]-b[7];}
function sortListingsByPrice(a,b){if(a[2]==b[2]){return sortListingsByBeds(a,b);}
var a_price;if(a[2]){a_price=parseFloat(replaceTextWithNewTextInString('$','',replaceTextWithNewTextInString(',','',a[2])));}else{a_price=0;}
var b_price;if(b[2]){b_price=parseFloat(replaceTextWithNewTextInString('$','',replaceTextWithNewTextInString(',','',b[2])));}else{b_price=0;}
return a_price-b_price;}
function sortListingsByZIPCode(a,b){if(a[12]==b[12]){return sortListingsByPrice(a,b);}
return parseInt(a[12],10)-parseInt(b[12],10);}
function tilesHaveLoaded(){if(map&&map.getBounds()){return true;}
return false;}
function updateListView(){var table=$('#list-view-results');$('tbody',table).empty();var search_url_with_lat_lng=search_url+'&latitude='+map.getCenter().lat().toFixed(3)+'&longitude='+map.getCenter().lng().toFixed(3);var list_view_search_url=search_url_with_lat_lng+'&search_url='+escape(search_url_with_lat_lng);if(search_data.list.searchURL==search_url_with_lat_lng){var listings=search_data.list.listings;var sort=$('#listings-sort option:selected').attr('value');var sort_function;if(sort=='area'){sort_function=sortListingsByArea;}else if(sort=='beds'){sort_function=sortListingsByBeds;}else if(sort=='price'){sort_function=sortListingsByPrice;}else if(sort=='zip-code'){sort_function=sortListingsByZIPCode;}
if(sort_function){var original_listings=listings;var listings=[];for(var i=0,listing;listing=original_listings[i];i++){listings.push(listing);}
listings.sort(sort_function);}
var listing_table_row='';for(var i=0,listing;listing=listings[i];i++){listing_table_row+='<tr';if(i%2===0){listing_table_row+=' class="odd"';}
listing_table_row+='>';listing_table_row+='<td class="address"><a href="'+getURLWithListingInfo(listing)+'">';var address=[];if(listing[11]!=undefined){address.push(listing[11]);}
if(listing[9]!=undefined){address.push(listing[9]);}
if(listing[10]!=undefined){address.push(listing[10]);}
if(listing[12]!=undefined){address.push(listing[12]);}
if(address.length==0){listing_table_row+='Address withheld by seller';}else{listing_table_row+=address.join(', ');if(listing[8]!=undefined){listing_table_row+='<br /><span class="address-area">'+listing[8]+'</span>';}}
listing_table_row+='</a></td>';listing_table_row+='<td class="price">';if(listing[2]!=undefined){listing_table_row+=listing[2];}
listing_table_row+='</td>';listing_table_row+='<td>';if(listing[7]!=undefined){listing_table_row+=listing[7];}
listing_table_row+='</td>';listing_table_row+='<td>';if(listing[6]!=undefined){listing_table_row+=formatBaths(listing[6]);}
listing_table_row+='</td>';listing_table_row+='<td class="status">';if(listing[13]!=undefined){listing_table_row+=listing[13];}
listing_table_row+='</td>';listing_table_row+='</tr>';}
$('tbody',table).append(listing_table_row);}else{getJSONAtURLWithCallbackFunction(list_view_search_url,function(data){didReceiveListForSearchURL(data.listings,data.search_url);});}}
function updateMapView(){if(map.zoom<4){addMarkersToViewForNameWithMarkerFunction('countries',addMarkerToMapForCountry);}else if(map.zoom<6){addMarkersToViewForNameWithMarkerFunction('states',addMarkerToMapForState);}else if(tilesHaveLoaded()){var need_to_fetch_data=false;if(map.zoom<10){need_to_fetch_data=shouldFetchDataAfterAddingTilesToViewForNameWithMarkerFunction(getCountyTilesForCurrentBounds(),'counties',addMarkerToMapForCounty);}else if(map.zoom<13){need_to_fetch_data=shouldFetchDataAfterAddingTilesToViewForNameWithMarkerFunction(getCityTilesForCurrentBounds(),'cities',addMarkerToMapForCity);}else{need_to_fetch_data=shouldFetchDataAfterAddingTilesToViewForNameWithMarkerFunction(getListingTilesForCurrentBounds(),'listings',addMarkerToMapForListing);}
if(need_to_fetch_data===true){fetchData();}}else{google.maps.event.addListenerOnce(map,'tilesloaded',updateMapView);}}
function updateWindowHistoryState(fallback_function){if(window.history.replaceState){window.history.replaceState('','','?'+getStateParameterString());window.location.hash='';}else if(fallback_function){fallback_function();}}
function updateWindowLocationHash(){updateWindowHistoryState(function(){window.location.hash=getStateParameterString();});}
function getStateParameterString(){var new_hash='';if(search_url_hash){new_hash+=search_url_hash+'&';}
new_hash+='view='+active_tab_id+'&map-type='+map.getMapTypeId()+'&zoom='+map.getZoom()+'&center='+map.getCenter().toUrlValue();if(search_address_location_mls&&search_address_location_mls.label){new_hash+='&address-location-mls='+search_address_location_mls.label;}
var sort_value=$('#listings-sort option:selected').attr('value');if(sort_value&&sort_value!=''){new_hash+='&sort='+sort_value;}
return new_hash;}
function zoomDidChange(){var clear=false;var zoom=map.zoom;if(zoom<4){if(map_zoom_level>=4){clear=true;}}else if(zoom<6){if(map_zoom_level<=4||map_zoom_level>=6){clear=true;}}else if(zoom<10){if(map_zoom_level<=6||map_zoom_level>=10){clear=true;}}else if(zoom<13){if(map_zoom_level<=10||map_zoom_level>=13){clear=true;}}else if(map_zoom_level<13){clear=true;}
if(clear===true){infoWindow.close();if(map_zoom_level>=13){removeAllSearchDataForName('listings');}else if(map_zoom_level>=10){removeAllSearchDataForName('cities');}else if(map_zoom_level>=6){removeAllSearchDataForName('counties');}else if(map_zoom_level>=4){removeAllSearchDataForName('states');}else{removeAllSearchDataForName('countries');}}
map_zoom_level=zoom;updateMapView();}
$(window).unload(function(){});
