/* --------- /javascripts/realius-region-selection-houses.js --------- */ 

Realius.RegionSelection={RegionHouses:{Model:ModelClass.create(),Presenter:PresenterClass.create(),MapAdapter:ModelClass.create(),FilmStripSequencer:ViewClass.create(),FilmStripAdapter:ViewClass.create(),FilmStripView:ViewClass.create()}}
Object.extend(Realius.RegionSelection.RegionHouses.Presenter.prototype,{initialize:function(args){Object.extend(this,args);},view_houseMouseOver:function(houseId){this.model.setHoverState(houseId);},view_houseMouseOut:function(houseId){this.model.clearHoverState(houseId);},view_houseClicked:function(houseId){this.model.selectHouse(houseId);},model_newHouses:function(houses){this.view.removeHouses();this.view.displayHouses(houses);},model_housesCleared:function(){this.view.removeHouses();},model_houseHover:function(house){this.view.setHoverState(house);},model_clearHouseHover:function(house){this.view.clearHoverState(house);}});Object.extend(Realius.RegionSelection.RegionHouses.Model.prototype,{initialize:function(args){this.houseMap=new Object();this.housesUrl=args.housesUrl;},showWithinRadius:function(place){this.notify("houseRequestStarted")
Ajax.makeRequest(this.housesUrl,{method:'get',asynchronous:true,evalScripts:true,parameters:{lat:place.lat,lng:place.lng,radius:place.radius},onSuccess:this._newHouses.bind(this,place.name),onComplete:this._requestFinished.bind(this,place.name)})},_requestFinished:function(){this.notify("houseRequestFinished")},_newHouses:function(name,response){var houses=response.responseJSON
var self=this;if(houses.length==0){this.notify('noHousesFound',name);}else{houses.each(function(house){self.houseMap[house.listingId]=house;});this.notify('newHouses',houses);}},clearHouses:function(){this.houseMap=new Object();this.notify('housesCleared');},setHoverState:function(houseId){var house=this.houseMap[houseId];if(house){this.notify('houseHover',house)}},clearHoverState:function(houseId){var house=this.houseMap[houseId];if(house){this.notify('clearHouseHover',house)}},selectHouse:function(houseId){var house=this.houseMap[houseId];if(house&&!house.hasBeenPlayed){this.notify('houseSelected',house)}}});Object.extend(Realius.RegionSelection.RegionHouses.MapAdapter.prototype,{initialize:function(args){Object.extend(this,args);this.markerGroup=Realius.Map.createMarkerGroup();this.map.addOverlay(this.markerGroup);},removeHouses:function(){this.markerGroup.clear();Realius.Map.hideInfoWindow();},displayHouses:function(houses){var self=this;houses.each(function(house){var marker=Realius.Map.createMarker(house.coordinates,self._iconImagePathForHouse(house));self.markerGroup.addMarker(marker,house.listingId);Realius.Map.addGEventListener(marker,"mouseover",self.triggerHouseMouseOver.bind(self,house));Realius.Map.addGEventListener(marker,"mouseout",self.triggerHouseMouseOut.bind(self,house));Realius.Map.addGEventListener(marker,"click",self.triggerHouseClicked.bind(self,house));});this.markerGroup.activate();},triggerHouseClicked:function(house){this.notify('houseClicked',house.listingId);},triggerHouseMouseOut:function(house){this.notify('houseMouseOut',house.listingId);},triggerHouseMouseOver:function(house){this.notify('houseMouseOver',house.listingId);},setHoverState:function(house){try{var marker=this.markerGroup.markersById[house.listingId];if(this.map.getBounds().containsLatLng(marker.getLatLng())){var icon='';if(house.hasBeenPlayed){icon=this.playedHoverIcon
$('listing-map-info-window').addClassName('priced-info-window');}else{icon=this.hoverIcon;$('listing-map-info-window').removeClassName('priced-info-window');}
marker.setImage(icon);Realius.Map.showInfoWindow(this.map,marker,house.infoWindow);}}catch(e){}},clearHoverState:function(house){try{var marker=this.markerGroup.markersById[house.listingId];marker.setImage(this._iconImagePathForHouse(house));Realius.Map.hideInfoWindow();}catch(e){}},_iconImagePathForHouse:function(house){return house.hasBeenPlayed?this.playedIcon:this.activeIcon;}});var ImageLoader={load:function(urls,done){var loadedCount=0;var doneAfterAll=done.callOnNth(urls.length+1);this.images=urls.map(function(url){var img=new Image();img.onload=doneAfterAll;img.onerror=doneAfterAll;img.src=url;return img;});doneAfterAll();}};var Sequencer=Class.create();Object.extend(Sequencer.prototype,{initialize:function(target){this.actionSequence=[];},hasActionsRemaining:function(){return this.actionSequence.length!=0;},sequence:function(){this.actionSequence=$A(arguments);if(!this.sequenceActive){this._performAction()}},done:function(){this._performAction();},_performAction:function(){this.sequenceActive=true;var action=this.actionSequence.shift();if(action){action();}else{this.sequenceActive=false;}}});Object.extend(Realius.RegionSelection.RegionHouses.FilmStripAdapter.prototype,{initialize:function(args){this.visibleImages=0;this.filmStripView=args.filmStripView;this.sequencer=args.sequencer;},subscribe:function(){var self=this;this.filmStripView.observe('slotClicked',function(index){self.notify('houseClicked',self.houses[index].listingId);});this.filmStripView.observe('slotMousedOver',function(index){self.notify('houseMouseOver',self.houses[index].listingId);});this.filmStripView.observe('slotMousedOut',function(index){self.notify('houseMouseOut',self.houses[index].listingId);});$('play').observe('click',function(){self.notify('houseClicked',self.houses[0].listingId)})},removeHouses:function(){var self=this;var sequencer=this.sequencer;sequencer.sequence(function(){self._hideHouses(sequencer)});},displayHouses:function(houses){this.houses=houses;var self=this;this.sequencer.sequence(function(){self._hideHouses()},function(){self._showHouses(houses)});},setHoverState:function(targetHouse){this.filmStripView.hoverListing(this._findListingIndex(targetHouse))},clearHoverState:function(targetHouse){this.filmStripView.clearListingHover(this._findListingIndex(targetHouse))},_findListingIndex:function(targetHouse){var self=this;var ret=null;this.houses.each(function(currentHouse,index){if(currentHouse==targetHouse){ret=index
throw $break;}});return ret},_hideHouses:function(){var self=this;var sequencer=this.sequencer;var visibleImages=self.visibleImages;self.visibleImages=0;var myDone=sequencer.done.callOnNth(visibleImages+1,sequencer);self.filmStripView.swishForward(function(element,index){if(index<visibleImages){self.filmStripView.hideHouse(myDone,element,index)}else{throw $break;}});myDone();},_showHouses:function(houses){var self=this;var sequencer=this.sequencer;var urls=houses.pluck("imageUrl");ImageLoader.load(urls,function(){if(!sequencer.hasActionsRemaining()){self.visibleImages=urls.length;var myDone=sequencer.done.callOnNth(self.visibleImages+1,sequencer);self.filmStripView.swishForward(function(element,index){if(index<houses.length){var house=houses[index];self.filmStripView.showHouse(myDone,element,index,house.imageUrl,house.hasBeenPlayed)}else{throw $break;}});myDone();}else{sequencer.done();}});}});Object.extend(Realius.RegionSelection.RegionHouses.FilmStripView.prototype,{subscribe:function(){var self=this;$$("ul.listing-strip a[href]").each(function(slot,index){slot.observe('click',self.notify.bind(self,"slotClicked",index))
slot.observe('mouseover',self.notify.bind(self,"slotMousedOver",index));slot.observe('mouseout',self.notify.bind(self,"slotMousedOut",index));})},swishForward:function(iterator){var index=0;var elements=$$("ul.listing-strip > *");var count=elements.length;var self=this;var doIt=function(){var current=elements[index];if(current&&index<count){try{iterator(current,index);index+=1;setTimeout(doIt,50);}catch(e){if(e!=$break){throw e;}}}};doIt();},hoverListing:function(index){$$("ul.listing-strip > *:nth-child("+(index+1)+")").invoke('addClassName','hover');},clearListingHover:function(index){$$("ul.listing-strip > *:nth-child("+(index+1)+")").invoke('removeClassName','hover');},showHouse:function(done,slot,index,url,hasBeenPlayed){var show=slot.select(".card")[0];var hide=slot.select(".card-back")[0];show.select(".content")[0].src=url;var classOperation=hasBeenPlayed?'addClassName':'removeClassName';[slot].invoke(classOperation,'played');this._swap(show,hide,done)},hideHouse:function(done,slot,index){var show=slot.select(".card-back")[0];var hide=slot.select(".card")[0];this._swap(show,hide,done)},_swap:function(toShow,toHide,done){var effects=[new Effect.Opacity(toShow,{from:0.0,to:1.0,sync:true}),new Effect.Scale(toShow,100,{scaleFrom:60,scaleContent:true,scaleFromCenter:true,sync:true}),new Effect.Opacity(toHide,{from:1.0,to:0.0,sync:true}),new Effect.Scale(toHide,60,{scaleFromCenter:true,restoreAfterFinish:true,sync:true})];toShow.show();new Effect.Parallel(effects,{duration:0.4,afterFinish:function(){toHide.hide();done();}});}});/* --------- /javascripts/new-round.js --------- */ 

var NewRound={DEFAULT_SEARCH_RADIUS:10,Coordinator:PresenterClass.create(),LocationSearchModel:ModelClass.create(),LocationSearchPresenter:PresenterClass.create(),LocationSearchView:ViewClass.create(),SearchFeedbackModel:ModelClass.create(),NamedPlacesModel:ModelClass.create(),NamedPlacesPresenter:PresenterClass.create(),NamedPlacesView:ViewClass.create(),NamedPlacesMapAdapter:ModelClass.create(),WelcomeHeaderView:ViewClass.create(),WelcomeHeaderCoordinator:PresenterClass.create(),RoundMarkerModel:ModelClass.create(),FormModel:ModelClass.create(),initialize:function(initializeArgs){MessageBus.observe('userLoggedIn',function(){Realius.reloadPage(window.location);});Event.observe(window,'load',function(){window.gmapInstance=Realius.Map.create({element:$('map')});gmapInstance.addControl(new Realius.Map.NavigationControl());var roundMarker=new HoverableGMarker(new GLatLng(0,0),initializeArgs.roundMarkerIcon);gmapInstance.addOverlay(roundMarker);roundMarker.hide();var roundMarkerModel=new NewRound.RoundMarkerModel({gMarker:roundMarker});var geocoder=new GClientGeocoder();geocoder.setBaseCountryCode((initializeArgs.countryCode&&!initializeArgs.countryCode.blank())?initializeArgs.countryCode:"us");var locationSearchView=new NewRound.LocationSearchView();var locationSearchModel=new NewRound.LocationSearchModel({geocoder:geocoder,validLocationPattern:initializeArgs.validLocationPattern,searchSuffix:initializeArgs.countryCode});new NewRound.LocationSearchPresenter({view:locationSearchView,model:locationSearchModel});var housesModel=new Realius.RegionSelection.RegionHouses.Model({housesUrl:initializeArgs.housesUrl});var regionHousesMapAdapter=new Realius.RegionSelection.RegionHouses.MapAdapter({map:gmapInstance,activeIcon:'/images/active.png',playedIcon:'/images/priced.png',hoverIcon:'/images/active-hover.png',playedHoverIcon:'/images/priced-hover.png'});new Realius.RegionSelection.RegionHouses.Presenter({model:housesModel,view:regionHousesMapAdapter});var filmStripView=new Realius.RegionSelection.RegionHouses.FilmStripView();var filmStripSequencer=new Sequencer();var filmStripAdapter=new Realius.RegionSelection.RegionHouses.FilmStripAdapter({filmStripView:filmStripView,sequencer:filmStripSequencer});new Realius.RegionSelection.RegionHouses.Presenter({model:housesModel,view:filmStripAdapter});var formModel=new NewRound.FormModel();var namedPlacesModel=new NewRound.NamedPlacesModel({placesUrl:initializeArgs.namedPlacesUrl,featuredPlacesUrl:initializeArgs.featuredPlacesUrl});var cluster=new ClusterMarker(gmapInstance,{clusterMarkerIcon:initializeArgs.placeIcon,clusterMarkerTitle:'Click to view %count nearby locations'});cluster.clusterMarkerClick=function(args){var markerSpecs=args.clusteredMarkers.map(function(marker){return function(element){element.innerHTML=marker.toHTML;element.observe('click',marker.triggerZoom);}});var infoWindow=expandTemplate('cluster-info-window',{'marker-count':args.clusteredMarkers.length,'markers':markerSpecs})
args.clusterMarker.openInfoWindowHtml(infoWindow)};var namedPlacesMapAdapter=new NewRound.NamedPlacesMapAdapter({map:gmapInstance,placeIcon:initializeArgs.placeIcon,mostLocalPlaceIcon:initializeArgs.mostLocalPlaceIcon,cluster:cluster});var namedPlacesPresenter=new NewRound.NamedPlacesPresenter({model:namedPlacesModel,view:namedPlacesMapAdapter});var breadcrumbsView=new Breadcrumb.View('breadcrumbs');var breadcrumbsModel=new Breadcrumb.Model();new Breadcrumb.Presenter({model:breadcrumbsModel,view:breadcrumbsView});new NewRound.Coordinator({locationSearchModel:locationSearchModel,roundMarkerModel:roundMarkerModel,housesModel:housesModel,mapModel:gmapInstance,formModel:formModel,namedPlacesModel:namedPlacesModel,messageBus:MessageBus,searchFeedbackModel:new NewRound.SearchFeedbackModel(),breadcrumbsModel:breadcrumbsModel});var welcomeHeaderView=new NewRound.WelcomeHeaderView();new NewRound.WelcomeHeaderCoordinator({welcomeHeaderView:welcomeHeaderView,messageBus:MessageBus,namedPlacesModel:namedPlacesModel,housesModel:housesModel});if(initializeArgs.initialPlace){(function(){namedPlacesModel.selectMostLocalPlace(initializeArgs.initialPlace)}).defer()}else{namedPlacesModel.showTopLevelPlaces();}
GEvent.addListener(gmapInstance,'click',Element.hide.curry($('search-feedback')))
NewRound.resize();Event.observe(window,'resize',NewRound.resize);});},resize:function(){var mapContainer=$('map-container');var fudgeFactor=30;var mapContainerDimensions=mapContainer.getDimensions();var mapContainerOffset=mapContainer.cumulativeOffset();var map=$('map');var marginFudge=-4;var mapMargin=Math.max(0,map.cumulativeOffset().top
-mapContainerOffset.top)+marginFudge;var derivedHeight=Metrics.getWindowHeight()-mapContainerOffset.top-fudgeFactor;var optimumHeight=Math.max(250,derivedHeight);mapContainer.setStyle({height:optimumHeight+'px'});map.setStyle({height:(optimumHeight-mapMargin)+'px'});window.gmapInstance.checkResize();}};Object.extend(NewRound.Coordinator.prototype,{initialize:function(args){this.locationSearchModel=args.locationSearchModel;this.roundMarkerModel=args.roundMarkerModel;this.housesModel=args.housesModel;this.mapModel=args.mapModel
this.formModel=args.formModel;this.namedPlacesModel=args.namedPlacesModel;this.messageBus=args.messageBus;this.searchFeedbackModel=args.searchFeedbackModel;this.breadcrumbsModel=args.breadcrumbsModel;},messageBus_placeLinkClicked:function(placeLink){var placeLink=$(placeLink);this._clear();this.namedPlacesModel.selectMostLocalPlace({lat:Number(placeLink.readAttribute('lat')),lng:Number(placeLink.readAttribute('lng')),radius:Number(placeLink.readAttribute('radius')),name:placeLink.readAttribute('title')});},messageBus_parentlessPlaceLinkClicked:function(placeLink){this.breadcrumbsModel.clearBreadcrumbs();this.messageBus_placeLinkClicked(placeLink);},locationSearchModel_searchReset:function(){this.breadcrumbsModel.homeCrumbClicked();},locationSearchModel_searchStarted:function(){this._clear();this.breadcrumbsModel.searchStarted()},locationSearchModel_searchSucceeded:function(searchInfo){this._placeMarker(searchInfo);},locationSearchModel_ambiguousSearchHappened:function(searchTerms,validPlaces){this.namedPlacesModel.showTopLevelPlaces();this.searchFeedbackModel.showAmbiguousSearchMessage(searchTerms,validPlaces);},locationSearchModel_outOfBoundsSearchHappened:function(terms,googleResults){this.namedPlacesModel.showTopLevelPlaces();var nonMatchingPlaces=googleResults.Placemark.pluck('address');this.searchFeedbackModel.showOutOfBoundsSearchMessage(terms,nonMatchingPlaces);},locationSearchModel_searchFailed:function(googleResult){this.namedPlacesModel.showTopLevelPlaces();this.searchFeedbackModel.showSearchFailedMessage(googleResult.name)},namedPlacesModel_mostLocalPlaceSelected:function(place){this._placeMarker(place);},namedPlacesModel_topLevelPlacesRequested:function(){this.breadcrumbsModel.clearBreadcrumbs();},namedPlacesModel_nonTopLevelPlacesRequested:function(place){this.breadcrumbsModel.addNonLocalCrumb(place)},namedPlacesModel_placeRequestStarted:function(request){this._clear();this.namedPlacesModel.showFeaturedPlaces({lat:request.lat,lng:request.lng});this.breadcrumbsModel.disable();},namedPlacesModel_placeRequestFinished:function(){this.breadcrumbsModel.enable();},housesModel_houseRequestStarted:function(){this.searchFeedbackModel.searchingForHousesStarted();this.breadcrumbsModel.disable();},housesModel_houseRequestFinished:function(){this.searchFeedbackModel.searchingForHousesFinished();this.breadcrumbsModel.enable();},housesModel_newHouses:function(houses){var bounds=new GLatLngBounds();bounds.extend(this.roundMarkerModel.getLatLng());houses.each(function(house){var coords=house.coordinates;bounds.extend(new GLatLng(coords[0],coords[1]))});this.mapModel.setZoom(this.mapModel.getBoundsZoomLevel(bounds)-1);},housesModel_noHousesFound:function(locationName){this.searchFeedbackModel.showSelectedLocationHasNoListingsMessage(locationName);},housesModel_houseSelected:function(house){this.formModel.setLatLng(house.coordinates[0],house.coordinates[1]);this.formModel.submitForm();},breadcrumbsModel_breadcrumbClicked:function(place){this.namedPlacesModel.showPlaces(place)},breadcrumbsModel_homeCrumbClicked:function(){this.namedPlacesModel.showTopLevelPlaces();},roundMarkerModel_markerClicked:function(place){this.formModel.setLatLng(place.lat,place.lng);this.formModel.submitForm();},_placeMarker:function(place){this.breadcrumbsModel.addMostLocalCrumb(place.name)
this.roundMarkerModel.setLocation(place)
this.roundMarkerModel.show()
this.housesModel.showWithinRadius({lat:place.lat,lng:place.lng,radius:place.radius,name:place.name});this.mapModel.setCenter(new GLatLng(place.lat,place.lng))
this.namedPlacesModel.clear();this.namedPlacesModel.showFeaturedPlaces({lat:place.lat,lng:place.lng});this.formModel.setName(place.name);this.formModel.setRadius(place.radius);},_clear:function(){this.roundMarkerModel.hide();this.housesModel.clearHouses();this.namedPlacesModel.clear();this.searchFeedbackModel.hide();}});Object.extend(NewRound.RoundMarkerModel.prototype,{initialize:function(args){this.gMarker=args.gMarker
GEvent.addListener(this.gMarker,'click',this._markerClicked.bind(this));},hide:function(){this.gMarker.hide();},show:function(){this.gMarker.show();},setLocation:function(locationInfo){this.gMarker.setLatLng(new GLatLng(locationInfo.lat,locationInfo.lng));},getLatLng:function(){return this.gMarker.getLatLng();},_markerClicked:function(){var ll=this.gMarker.getLatLng();this.notify('markerClicked',{lat:ll.lat(),lng:ll.lng()});}});Object.extend(NewRound.LocationSearchModel.prototype,{initialize:function(args){this.geocoder=args.geocoder;this.validLocationPattern=args.validLocationPattern;this.searchSuffix=args.searchSuffix},reset:function(){this.notify("searchReset");},search:function(terms){var self=this;self.notify('searchStarted');var hasSuffix=this.searchSuffix&&!this.searchSuffix.blank();var actualTerms=terms+(hasSuffix?", "+this.searchSuffix:"");var convertPlacemark=function(place){return{name:place.address,lat:place.Point.coordinates[1],lng:place.Point.coordinates[0],radius:NewRound.DEFAULT_SEARCH_RADIUS};}
this.geocoder.getLocations(actualTerms,function(searchResults){if(searchResults.Status.code==G_GEO_SUCCESS){var places=searchResults.Placemark.select(self.validLocationPattern);if(places.length==1){self.notify('searchSucceeded',convertPlacemark(places[0]));}else if(places.length>0){self.notify('ambiguousSearchHappened',terms,places.map(convertPlacemark));}else{self.notify('outOfBoundsSearchHappened',terms,searchResults);}}else{self.notify('searchFailed',searchResults);}});}});Object.extend(NewRound.LocationSearchPresenter.prototype,{view_searchRequested:function(searchTerms){this.model.search(searchTerms);},view_targetClicked:function(){this.model.reset();}});Object.extend(NewRound.LocationSearchView.prototype,{subscribe:function(){var self=this;$('location-search-form').observe('submit',function(){self.notify('searchRequested',$('location-search-box').value);});this.forwardEvents('#location-search-target',['click','targetClicked']);}});Object.extend(NewRound.FormModel.prototype,{initialize:function(args){this.formSubmitted=false;},setName:function(name){$('round_name').value=name;},setRadius:function(radius){$('round_radius').value=radius;},setLatLng:function(lat,lng){$('round_lat').value=lat;$('round_lng').value=lng;},submitForm:function(){if(!this.formSubmitted){this.formSubmitted=true
$('new-round-form').submit();}}});Object.extend(NewRound.NamedPlacesModel.prototype,{initialize:function(args){this.placesUrl=args.placesUrl;this.featuredPlacesUrl=args.featuredPlacesUrl;this.requestCancelled=false;},clear:function(){this.requestCancelled=true;this.notify('placesCleared');},showTopLevelPlaces:function(){this.notify('topLevelPlacesRequested');this._requestPlaces({localness:null})},showPlaces:function(args){this.notify('nonTopLevelPlacesRequested',args);this._requestPlaces(args);},_requestPlaces:function(args){this.notify('placesCleared');this.notify('placeRequestStarted',args);this.requestCancelled=false;Ajax.makeRequest(this.placesUrl,{parameters:args,method:'get',onSuccess:this._placesChanged.bind(this)});},showFeaturedPlaces:function(args){new Ajax.Request(this.featuredPlacesUrl,{parameters:args,method:'get'});},selectMostLocalPlace:function(place){this.notify('mostLocalPlaceSelected',place);},_placesChanged:function(ajaxResponse){this.notify("placeRequestFinished")
if(!this.requestCancelled){var places=ajaxResponse.responseJSON;this.notify('placesChanged',places);}}});Object.extend(NewRound.NamedPlacesPresenter.prototype,{model_placesCleared:function(){this.view.clear();},model_placesChanged:function(places){this.view.show(places);this.view.center();},view_placeZoomed:function(place){if(place.most_local){this.model.selectMostLocalPlace(place);}else{this.model.showPlaces({name:place.name,lat:place.lat,lng:place.lng,radius:place.radius,localness:1+place.localness});}},view_placeClicked:function(place){this.view.showInfoWindowFor(place);}});Object.extend(NewRound.NamedPlacesMapAdapter.prototype,{initialize:function(args){this.map=args.map;this.icon=args.icon;this.placeIcon=args.placeIcon;this.mostLocalPlaceIcon=args.mostLocalPlaceIcon;this.cluster=args.cluster;},clear:function(){this.map.closeInfoWindow();this.cluster.removeMarkers();},center:function(){this.cluster.fitMapToMarkers();},showInfoWindowFor:function(place){var container=$(document.createElement('div'));container.insert(place.info_window);container.select('.zoom-in').invoke('observe','click',this.notify.bind(this,'placeZoomed',place));this.map.openInfoWindowHtml(new GLatLng(place.lat,place.lng),container);},show:function(places){var self=this;var markers=[]
places.each(function(place){var coordinates=new GLatLng(place.lat,place.lng);var icon=place.most_local?self.mostLocalPlaceIcon:self.placeIcon;var marker=new HoverableGMarker(coordinates,icon);marker.toHTML=place.name;marker.triggerZoom=function(){self.notify('placeZoomed',place)};markers.push(marker)
Realius.Map.addGEventListener(marker,"click",self.notify.bind(self,'placeClicked',place));});this.cluster.addMarkers(markers);}});Object.extend(NewRound.WelcomeHeaderCoordinator.prototype,{initialize:function(args){this.welcomeHeaderView=args.welcomeHeaderView;this.messageBus=args.messageBus;this.namedPlacesModel=args.namedPlacesModel;this.housesModel=args.housesModel;},messageBus_welcomeHeaderCloseButtonClicked:function(){this.welcomeHeaderView.hide();},messageBus_welcomeHeaderShowScoreboard:function(){this.welcomeHeaderView.showWithCloseButton();this.welcomeHeaderView.hideAfter({seconds:10});},namedPlacesModel_placeRequestStarted:function(){this.welcomeHeaderView.showWithoutCloseButton();},namedPlacesModel_topLevelPlacesRequested:function(){this.welcomeHeaderView.hideBreadcrumbs();},namedPlacesModel_nonTopLevelPlacesRequested:function(place){this.welcomeHeaderView.showBreadcrumbs();},housesModel_houseRequestStarted:function(){this.welcomeHeaderView.showBreadcrumbs();},housesModel_newHouses:function(){this.welcomeHeaderView.hide();}});Object.extend(NewRound.WelcomeHeaderView.prototype,{hideBreadcrumbs:function(){$('guide').show();$('breadcrumbs-container').hide();},showBreadcrumbs:function(){$('guide').hide();$('breadcrumbs-container').show();},hide:function(){this._clearTimeout();new Effect.Parallel([new Effect.Fade('intro',{sync:true}),new Effect.Fade('welcome-header',{sync:true}),new Effect.Appear('listings-header',{sync:true})],{duration:.6})},showWithCloseButton:function(){this._clearTimeout();$('close-welcome-header').setStyle({visibility:'visible'});new Effect.Parallel([new Effect.Fade('listings-header',{sync:true}),new Effect.Appear('welcome-header',{sync:true}),new Effect.Appear('intro',{sync:true})],{duration:.6})},showWithoutCloseButton:function(){this._clearTimeout();$('close-welcome-header').setStyle({visibility:'hidden'});new Effect.Parallel([new Effect.Fade('listings-header',{sync:true}),new Effect.Appear('welcome-header',{sync:true}),new Effect.Appear('intro',{sync:true})],{duration:.6})},_clearTimeout:function(){if(this.timeout!=null){clearTimeout(this.timeout);}},hideAfter:function(args){this.timeout=setTimeout(this.hide.bind(this),1000*args.seconds);}});Object.extend(NewRound.SearchFeedbackModel.prototype,{searchingForHousesStarted:function(){$('map-loading-spinner').show();},searchingForHousesFinished:function(){$('map-loading-spinner').hide();},hide:function(){$('search-feedback').hide();},showSelectedLocationHasNoListingsMessage:function(locationName){this._showErrorMessageElement(expandTemplate('location-has-no-listings',{'location-name':locationName}));},showSearchFailedMessage:function(searchCriteria){this._showErrorMessageElement(expandTemplate('search-failed-generic',{'search-criteria':searchCriteria}));},showOutOfBoundsSearchMessage:function(searchCriteria,outOfBoundsPlaces){this._showErrorMessageElement(expandTemplate('search-failed-out-of-bounds',{'search-criteria':searchCriteria,'search-results':outOfBoundsPlaces}));},showAmbiguousSearchMessage:function(searchCriteria,validPlaces){var placeExpansions=validPlaces.map(function(place){return{"$a[href=#][onclick]":{"innerHTML":place.name,"@lat":place.lat,"@lng":place.lng,"@radius":place.radius,"@title":place.name}}});var message=expandTemplate('search-failed-ambiguous',{'search-criteria':searchCriteria,'matches':placeExpansions});this._showErrorMessageElement(message);},_showErrorMessageElement:function(element){var feedbackElement=$('search-feedback');feedbackElement.innerHTML="";feedbackElement.insert(element);feedbackElement.show();new Effect.Highlight(feedbackElement);}});var GIS={EARTH_RADIUS_IN_MILES:3963.19,deg2rad:function(degrees){return degrees/180.0*Math.PI;},distanceBetweenRadiansInMiles:function(fromLat,fromLng,toLat,toLng){return GIS.EARTH_RADIUS_IN_MILES*Math.acos(Math.sin(fromLat)*Math.sin(toLat)+
Math.cos(fromLat)*Math.cos(toLat)*Math.cos(toLng-fromLng));}}
var PlacePattern={compile:function(pattern){if(!pattern||pattern.length==0){return function(){return true};}
var op=pattern[0];var args=pattern.slice(1,pattern.length);return PlacePattern[op].apply(PlacePattern,args);},'and':function(){var subPatterns=$A(arguments).map(PlacePattern.compile);return function(mark){return subPatterns.inject(true,function(result,subPattern){return result&&subPattern(mark);});};},'or':function(){var subPatterns=$A(arguments).map(PlacePattern.compile);return function(mark){return subPatterns.inject(false,function(result,subPattern){return result||subPattern(mark);});};},'hasCountry':function(code){return function(mark){return Object.traverse(mark,"AddressDetails.Country.CountryNameCode")==code;};},'hasAdministrativeArea':function(name){return function(mark){return Object.traverse(mark,"AddressDetails.Country.AdministrativeArea.AdministrativeAreaName")==name;};},'withinMiles':function(radius,lat,lng){var fromLatR=GIS.deg2rad(lat);var fromLngR=GIS.deg2rad(lng);return function(mark){var coordinates=Object.traverse(mark,"Point.coordinates");if(!coordinates){return false;}
var toLngR=GIS.deg2rad(mark.Point.coordinates[0]);var toLatR=GIS.deg2rad(mark.Point.coordinates[1]);return GIS.distanceBetweenRadiansInMiles(fromLatR,fromLngR,toLatR,toLngR)<=radius;}}}
function HoverableGMarker(latlng,icon,inert){var marker=new GMarker(latlng,icon,inert);Realius.Map.addGEventListener(marker,"mouseover",marker.setImage.bind(marker,icon.hoverImage||icon.image));Realius.Map.addGEventListener(marker,"mouseout",marker.setImage.bind(marker,icon.image));return marker;}/* --------- /javascripts/breadcrumbs.js --------- */ 

var Breadcrumb={View:ViewClass.create(),Model:ModelClass.create(),Presenter:PresenterClass.create()}
Object.extend(Breadcrumb.View.prototype,{initialize:function(elementId){this.elementId=elementId;this.content=[];},subscribe:function(){this.forwardEvents('#start-over-button',['click','homeCrumbClicked']);},element:function(){return $(this.elementId);},updateLastCrumbWithNonMostLocal:function(name){$('last-breadcrumb-name').innerHTML="Find a play location in "+name+"...";},updateLastCrumbWithMostLocal:function(name){$('last-breadcrumb-name').innerHTML=name;},addCrumb:function(place){var expandedTemplate=expandTemplate("breadcrumb-prototype",{"name":place.name});var self=this;var element=this.element();var index=element.childElements().length;expandedTemplate.observe('click',self.notify.bind(self,'crumbClicked',index,place));element.insert(expandedTemplate)},clearLastMarker:function(){this.element().select(".last").invoke("removeClassName","last");},clear:function(){$('last-breadcrumb-name').innerHTML="Find a play location in...";this.element().innerHTML="";},removeCrumbsStartingFrom:function(crumbIndex){var element=this.element();var crumbs=element.childElements();$R(crumbIndex,crumbs.length,true).each(function(i){element.removeChild(crumbs[i]);});}});Object.extend(Breadcrumb.Presenter.prototype,{view_crumbClicked:function(crumbIndex,place){if(this.model.enabled){this.view.removeCrumbsStartingFrom(crumbIndex);this.model.breadcrumbClicked(place);}},view_homeCrumbClicked:function(){this.model.homeCrumbClicked();},model_homeCrumbClicked:function(){this.view.clear();},model_nonLocalCrumbAdded:function(place){this.view.clearLastMarker();this.view.addCrumb(place);this.view.updateLastCrumbWithNonMostLocal(place.name);},model_mostLocalCrumbAdded:function(name){this.view.clearLastMarker();this.view.updateLastCrumbWithMostLocal(name);},model_searchStarted:function(){this.view.clear();},model_clearBreadcrumbs:function(){this.view.clear();}});Object.extend(Breadcrumb.Model.prototype,{searchStarted:function(){this.notify('searchStarted');},breadcrumbClicked:function(place){this.notify("breadcrumbClicked",place)},addNonLocalCrumb:function(name){this.notify('nonLocalCrumbAdded',name);},addMostLocalCrumb:function(name){this.notify('mostLocalCrumbAdded',name);},clearBreadcrumbs:function(){this.notify('clearBreadcrumbs');},homeCrumbClicked:function(){if(this.enabled){this.notify("homeCrumbClicked");}},enable:function(){this.enabled=true;},disable:function(){this.enabled=false;}});/* --------- /javascripts/ClusterMarker.js --------- */ 

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('7 a(2c,6){2.3=2c;2.5=[];2.r=[];2.v=[];2.J=[];4(1r(6)==="1q"){6={}}2.16=(6.16)?6.16:2R;2.1g=(6.1g===h)?h:n;4(6.P){2.P=6.P}4(6.k){2.k=6.k}I{2.k=e 2Q();2.k.2P="2a://2O.29.28/27/2N.26";2.k.1M=e 25(24,23);2.k.1K=e D(9,2b);2.k.2M=e D(9,2b);2.k.2L="2a://2K.29.28/2J/2I/27/2H.26";2.k.2G=e 25(24,23)}2.18=(6.18)?6.18:"2F 2E 2D 21 2C 2B %1W 1C";4(6.E){2.E=6.E}2.Z=(6.Z)?6.Z:0;4(6.1C){2.22(6.1C)}A.1B(2.3,"2A",2,2.1O);A.1B(2.3,"2z",2,2.1D);A.1B(2.3,"2y",2,2.1P)}a.d.22=7(m){f i;4(!m[0]){f 1A=[];b(i 21 m){1A.t(m[i])}m=1A}b(i=m.8-1;i>=0;i--){m[i].q=h;m[i].g=h;m[i].o=h}2.5=2.5.2x(m)};a.d.1S=7(Q){7 $1X(20,1Z,1Y){1p e 2w(20,{2v:1Z,2u:1Y})}f 17=e 1j(),i,G,1z=[],R,1V=2;b(i=Q.8-1;i>=0;i--){R=2.5[Q[i]];R.2t=Q[i];17.12(R.p());1z.t(R)}G=$1X(17.1Q(),2.k,2.18.2s(/%1W/2r,Q.8));G.1U=17;2.J.t(A.2q(G,"1E",7(){1V.P({1x:G,2p:1z})}));1p G};a.d.P=7(1y){2.3.T(1y.1x.p(),2.3.1R(1y.1x.1U))};a.d.1J=7(){f F=2.16,u=2.3.U(),O=2.3.1f().1N(),15,1w,1u,14,1v,1t,w=2.3.2o(),i,c,13=[],1s;4(F){15=O.1m(w.2n(),u);1w=e D(15.x-F,15.y+F);1u=O.W(1w,u);14=O.1m(w.2m(),u);1v=e D(14.x+F,14.y-F);1t=O.W(1v,u);w.12(1u);w.12(1t)}2.K=h;4(1r(2.r[u])==="1q"){2.r[u]=[];2.K=n;b(i=2.5.8-1;i>=0;i--){c=2.5[i];c.g=w.1T(c.p())?n:h;c.o=c.g;4(c.g){13.t(i)}}}I{b(i=2.5.8-1;i>=0;i--){c=2.5[i];1s=c.g;c.g=w.1T(c.p())?n:h;c.o=c.g;4(!2.K&&1s!==c.g){2.K=n}4(c.g&&1r(2.r[u][i])==="1q"){13.t(i)}}}1p 13};a.d.1G=7(){f s,i,j,1o=2.3.U();b(i=2.5.8-1;i>0;i--){4(2.5[i].o){s=[];b(j=i-1;j>=0;j--){4(2.5[j].o&&2.r[1o][i].2l(2.r[1o][j])){s.t(j)}}4(s.8!==0){s.t(i);b(j=s.8-1;j>=0;j--){2.5[s[j]].o=h}2.v.t(2.1S(s))}}}};a.d.2k=7(){f 1n=2.5,11=e 1j(),i;b(i=1n.8-1;i>=0;i--){11.12(1n[i].p())}f 10=2.3.1R(11);4(2.E&&10>2.E){10=2.E}2.3.T(11.1Q(),10);2.H()};a.d.1P=7(){2.H(n)};a.d.1O=7(){4(!2.19){2.H()}I{2.19=h}};a.d.1H=7(V){f X=2.3.1f().1N(),L=2.3.U(),i,N,Y,C,B,1l,1k,1i,1h,M=2.Z;b(i=V.8-1;i>=0;i--){N=2.5[V[i]];Y=N.1L().1M;C=X.1m(N.p(),L);B=N.1L().1K;1l=e D(C.x-B.x-M,C.y-B.y+Y.2j+M);1k=e D(C.x-B.x+Y.2i+M,C.y-B.y-M);1i=X.W(1l,L);1h=X.W(1k,L);2.r[L][V[i]]=e 1j(1i,1h)}};a.d.H=7(1I){f i,l,1e=2.1J();4(2.K||1I){2.1b();4(2.1g&&2.3.U()<2.3.1f().2h()){4(1e.8>0){2.1H(1e)}2.1G()}b(i=2.v.8-1;i>=0;i--){2.3.1F(2.v[i])}b(i=2.5.8-1;i>=0;i--){l=2.5[i];4(!l.q&&l.o){2.3.1F(l);l.q=n}4(l.q&&!l.o){2.3.1d(l);l.q=h}}}};a.d.1b=7(){b(f i=2.v.8-1;i>=0;i--){2.3.1d(2.v[i])}b(i=2.J.8-1;i>=0;i--){A.2g(2.J[i])}2.v=[];2.J=[]};a.d.2f=7(){b(f i=2.5.8-1;i>=0;i--){4(2.5[i].q){2.3.1d(2.5[i])}1c 2.5[i].q;1c 2.5[i].g;1c 2.5[i].o}2.1b();2.5=[];2.r=[]};a.d.1a=7(S){f z=2.5[S];4(z.q){A.2e(z,"1E")}I{4(z.g){2.3.T(z.p());2.3.2d();2.1a(S)}I{2.3.T(z.p());2.1a(S)}}};a.d.1D=7(){2.19=n;2.H(n)};',62,178,'||this|_map|if|_mapMarkers|_2|function|length||ClusterMarker|for|_1c|prototype|new|var|_isActive|false|||clusterMarkerIcon|_36|_3|true|_makeVisible|getLatLng|_isVisible|_iconBounds|_1f|push|_12|_clusterMarkers|_1a|||_3b|GEvent|_2e|_2d|GPoint|fitMapMaxZoom|_11|_c|refresh|else|_eventListeners|_activeMarkersChanged|_29|_33|_2b|_13|clusterMarkerClick|_6|_e|_3a|setCenter|getZoom|_27|fromPixelToLatLng|_28|_2c|intersectPadding|_26|_24|extend|_1d|_17|_14|borderPadding|_a|clusterMarkerTitle|_cancelMoveEnd|triggerClick|_removeClusterMarkers|delete|removeOverlay|_37|getCurrentMapType|clusteringEnabled|_32|_31|GLatLngBounds|_30|_2f|fromLatLngToPixel|_23|_22|return|undefined|typeof|_1e|_19|_16|_18|_15|clusterMarker|_10|_d|_5|bind|markers|_zoomEnd|click|addOverlay|_filterIntersectingMapMarkers|_preCacheIconBounds|_34|_filterActiveMapMarkers|iconAnchor|getIcon|iconSize|getProjection|_moveEnd|_mapTypeChanged|getCenter|getBoundsZoomLevel|_clusterMarker|containsLatLng|clusterGroupBounds|_f|count|newClusterMarker|_9|_8|_7|in|addMarkers|34|39|GSize|png|mapfiles|com|google|http|31|_1|zoomIn|trigger|removeMarkers|removeListener|getMaximumResolution|width|height|fitMapToMarkers|intersects|getNorthEast|getSouthWest|getBounds|clusteredMarkers|addListener|gi|replace|index|title|icon|GMarker|concat|maptypechanged|zoomend|moveend|see|and|zoom|to|Click|shadowSize|arrowshadow|en_us|intl|www|shadow|infoWindowAnchor|arrow|maps|image|GIcon|256'.split('|'),0,{}))
