initializePage={map:function(){resizePage.init();if(typeof(development_mode)=='undefined'){window.onerror=reportBug;}
searchFilters.toggle(false);searchFilters.restripe();map=new GMap2($('gmap'));moveMapElements();force_polygons();map.checkResize();map.queryCenter=new GLatLng((max_y+min_y)/2,(max_x+min_x)/2);map.setCenter(map.queryCenter,12);if(max_x&&max_y&&min_x&&min_y){var bounds=new GLatLngBounds();bounds.extend(new GLatLng(max_y,max_x));bounds.extend(new GLatLng(min_y,min_x));zoom=map.getBoundsZoomLevel(bounds);}
map.setZoom(zoom);updateMapCenter();map.enableScrollWheelZoom();GEvent.addListener(map,"zoomend",function(){update_map();});GEvent.addListener(map,"dragend",dragEnd);GEvent.addListener(map,"moveend",moveEnd);GEvent.addListener(map,"infowindowopen",infoWindowOpen);map.addControl(new GLargeMapControl());map.addControl(new GScaleControl());resizePage.resize();window.onresize=function(){resizePage.resize();map.checkResize();};setupTooltip(map);current_lots=new Lots();new Form.Element.Observer('full_text',0.1,full_text_observer);new Form.Element.Observer('transit_stops',0.1,transit_search_observer);var temp=$('order_by').value.split('_');set_order_img(temp[0],temp[1]);var initial_page=current_page();var fff=function(){update_map(initial_page);NotificationBar.show(Content.city_search_error_txt,$('map_notification'));};if(initial_area_id){location_search(fff,{skip_open_map:true,area_id:initial_area_id,dist:initial_dist,area_type:initial_area_type,initial_load:true});}else if(!initial_location.blank()){EstatelyLog('running initial location_search');location_search(fff,{skip_open_map:true,loc:initial_location,dist:initial_dist,initial_load:true});}
else{update_map(initial_page);}
DropDown=new DropDownController();createListingGallerySpotlight();generalSpotlight=new Spotlight('general','page_container');},listing:function(){if(Estately.partner.get('isSet')===false){initializePage.map();}
else{resizePage.init();resizePage.resize();window.onresize=function(){resizePage.resize();};createListingGallerySpotlight();generalSpotlight=new Spotlight('general','page_container');}},listingAjax:function(){}};function get_permalink(){return $('permalink').href;};function save_search(){var area='';var popupDiv=new Element('div');popupDiv.update('Type a name for this search:<br/>');var form=new Element('form',{action:"/saved_searches/create",method:"post"});var nameInput=form.appendChild(new Element('input',{type:"text",name:"name",value:area}));form.appendChild(new Element('input',{type:"hidden",name:"bookmark",value:get_permalink()}));form.appendChild(new Element('input',{type:"hidden",name:"authenticity_token",value:auth_token}));form.appendChild(new Element('input',{type:"submit",value:"Save"}));popupDiv.appendChild(form);open_map_overlay("Save Search",popupDiv);nameInput.focus();nameInput.select();}
function set_daily_property_alerts(){open_alert('subscribing...');var f=function(){open_alert('You are now subscribed to saved properties email alerts');var subscription_ele=$('daily_property_alert_subscription');subscription_ele.onclick='';subscription_ele.innerHTML='You are now subscribed to daily alerts!';};new Ajax.Request('/account/set_daily_property_alerts',{method:'post',onSuccess:f});};function save_property(id){EstateyLog('USING DEPRECIATED SAVE FUNCTION. Please update.');Home.toggleState('save',id,false);}
function remove_property(id){EstateyLog('USING DEPRECIATED UNSAVE FUNCTION. Please update.');Home.toggleState('save',id,true);}
Home={'save':{'verb':'unsave','true':{url:'/saved_properties/destroy',msg1:'Unsaving home...',msg2:'Home is no longer saved.',verb1:'Unsave',verb2:'Save'},'false':{url:'/saved_properties/create',msg1:'Saving home...',msg2:'Home is now saved.',verb1:'Save',verb2:'Unsave'}},'hide':{'verb':'unhide','true':{url:'/trashed_properties/destroy',msg1:'Unhiding home...',msg2:'Home is no longer hidden.',verb1:'Unhide',verb2:'Hide'},'false':{url:'/trashed_properties/create',msg1:'Hiding home...',msg2:'The property will not appear in your search results. <a href="#" onclick="Home.toggleState(\'hide\', \'#id\', true); return false;">Undo</a>?',verb1:'Hide',verb2:'Unhide'}},toggleState:function(action,id,state){if(typeof(this[id])!=='undefined'){EstatelyLog('Still processing...');return false;}
this[id]=true;var textEl=textEl||false;var togglePoints=$$('.home_'+id);var textPoints=$$('.text_'+action+'_'+id);if(!togglePoints.length&&(typeof(state)==='undefined')){return false;}
if(typeof(state)==='undefined'){state=togglePoints[0].hasClassName('home_'+this[action].verb);}
var params=this[action][state];NotificationBar.show(params.msg1,$('map_notification'));var onSuccess=function(){togglePoints.each(function(el){el.removeClassName('home_'+params.verb1.toLowerCase()).addClassName('home_'+params.verb2.toLowerCase());if(textPoints){textPoints.each(function(el){el.update(el.innerHTML.replace(params.verb1,params.verb2));});}
NotificationBar.show(params.msg2.gsub('#id',id),$('map_notification'));});delete Home[id];if(action=='save'){if(!!state&&current_lots.has_property(id)){current_lots.property(id).unsave_property();}
else if(!state&&current_lots.has_property(id)){current_lots.property(id).save_property();}}
else if((action=='hide')&&(!state)){if(current_lots){EstatelyLog('found current_lots');current_lots.remove_property(id);}}};new Ajax.Request(params.url,{method:'post',postBody:'property_id='+id,onSuccess:onSuccess,on403:function(){}});}};function force_polygons(){if(document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#SVG","1.1")){_mSvgEnabled=true;_mSvgForced=true;}}
function add_user_area(){var newInput=new Element("input",{type:"text",name:"areas_of_interest[]",onfocus:"$('create_buyer_area_list_slow_tip').show();",onblur:"$('create_buyer_area_list_slow_tip').hide()"});var newDiv=new Element("div");newDiv.appendChild(newInput);new Insertion.Bottom($("buyer_area_list"),newDiv);new Ajax.Autocompleter(newInput,"buyer_area_list_auto_complete","/auto_complete/buyer_area",{});}
var Content={saved_properties_email_error:'Unable to update your saved property email option!',saved_properties_email_error:'Your saved property email option has been updated',bubble_error_txt:"Application Error!\n  Please try again in a few seconds.",search_error_txt:"Application Error!\n Please try your search again.",tab_error_txt:'<div class="splash_main" style="padding: 40px 55px; text-align: center;"><h2>Application Error!</h2>Something weird just happened... please try again in a few seconds.</div>',city_search_error_txt:"Unknown location!"};function open_alert(message,urgency,fade){if($("alert_message")!=null){$("alert_message").innerHTML=message;if(urgency=="high"){$("alert_table").style.backgroundColor="#fa6464";}
else{$("alert_table").style.backgroundColor="#64b1fa";};$("alert").show();if(!(fade==false)){setTimeout('Effect.Fade(\'alert\')',10000);};}}
function close_alert(){if($("alert")!=null){$("alert").style.display="none";}}
function open_map_overlay(title,msg,width){if(typeof(width)==='undefined'){width='300';}
$('map_overlay_dialog').setStyle({'width':(width+'px'),'marginLeft':((width/-2)+'px')});$('map_overlay_title').update(title);if(typeof(msg)=="string"){$('map_overlay_contents').update(msg);}else{$('map_overlay_contents').update('');$('map_overlay_contents').appendChild(msg);}
$('map_overlay').show();var height=($('map_overlay_dialog').getHeight()/-2)+'px';$('map_overlay_dialog').setStyle('margin-top:'+height);}
function close_map_overlay(){$('map_overlay').hide();}
function set_location_search(location,options){if(!options){options={};}
$('search_location').value=location;if(options.buffer){$('place_search_buffer').value=options.buffer;}
if(options.area_id){$('search_area_id').value=options.area_id;}
if(options.area_type){$('search_area_type').value=options.area_type;}}
function location_search(failure,options){if(!options){options={};}
skip_open_map=options.skip_open_map;if(!failure){failure=function(){NotificationBar.show(Content.city_search_error_txt,$('map_notification'));};}
f=function(){failure();PageUpdater.set_default('city');};ff=function(){new Ajax.Request('/map/city_search',{onFailure:f,parameters:{location:options.loc||$('search_location').value,area_id:options.area_id||$('search_area_id').value,area_type:options.area_type||$('search_area_type').value,buffer:options.dist||$('place_search_buffer').value,initial_load:options.initial_load?'true':false}});};current_lots.unselect();PageUpdater.set_loading('city');if(skip_open_map){ff();}
else{show_map({after_open:ff});}}
function scrollToResult(result){if(!result){return false;}
var results=$('search_results');results.scrollTop=result.cumulativeOffset().top-results.cumulativeOffset().top-(results.getHeight()/2-10);}
var resizePage={init:function(){this.pageContainer=$('page_container');this.searchFilters=$('search_filters');this.searchColumn=$('search_column');this.searchResults=$('search_results');this.contentColumn=$('content_column');this.contentPages=$('content_pages');this.contentMap=$('content_map');this.mapStatusbar=$('map_statusbar');this.gmap=$('gmap');this.mapHeight=130;this.searchHeightAdjust=this.searchHeightAdjust||0;if(Estately.partner.get('name')==='findwell'){this.mapHeight=200;this.searchHeightAdjust=-70;}
else if(Estately.partner.get('name')==='sutton'){this.mapHeight=122;this.searchHeightAdjust=-109;}
this.resize();},resize:function(){this.docHeight=document.viewport.getHeight();var docHeight=this.docHeight;var mapHeight=this.mapHeight;this.resizeFilters();var hContentColumn=(docHeight-mapHeight-2)+'px';this.contentColumn.setStyle('min-height:'+hContentColumn+';height:auto!important; height:'+hContentColumn);this.contentMap.setStyle('height:'+(docHeight-mapHeight-11)+'px');this.gmap.setStyle('height:'+(docHeight-mapHeight-13-24)+'px');docWidth=document.viewport.getWidth();if(docWidth>1310){var wContentMap=(docWidth-315-15-10)+'px';var wContentPages='970px';var wMapStatusbar=(docWidth-315-15-12)+'px';var wPageContainer='auto';}else if(docWidth>969){var wContentMap=(docWidth-315-15-10)+'px';var wContentPages='auto';var wMapStatusbar=(docWidth-315-15-12)+'px';var wPageContainer='auto';}else{var wContentMap='630px';var wContentPages='auto';var wMapStatusbar='628px';var wPageContainer='970px';}
this.contentMap.setStyle('width:'+wContentMap);this.contentPages.setStyle('width:'+wContentPages);this.mapStatusbar.setStyle('width:'+wMapStatusbar);this.pageContainer.setStyle('width:'+wPageContainer);if(!!this.searchColumn){this.resizeSearch(true);}},resizeSearch:function(chained){chained=chained||true;var y=this.docHeight-15-7-this.searchColumn.getHeight()+this.searchResults.getHeight();y+=this.searchHeightAdjust;if(Estately.partner.get('isSet')){y-=115;}
if(y>50){this.searchResults.setStyle('height:'+y+'px');}
else{this.searchResults.setStyle('height:50px');}
if(!chained){(function(){resizePage.resizeSearch(true);}).delay(3);}},resizeFilters:function(){var ratio=2.8;var docHeight=document.viewport.getHeight();var searchFilters=this.searchFilters;if(!!this.searchColumn){searchFilters.setStyle({'height':'auto'});var filterHeight=searchFilters.getHeight();if(docHeight/filterHeight<ratio){searchFilters.setStyle({'height':docHeight/ratio+'px'});}}}};PageUpdater={id:0,is_updating:function(){if(this.is_updating_data['gmap']||this.is_updating_data['city']){return true;}
else{return false;}},is_updating_data:{gmap:false,city:false},set_default:function(type){this.is_updating_data[type]=false;if(!this.is_updating()){this.is_updating_data[type]=true;this.hide_loading();this.is_updating_data[type]=false;}},set_loading:function(type){this.is_updating_data[type]=true;this.show_loading();},hide_loading:function(){if(this.is_updating()){$('map_loading').addClassName('hide');document.body.style.cursor='default';}
else{EstatelyLog('not hiding loading div ');}},show_loading:function(){if(this.is_updating()){$('map_loading').removeClassName('hide');document.body.style.cursor='progress';}},get_id:function(){this.id=this.id+1;return this.id;},is_current_id:function(test_id){if(test_id==this.id){return true;}
else{return false;}}};function open_element(element){Element.show(element);new Effect.Highlight(element);}
function clearDefault(el){if(el.defaultValue==el.value){el.value="";}}
function agent_slide(element){target=$(element.id+'_target');if((target.style)&&(target.style.display=='none')){Effect.SlideDown(target,{duration:0.3});element.parentNode.className='show_less';}
else{Effect.SlideUp(target,{duration:0.3});element.parentNode.className='show_more';}}
function slide(element,open_link,close_link){target=$(element.id+'_target');if((target.style)&&(target.style.display=='none')){Effect.SlideDown(target.id);if(close_link){element.innerHTML=close_link;}}
else{Effect.SlideUp(target.id);if(open_link){element.innerHTML=open_link;}}}
function blind(element,duration){target=$(element.id+'_target');if((target.style)&&(target.style.display=='none')){Effect.BlindDown(target.id,duration);}
else{Effect.BlindUp(target.id,duration);}}
function number_to_currency(nStr,precision){var multiplier=Math.pow(10,precision);nStr=Math.round(parseFloat(nStr)*multiplier)/multiplier;nStr+='';var x=nStr.split('.');var x1=x[0];var x2=x.length>1?'.'+x[1]:'';var rgx=/(\d+)(\d{3})/;while(rgx.test(x1)){x1=x1.replace(rgx,'$1'+','+'$2');}
return'$'+x1+x2;}
function complexParseFloat(string){var scrubbed=string.toString().gsub(/[^1234567890.]/,'');if(scrubbed=='')
scrubbed='0';return(parseFloat(scrubbed));}
function setCookie(name,value){document.cookie=name+'='+escape(value)+';';}
function getCookie(name){name+='=';start=document.cookie.indexOf(name);if(start!=-1){start+=name.length;end=document.cookie.indexOf(';',start);if(end==-1)end=document.cookie.length;return(unescape(document.cookie.substring(start,end)));}else{return null;}}
function setRssFeedUrl(url){var elements=$$("#map_rss_button option[value!='none']");for(i=0;i<elements.length;i++){if(!elements[i].getAttribute('base_href')&&elements[i].getAttribute('base_href')!='')
elements[i].setAttribute('base_href',elements[i].getAttribute('value'));if(elements[i].getAttribute('base_href')!='')
url=encodeURIComponent(url);elements[i].setAttribute('value',elements[i].getAttribute('base_href')+url);}}
function showNoAddressError(mls,ln){open_map_overlay("Why can't I see this address?","<p class='last-child'>Unfortunately, local MLS rules prevent us from displaying the address. You can <a href='/about/contact_us?subject=About+"+mls+"+"+ln+"'>contact us</a> for more information on any property.</p>");}
var searchFilters={toggle:function(state){var toggleFilters=$('toggle_filters');var toggleFilterText=$('toggle_filters_text');var additionFilters=$('additional_filters');if(typeof(state)==='undefined'){var state=toggleFilters.hasClassName('more');if(state){EstatelyEvent('Map - Search Filters','Show More');}
else{EstatelyEvent('Map - Search Filters','Show Less');}}
if(state){toggleFilters.removeClassName('more').addClassName('less');toggleFilterText.update('Hide Unused Search Options');additionFilters.removeClassName('hidden');additionFilters.select('*[disabled]').each(function(el){el.enable();});}else{toggleFilters.removeClassName('less').addClassName('more');toggleFilterText.update('Show More Search Options');additionFilters.addClassName('hidden');additionFilters.select('.filter').each(function(filter){if(searchFilters.checkStatus(filter)){filter.addClassName('visible');}else{filter.removeClassName('visible');}});additionFilters.select('.filter:not([class~="visible"]) select, .filter:not([class~="visible"]) input').each(function(el){el.disable();});this.restripe();}
resizePage.resizeFilters();resizePage.resizeSearch(true);},remove:function(filter){var filterLabel=$(filter).down('label').innerHTML.replace(':','');EstatelyEvent('Map - Search Filters','Remove: '+filterLabel);var filterInUse=this.checkStatus(filter);if(filterInUse){filter.removeClassName('visible').select('select, input').each(function(el){el.disable().clear().selectedIndex=0;});update_map();}else{filter.removeClassName('visible');}
resizePage.resizeFilters();resizePage.resizeSearch(true);this.restripe();},reset:function(formControl){$(formControl).clear().selectedIndex=0;},checkStatus:function(filter){var status=false;if(filter.id==='filter_transit'){transitDistance=$('transit_dist');status=!transitDistance.options[transitDistance.selectedIndex].selected;status=$('transit_stops').present();return status;}
var selectFields=filter.select('select');var inputFields=filter.select('input');selectFields.each(function(el){if(el.selectedIndex>0){status=true;}});inputFields.each(function(el){if(el.present()){status=true;}});return status;},restripe:function(){$$('#additional_filters .visible').each(function(el,i){if(i%2===0){el.removeClassName('even').addClassName('odd');}
else{el.removeClassName('odd').addClassName('even');}});}};searchBounds={toggle:function(state){var boundsMenu=$('search_bounds_menu');if(typeof(state)==='undefined'){var state=!boundsMenu.hasClassName('show');}
if(state){boundsMenu.addClassName('show');this.boundEvent=searchBounds.click.bindAsEventListener();Event.observe(document,'click',searchBounds.boundEvent);}else{boundsMenu.removeClassName('show');Event.stopObserving(document,'click',searchBounds.boundEvent);}},click:function(event){var clickedEl=Event.element(event);if((clickedEl.id!=='search_bounds')&&(!clickedEl.up('#search_bounds'))){searchBounds.toggle(false);}},set:function(anchor,distance){var boundsMenu=$('search_bounds_menu');boundsMenu.removeClassName('show');if(anchor.hasClassName('selected')){return false;}
EstatelyEvent('Map - Location Searchbar','Set: Bounds',distance.toString());anchor.up().down('.selected').removeClassName('selected');anchor.addClassName('selected');$('place_search_buffer').value=distance;this.update(distance);location_search();},update:function(distance){var boundsDisplay=$('search_bounds');switch(distance){case-1:boundsDisplay.update('<b>+</b>Map');break;case 0:boundsDisplay.update('<b>+0</b> mi');break;case 805:boundsDisplay.update('<b>+0.5</b> mi');break;case 1609:boundsDisplay.update('<b>+1</b> mi');break;case 3218:boundsDisplay.update('<b>+2</b> mi');break;case 8046:boundsDisplay.update('<b>+5</b> mi');break;case 16093:boundsDisplay.update('<b>+10</b> mi');break;}}};mapPagination={setCurrentPage:function(page){this.currentPage=page;},setPage:function(by,el){if(this.isDisabled(el)){return false;}
EstatelyEvent('Other - Optimization','Pagination','Click');update_map((this.currentPage+by));},isDisabled:function(el){if(el.hasClassName('disabled')){return true;}
if(!$('map_loading').hasClassName('hide')){return true;}
return false;}};Array.prototype.remove=function(s){for(i=0;i<this.length;i++){if(s==this[i])this.splice(i,1);}};var RedBox={showInline:function(id)
{this.showOverlay();new Effect.Appear('RB_window',{duration:0.4,queue:'end'});Element.scrollTo('RB_window');this.cloneWindowContents(id);},loading:function()
{this.showOverlay();Element.show('RB_loading');this.setWindowPosition();},addHiddenContent:function(id)
{this.removeChildrenFromNode($('RB_window'));this.moveChildren($(id),$('RB_window'));Element.hide('RB_loading');new Effect.Appear('RB_window',{duration:0.4,queue:'end'});Element.scrollTo('RB_window');this.setWindowPosition();},close:function()
{new Effect.Fade('RB_window',{duration:0.4});new Effect.Fade('RB_overlay',{duration:0.4});},showOverlay:function()
{if($('RB_redbox'))
{Element.update('RB_redbox',"");new Insertion.Top($('RB_redbox'),'<div id="RB_window" style="display: none;"></div><div id="RB_overlay" style="display: none;"></div>');}
else
{new Insertion.Bottom(document.body,'<div id="RB_redbox" align="center"><div id="RB_window" style="display: none;"></div><div id="RB_overlay" style="display: none;"></div></div>');}
new Insertion.Top('RB_overlay','<div id="RB_loading" style="display: none"></div>');this.setOverlaySize();new Effect.Appear('RB_overlay',{duration:0.4,to:0.6,queue:'end'});},setOverlaySize:function()
{$("RB_overlay").style['height']=document.viewport.getHeight()+'px';},setWindowPosition:function()
{var pagesize=this.getPageSize();$("RB_window").style['width']='auto';$("RB_window").style['height']='auto';var dimensions=Element.getDimensions($("RB_window"));var width=dimensions.width;var height=dimensions.height;$("RB_window").style['left']=((pagesize[0]-width)/2)+"px";$("RB_window").style['top']=((pagesize[1]-height)/2)+"px";},getPageSize:function(){var w=document.viewport.getWidth();var h=document.viewport.getHeight();arrayPageSize=new Array(w,h)
return arrayPageSize;},removeChildrenFromNode:function(node)
{while(node.hasChildNodes())
{node.removeChild(node.firstChild);}},moveChildren:function(source,destination)
{while(source.hasChildNodes())
{destination.appendChild(source.firstChild);}},cloneWindowContents:function(id)
{var content=$(id).cloneNode(true);content.style['display']='block';$('RB_window').appendChild(content);this.setWindowPosition();}}