(function(){var Dom=YAHOO.util.Dom,Ev=YAHOO.util.Event,Rs=YAHOO.ps.Realestate.results;var animateSpeed=1.2,easing=YAHOO.util.Easing.easeBoth;var config={trackListings:"",trackSearches:"",maxZoom:0,resultsZoom:0,searchCityZoom:0,searchZipZoom:0,newDom:7,offices:"",resultsMapLimit:200,closePixel:20,displaySecNav:0,swBoundary:[0,0],neBoundary:[0,0]};var setConfig=function(keys){for(var i in keys){if(YAHOO.lang.hasOwnProperty(keys,i)){config[i]=keys[i]}}};var getZoom=function(rsSearch){var rsZip=new RegExp(/(^\d{5}$)/);var rsZoom=config.searchCityZoom;if(rsZip.test(rsSearch)){rsZoom=config.searchZipZoom}return rsZoom};var onInitMapResults=new YAHOO.util.CustomEvent("onInitMapResults"),onInitListResults=new YAHOO.util.CustomEvent("onInitListResults");var resultsTab,resultsMsg,paginator,orderTop,orderBottom,limitTop,limitBottom,listNavResults,map,geo;var updateMessage=function(txt,type,anim){var toColor;if(type=="results"){txt="<h3>"+txt+'</h3><span id="pageMessage"></span>';toColor="#333333"}else{if(type=="message"){txt="<span>"+txt+"</span>";toColor="#a90000"}else{toColor="#777777"}}if(anim){Dom.setStyle(resultsMsg,"color","#ffffff");resultsMsg.innerHTML=txt;var animMsg=new YAHOO.util.ColorAnim(resultsMsg.id,{color:{from:"#ffffff",to:toColor}},animateSpeed,easing);animMsg.animate()}else{Dom.setStyle(resultsMsg,"color",toColor);resultsMsg.innerHTML=txt}};var clearMessage=function(){resultsMsg.innerHTML=""};var trackSearch=function(){if(pageTracker&&config.trackSearches!=""){var url=config.trackSearches;var currValues=YAHOO.ps.Realestate.criteria.getValues();if(currValues.option=="sale"){url+="/sale/minprice/"+currValues.minsp+"/maxprice/"+currValues.maxsp;url+="/bed/"+currValues.bed+"/bath/"+currValues.bath}else{if(currValues.option=="rent"){url+="/rent/minprice/"+currValues.minrp+"/maxprice/"+currValues.maxrp;url+="/bed/"+currValues.bed+"/bath/"+currValues.bath}else{if(currValues.option=="land"){url+="/land/minprice/"+currValues.minlp+"/maxprice/"+currValues.maxlp;url+="/minlot/"+currValues.minls+"/maxlot/"+currValues.maxls}}}if(currValues.view==0){url+="/listview/location/"+currValues.search}else{url+="/mapview/lat/"+currValues.lat+"/long/"+currValues.lng+"/zoom/"+currValues.zoom}if(currValues.oh==1){url+="/openhouse/yes"}pageTracker._trackPageview(url)}};var getMapLocation=function(rsSearch){if(geo&&rsSearch!=""){geo.getLatLng(rsSearch,function(point){if(point){if(point.lat()<config.swBoundary[0]||point.lat()>config.neBoundary[0]||point.lng()<config.swBoundary[1]||point.lng()>config.neBoundary[1]){Dom.get("search").value="";updateMessage("This location is outside the search boundaries, enter another location.","message",true)}else{var orgZoom=map.getZoom();var newZoom=getZoom(rsSearch);map.setCenter(new GLatLng(point.lat().toFixed(7),point.lng().toFixed(7)),newZoom);if(orgZoom==newZoom){mapChange()}}}else{Dom.get("search").value="";updateMessage("This location can't be found, enter another location.","message",true)}})}};var tabChange=function(){var currValues=YAHOO.ps.Realestate.criteria.getValues();var currSearch=currValues.search;listNavResults.innerHTML="";clearMessage();if(Dom.hasClass("contentList","yui-hidden")){$("label#searchLabel").html("Use map or enter a new location");$("label#searchLabel").css({textIndent:0});YAHOO.ps.Realestate.criteria.updateValues({search:"",view:1});showMapResults();if(currSearch!=""){Dom.get("search").value="";getMapLocation(currSearch)}else{mapChange()}}else{$("label#searchLabel").html("Enter a location to search");var currLat=parseFloat(currValues.lat).toFixed(7);var currLng=parseFloat(currValues.lng).toFixed(7);var currZoom=parseInt(currValues.zoom);YAHOO.ps.Realestate.criteria.updateValues({view:0,page:1});showListResults();if(currZoom>=config.resultsZoom){geo.getLocations(new GLatLng(currLat,currLng),function(response){if(response&&response.Status.code==200){var area=response.Placemark[0].AddressDetails.Country.AdministrativeArea;var areaZip,areaState,areaCity,areaSearch="";if(!YAHOO.lang.isUndefined(area.Locality)){areaZip=area.Locality.PostalCode.PostalCodeNumber;areaCity=area.Locality.LocalityName}else{if(!YAHOO.lang.isUndefined(area.SubAdministrativeArea.Locality)){areaZip=area.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber;areaCity=area.SubAdministrativeArea.Locality.LocalityName}else{if(!YAHOO.lang.isUndefined(area.SubAdministrativeArea.PostalCode)){areaZip=area.SubAdministrativeArea.PostalCode.PostalCodeNumber}else{areaZip=area.PostalCode.PostalCodeNumber}}}if(!YAHOO.lang.isUndefined(area.AdministrativeAreaName)){areaState=area.AdministrativeAreaName}if((currZoom>=config.searchZipZoom||YAHOO.lang.isUndefined(areaCity))&&!YAHOO.lang.isUndefined(areaZip)){areaSearch=areaZip}else{if(!YAHOO.lang.isUndefined(areaCity)&&!YAHOO.lang.isUndefined(areaState)){areaCity=areaCity.replace(/mc lean/i,"McLean");areaSearch=areaCity+", "+areaState}}Dom.get("search").value=areaSearch;$("label#searchLabel").css({textIndent:-10000});YAHOO.ps.Realestate.criteria.updateValues({search:areaSearch});YAHOO.ps.Realestate.criteria.recordHistory()}})}else{listChange()}}};var listChange=function(page){var currValues=YAHOO.ps.Realestate.criteria.getValues();var order,orderBtm,limit,newPage=1;order=orderTop.options[orderTop.selectedIndex].value;orderBtm=orderBottom.options[orderBottom.selectedIndex].value;if(YAHOO.lang.isNumber(page)){newPage=page}if(currValues.order==order){order=orderBtm}limit=parseInt(limitTop.options[limitTop.selectedIndex].value,10);if(parseInt(currValues.limit,10)==limit){limit=parseInt(limitBottom.options[limitBottom.selectedIndex].value,10)}scroll(0,0);YAHOO.ps.Realestate.criteria.updateValues({order:order,limit:limit,page:newPage,view:0});YAHOO.ps.Realestate.criteria.recordHistory()};var mapChange=function(){map.closeExtInfoWindow();var zoom=map.getZoom();var bounds=map.getBounds();var center=map.getCenter();if(zoom<config.maxZoom){updateMessage("You can't zoom out any further. Zoom in or search for a location.","message",true);map.setZoom(config.maxZoom)}else{if(center.lat()<config.swBoundary[0]||center.lng()<config.swBoundary[1]||center.lat()>config.neBoundary[0]||center.lng()>config.neBoundary[1]){var defaultValues=YAHOO.ps.Realestate.criteria.getValues(true);updateMessage("This location is outside the search boundaries.","message",true);map.setCenter(new GLatLng(parseFloat(defaultValues.lat).toFixed(7),parseFloat(defaultValues.lng).toFixed(7)),parseInt(defaultValues.zoom))}else{Dom.get("search").value="";YAHOO.ps.Realestate.criteria.updateValues({lat:center.lat().toFixed(7),lng:center.lng().toFixed(7),zoom:zoom,search:"",view:1});YAHOO.ps.Realestate.criteria.recordHistory()}}};var showDetails=function(key){YAHOO.ps.Realestate.criteria.updateValues({key:key});YAHOO.ps.Realestate.criteria.recordHistory();if(pageTracker&&config.trackListings!=""){pageTracker._trackPageview(config.trackListings+"/"+key+"/details")}};var updateResultsFromValues=function(){var currValues=YAHOO.ps.Realestate.criteria.getValues();var currView=parseInt(currValues.view,10);var searchBox=Dom.get("search").value;var diff=YAHOO.ps.Realestate.criteria.comparePrevious("all",true);if(currView==0&&diff){if(Dom.hasClass("contentList","yui-hidden")){resultsTab.selectTab(currView);showListResults()}YAHOO.ps.Form.setDropDown("orderTop",currValues.order);YAHOO.ps.Form.setDropDown("orderBottom",currValues.order);YAHOO.ps.Form.setDropDown("limitTop",currValues.limit);YAHOO.ps.Form.setDropDown("limitBottom",currValues.limit);paginator.setPage(parseInt(currValues.page,10),true);if(currValues.search==""&&currValues.comp==0){Dom.addClass("listNavTop","hide");Dom.addClass("listNavBottom","hide");Dom.get("listMessage").innerHTML="Please enter the city, county, state or zip code you want to search.";Dom.removeClass("listNavNoResults","hide");listNavResults.innerHTML="";clearMessage()}else{clearMessage();if(YAHOO.util.Dom.inDocument("wait")){YAHOO.ps.container.wait.show()}trackSearch();var postValues=YAHOO.ps.Realestate.criteria.stringifyValues();YAHOO.util.Connect.asyncRequest("POST","/server/realestate/list",searchListCallback,postValues)}}else{if(currView==1&&diff&&searchBox==""){if(Dom.hasClass("contentMap","yui-hidden")){resultsTab.selectTab(currView);showMapResults()}map.setCenter(new GLatLng(parseFloat(currValues.lat).toFixed(7),parseFloat(currValues.lng).toFixed(7)),parseInt(currValues.zoom));map.clearOverlays();var zoom=map.getZoom();var bounds=map.getBounds();var sw=bounds.getSouthWest();var ne=bounds.getNorthEast();var zoomResults=config.resultsZoom;if(YAHOO.ps.Form.getCheckboxBool("comp","advCompanyBox")){zoomResults=zoomResults-1}if(currValues.zoom<zoomResults){var zoomOff=zoomResults-currValues.zoom;var levelTxt=(zoomOff==1)?zoomOff+" level":zoomOff+" levels";updateMessage("Search for a location on your left or zoom in "+levelTxt+" below to see listings.","message",true)}else{clearMessage();var postValues=YAHOO.ps.Realestate.criteria.stringifyValues();postValues+="&nelat="+ne.lat().toFixed(7)+"&nelng="+ne.lng().toFixed(7)+"&swlat="+sw.lat().toFixed(7)+"&swlng="+sw.lng().toFixed(7);if(YAHOO.util.Dom.inDocument("wait")){YAHOO.ps.container.wait.show()}trackSearch();YAHOO.util.Connect.asyncRequest("POST","/server/realestate/map",searchMapCallback,postValues)}}}};var handleSearchMapSuccess=function(o){if(YAHOO.util.Dom.inDocument("wait")){YAHOO.ps.container.wait.hide()}var response=YAHOO.ps.Ajax.eval(o);if(response!==false){if(response.success<=0){updateMessage(response.error,"message",true)}else{var recordsReturned=response.listings["records"].length;var totalRecords=parseInt(response.listings["totalRecords"],10);if(totalRecords>config.resultsMapLimit){updateMessage(addCommas(totalRecords)+" listings found. Zoom in or narrow criteria to get your results under "+config.resultsMapLimit+".","message",true)}else{if(totalRecords>0){var listingTxt=(totalRecords==1)?totalRecords+" Listing":totalRecords+" Listings";updateMessage(listingTxt+" Found","results",true)}else{updateMessage("No listings have been found, zoom out or adjust your criteria.","message",true)}}if(totalRecords<=config.resultsMapLimit){var grpRecords=organizeMarkers(response.listings["records"]);var countGroup=grpRecords.length;if(countGroup>0){for(var i=0;i<countGroup;i++){addMarker(grpRecords[i]["latitude"],grpRecords[i]["longitude"],grpRecords[i]["color"],grpRecords[i]["multi"],grpRecords[i]["type"],grpRecords[i]["listing_key"])}}}}}};var handleSearchMapFailure=function(o){if(YAHOO.util.Dom.inDocument("wait")){YAHOO.ps.container.wait.hide()}if(o.responseText!==undefined){updateMessage("Error: Unable to transmit update request.","message",true)}};var searchMapCallback={success:handleSearchMapSuccess,failure:handleSearchMapFailure,timeout:10000};var handleSearchListSuccess=function(o){if(YAHOO.util.Dom.inDocument("wait")){YAHOO.ps.container.wait.hide()}var response=YAHOO.ps.Ajax.eval(o);if(response!==false){if(response.success<=0){updateMessage(response.error,"message",true)}else{var recordsReturned=response.listings["records"].length;var startIndex=(response.listings["page"]-1)*response.listings["recordsPerPage"];var endIndex=startIndex+recordsReturned;var totalRecords=parseInt(response.listings["totalRecords"],10);if(totalRecords==0){Dom.addClass("listNavTop","hide");Dom.addClass("listNavBottom","hide");Dom.get("listMessage").innerHTML="No results were found.";Dom.removeClass("listNavNoResults","hide");listNavResults.innerHTML="";updateMessage("0 Listings Found","results",true)}else{var listingTxt=(totalRecords==1)?totalRecords+" Listing":totalRecords+" Listings";updateMessage(listingTxt+" Found","results",true);if(recordsReturned>=config.displaySecNav){Dom.removeClass("listNavBottom","hide")}else{Dom.addClass("listNavBottom","hide")}Dom.removeClass("listNavTop","hide");Dom.addClass("listNavNoResults","hide");addListNavigation(startIndex,endIndex,totalRecords,recordsReturned);var htmlKeys="";clearTooltip();for(var i=0;i<recordsReturned;i++){htmlKeys+=getListItemDisplay(response.listings["records"][i])}listNavResults.innerHTML=htmlKeys;buildTooltip()}}}};var handleSearchListFailure=function(o){if(YAHOO.util.Dom.inDocument("wait")){YAHOO.ps.container.wait.hide()}if(o.responseText!==undefined){updateMessage("Error: Unable to transmit update request.","message",true)}};var searchListCallback={success:handleSearchListSuccess,failure:handleSearchListFailure,timeout:18000};var addListNavigation=function(startIndex,endIndex,totalRecords,recordsReturned){var currValues=YAHOO.ps.Realestate.criteria.getValues();Dom.get("pageMessage").innerHTML=(totalRecords==0||(totalRecords>0&&recordsReturned==totalRecords))?"&nbsp;":"(Showing "+(startIndex+1)+" of "+endIndex+")";paginator.setState({rowsPerPage:currValues.limit,totalRecords:totalRecords,recordOffset:startIndex})};var addMarker=function(lat,lng,color,count,type,key){var icon=new GIcon();var infoContent;var name=type;if(count>4){name=4}else{if(count>1){name=count}}icon.image="/resources/images/maps/icon-"+color+"-"+name+".png";icon.iconSize=new GSize(21,24);icon.iconAnchor=new GPoint(11,24);icon.infoWindowAnchor=new GPoint(122,24);if(!(YAHOO.env.ua.ie>=6&&YAHOO.env.ua.ie<=7)){icon.shadow="/resources/images/maps/icon-shadow.png";icon.shadowSize=new GSize(36,24)}if(count>1){infoContent='<div id="markerNav"></div><div id="marker" class="loading"></div>'}else{infoContent='<div id="marker" class="loading"></div>'}var point=new GLatLng(parseFloat(lat),parseFloat(lng));var marker=new GMarker(point,icon);var currValues=YAHOO.ps.Realestate.criteria.getValues();var opt=currValues.option;var listPath="/server/realestate/residential";if(opt=="land"){listPath="/server/realestate/lot"}var type="partial";GEvent.addListener(marker,"click",function(){clearTooltip();map.savePosition();marker.openExtInfoWindow(map,color+"_info",infoContent,{beakOffset:18,paddingX:5,paddingY:15});YAHOO.util.Connect.asyncRequest("POST",listPath,listingMapCallback,"type="+type+"&key="+key)});map.addOverlay(marker)};var organizeMarkers=function(listings){var zoom=map.getZoom();var width=map.getSize().width;var height=map.getSize().height;var bounds=map.getBounds();var sw=bounds.getSouthWest();var ne=bounds.getNorthEast();var dis=distance(sw.lat(),sw.lng(),sw.lat(),ne.lng())/width;var diff=dis*config.closePixel;var diff=(zoom>15)?diff*0.8:diff;var orgListings=new Array();var cntListings=listings.length;var x=0;for(var i=0;i<cntListings;i++){var y=0;if(!YAHOO.lang.isNull(listings[i]["longitude"])&&!YAHOO.lang.isNull(listings[i]["latitude"])){orgListings[x]=new Array();var hashListing={};hashListing.longitude=parseFloat(listings[i]["longitude"]);hashListing.latitude=parseFloat(listings[i]["latitude"]);hashListing.listing_key=listings[i]["listing_key"];hashListing.type=getType(listings[i]["type"]);hashListing.color=getColor(listings[i]["list_status"],parseInt(listings[i]["dom"],10),listings[i]["open_date"]);orgListings[x][y]=hashListing;listings[i]["longitude"]=null;listings[i]["latitude"]=null;y++;for(var j=0;j<cntListings;j++){if(!YAHOO.lang.isNull(listings[j]["longitude"])&&!YAHOO.lang.isNull(listings[j]["latitude"])){if(distance(hashListing.latitude,hashListing.longitude,listings[j]["latitude"],listings[j]["longitude"])<diff){var subHashListing={};subHashListing.longitude=parseFloat(listings[j]["longitude"]);subHashListing.latitude=parseFloat(listings[j]["latitude"]);subHashListing.listing_key=listings[j]["listing_key"];subHashListing.type=getType(listings[j]["type"]);subHashListing.color=getColor(listings[j]["list_status"],parseInt(listings[j]["dom"],10),listings[j]["open_date"]);orgListings[x][y]=subHashListing;listings[j]["longitude"]=null;listings[j]["latitude"]=null;y++}}}x++}}var reorderListings=new Array();var x=0;for(var i=0;i<orgListings.length;i++){if(orgListings[i].length==1){reorderListings[x]=orgListings[i]}else{if(orgListings[i].length>1){reorderListings[x]=new Array();var y=0;for(var j=0;j<orgListings[i].length;j++){if(orgListings[i][j]["color"]=="orange"){reorderListings[x][y]=orgListings[i][j];y++}}for(var j=0;j<orgListings[i].length;j++){if(orgListings[i][j]["color"]=="blue"){reorderListings[x][y]=orgListings[i][j];y++}}for(var j=0;j<orgListings[i].length;j++){if(orgListings[i][j]["color"]!="orange"&&orgListings[i][j]["color"]!="blue"){reorderListings[x][y]=orgListings[i][j];y++}}}}x++}var orgListings=new Array();orgListings=reorderListings;var grpListings=new Array();for(var i=0;i<orgListings.length;i++){var listing=new Array();if(orgListings[i].length==1){listing=orgListings[i][0];grpListings[i]=listing;grpListings[i]["multi"]=1}else{if(orgListings[i].length>1){var grpKeys=new Array();var strKeys="";for(var j=0;j<orgListings[i].length;j++){grpKeys[j]=orgListings[i][j]["listing_key"]}for(var j=0;j<grpKeys.length;j++){strKeys+=grpKeys[j]+","}strKeys=strKeys.substring(0,(strKeys.length-1));listing=orgListings[i][0];listing.listing_key=strKeys;listing.multi=orgListings[i].length;grpListings[i]=listing}}}return grpListings};var getType=function(type){var newType="land";if(type=="Townhouse"||type=="Attach/Row Hse"||type=="Back-to-Back"||type=="Duplex"){newType="attached"}else{if(type=="Mid-Rise 5-8 Floors"||type=="Hi-Rise 9+ Floors"||type=="Garden 1-4 Floors"){newType="condo"}else{if(type!=""){newType="detached"}}}return newType};var getColor=function(status,dom,open){var color="";if(!YAHOO.lang.isNull(open)){color="orange"}else{if(dom<config.newDom){color="blue"}else{if(status=="ACTIVE"){color="green"}else{if(status=="SOLD"||status=="CONTRACT"||status=="CNTG/KO"||status=="CNTG/NO KO"){color="red"}}}}return color};var distance=function(lat1,long1,lat2,long2){var r=6371;var dLat=lat2-lat1;var dLong=long2-long1;var a=Math.sin(dLat/2)*Math.sin(dLat/2)+Math.cos(lat1)*Math.cos(lat2)*Math.sin(dLong/2)*Math.sin(dLong/2);var dist=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));var km=r*dist;return km};var colors,keys,currKey;var getListingDisplay=function(listing,hideList){var imgHover="";if(listing.imageCount>1){imgHover=' title="'+(listing.imageCount-1)+' additional images"';addTooltipId("keyImg"+listing.listing_key)}var htmlListing="";var titlePad=(YAHOO.lang.isUndefined(listing.openHouses)&&YAHOO.lang.isUndefined(listing.agent_name))?" pad":"";var address=listing.street_address;if(address.length<26&&listing.city.length<10){address+=", "+listing.city}else{if(address.length<22&&listing.city.length<14){address+=", "+listing.city}else{if(address.length<18&&listing.city.length<18){address+=", "+listing.city}}}htmlListing+='<div class="title'+titlePad+'">'+address+"</div>";if(listing.url_picture!=""){htmlListing+='<div id="keyImg'+listing.listing_key+'"  class="image"'+imgHover+'><img src="'+listing.url_mapview+'" /></div>'}else{htmlListing+='<div id="keyImg'+listing.listing_key+'"  class="image"><img src="/resources/images/nolisting-map.jpg" /></div>'}htmlListing+='<div class="detail price"><span class="value">$'+addCommas(listing.list_price)+"</span></div>";htmlListing+='<div class="detail"><span class="item">Listed:</span><span class="value">'+listing.dis_list_date+"</span></div>";htmlListing+='<div class="detail"><span class="item">Status:</span><span class="';htmlListing+=(listing.list_status=="ACTIVE")?"value green":"value red";htmlListing+='">'+listing.list_status+"</span></div>";if(listing.beds>0||listing.baths>0){htmlListing+='<div class="detail"><span class="bedbath">';if(listing.beds>0){htmlListing+=listing.beds+" Bed"}if(listing.baths>0){if(listing.beds>0){htmlListing+=" | "}var bathTotal=(parseInt(listing.baths_full)+(listing.baths_half/2));bathTotal+=" Bath";htmlListing+=bathTotal.replace(".5"," 1/2")}htmlListing+="</span></div>"}if(listing.type_listing=="lot"){htmlListing+='<div class="detail"><span class="item">Lot Size</span><span class="value">'+(listing.area_lot_size/43560).toFixed(2)+" Acre(s)</span></div>"}if(!YAHOO.lang.isUndefined(listing.openHouses)){htmlListing+='<div class="oh"><span class="title">OPEN:</span> '+listing.openHouses[0]["open_date"];htmlListing+=", "+listing.openHouses[0]["open_start_time"]+" - ";htmlListing+=listing.openHouses[0]["open_end_time"]+"</div>"}else{if(!YAHOO.lang.isUndefined(listing.agent_name)){htmlListing+='<div class="agentName">Listed by '+listing.agent_name+"</div>"}}var classList="listing";if(hideList==true){classList="listing hide"}htmlListing='<div id="keyMap'+listing.listing_key+'" class="'+classList+'" onclick="YAHOO.ps.Realestate.results.showDetails('+listing.listing_key+');">'+htmlListing+"</div>";if(pageTracker&&config.trackListings!=""){pageTracker._trackPageview(config.trackListings+"/"+listing.listing_key+"/mapview")}return htmlListing};var getNavDisplay=function(listings){var htmlNav="";htmlNav+='<div class="prev"><a id="prevList" href="javascript:void(0);" alt="Show Previous Listing">Prev</a></div>';htmlNav+='<div class="total"><span id="currList"></span>&nbsp;of '+listings.length+" Listings</div>";htmlNav+='<div class="next"><a id="nextList" href="javascript:void(0);" alt="Show Next Listing">Next</a></div>';return htmlNav};var addCommas=function(nStr){nStr+="";x=nStr.split(".");x1=x[0];x2=x.length>1?"."+x[1]:"";var rgx=/(\d+)(\d{3})/;while(rgx.test(x1)){x1=x1.replace(rgx,"$1,$2")}return x1+x2};var setKeys=function(listings){keys=new Array(listings.length);colors=new Array(listings.length);currKey=0;for(var i=0;i<listings.length;i++){keys[i]="keyMap"+listings[i]["listing_key"];var open=null;if(!YAHOO.lang.isUndefined(listings[i]["openHouses"])){open=true}var dom=YAHOO.ps.Date.getDateDiff(listings[i]["list_date"]);colors[i]=getColor(listings[i]["list_status"],dom,open)}};var prevList=function(){YAHOO.util.Dom.removeClass("containerItem",colors[currKey]+"_info");currKey=currKey-1;currKey=(currKey<0)?keys.length-1:currKey;changeList(currKey)};var nextList=function(){YAHOO.util.Dom.removeClass("containerItem",colors[currKey]+"_info");currKey=currKey+1;currKey=(currKey>=keys.length)?0:currKey;changeList(currKey)};var changeList=function(key){var elements=YAHOO.util.Dom.getElementsByClassName("listing","div");YAHOO.util.Dom.addClass("containerItem",colors[key]+"_info");YAHOO.util.Dom.addClass(elements,"hide");YAHOO.util.Dom.removeClass(keys[key],"hide");YAHOO.util.Dom.get("currList").innerHTML=key+1};var getListItemDisplay=function(listing){var imgHover="";if(listing.imageCount>1){imgHover=' title="'+(listing.imageCount-1)+' additional images"';addTooltipId("keyImg"+listing.listing_key)}var htmlListing="";if(listing.url_picture!=""){htmlListing+='<div id="keyImg'+listing.listing_key+'" class="image"'+imgHover+'><img src="'+listing.url_listview+'" /></div>'}else{htmlListing+='<div id="keyImg'+listing.listing_key+'" class="image"><img src="/resources/images/nolisting-list.jpg" /></div>'}htmlListing+='<div class="detailGrp">';if(config.offices.indexOf(listing.pri_office_code)>=0){htmlListing+='<div class="logo"><img src="/resources/images/logo-sm.gif" /></div>'}htmlListing+='<div class="status"><span class="';htmlListing+=(listing.list_status=="ACTIVE")?"value green":"value red";htmlListing+='">'+listing.list_status+"</span></div>";htmlListing+='<div class="title">'+listing.street_address+"<br />"+listing.city;htmlListing+=", "+listing.state+" "+listing.zip+"</div>";htmlListing+='<div class="price">$'+addCommas(listing.list_price)+"</div>";htmlListing+='<div class="info">Listed: '+listing.dis_list_date+"</div>";if(listing.beds>0||listing.baths>0){htmlListing+='<div class="info">';if(listing.beds>0){htmlListing+=listing.beds+" Bed"}if(listing.baths>0){if(listing.beds>0){htmlListing+=" | "}var bathTotal=(parseInt(listing.baths_full)+(listing.baths_half/2));bathTotal+=" Bath";htmlListing+=bathTotal.replace(".5"," 1/2")}htmlListing+="</div>"}if(listing.type_listing=="lot"){htmlListing+='<div class="info">Lot Size: '+(listing.area_lot_size/43560).toFixed(2)+" Acre(s)</div>"}var agentClass="";if(!YAHOO.lang.isUndefined(listing.agent_name)){htmlListing+='<div class="agentName">Listing by '+listing.agent_name;if(listing.agent_name.length<20){htmlListing+=" of McEnearney Associates, Inc."}htmlListing+="</div>";agentClass=" agent"}htmlListing+="</div>";if(!YAHOO.lang.isUndefined(listing.openHouses)){htmlListing+='<div class="oh"><div class="title">OPEN HOUSE:</div>'+listing.openHouses[0]["open_date_long"];htmlListing+="<br />"+listing.openHouses[0]["open_start_time"]+" - ";htmlListing+=listing.openHouses[0]["open_end_time"];if(!YAHOO.lang.isUndefined(listing.openHouses[1])){htmlListing+='<div class="oh2">'+listing.openHouses[1]["open_date_long"];htmlListing+="<br />"+listing.openHouses[1]["open_start_time"]+" - ";htmlListing+=listing.openHouses[1]["open_end_time"]+"</div>"}htmlListing+="</div>"}htmlListing='<div id="keyList'+listing.listing_key+'" class="listing'+agentClass+'" onclick="YAHOO.ps.Realestate.results.showDetails('+listing.listing_key+');">'+htmlListing+"</div>";if(pageTracker&&config.trackListings!=""){pageTracker._trackPageview(config.trackListings+"/"+listing.listing_key+"/listview")}return htmlListing};var handleListingMapSuccess=function(o){if(YAHOO.util.Dom.inDocument("wait")){YAHOO.ps.container.wait.hide()}var response=YAHOO.ps.Ajax.eval(o);if(response!==false){if(response.success<=0){map.closeExtInfoWindow();updateMessage(response.error,"message",true)}else{var count=response.listings.length;var htmlListing="";if(count==1){htmlListing=getListingDisplay(response.listings[0],false)}else{if(count>1){YAHOO.util.Dom.get("markerNav").innerHTML=getNavDisplay(response.listings);setKeys(response.listings);YAHOO.util.Event.addListener("prevList","click",prevList);YAHOO.util.Event.addListener("nextList","click",nextList);for(var i=0;i<count;i++){htmlListing+=getListingDisplay(response.listings[i],true)}}}YAHOO.util.Dom.removeClass("marker","loading");YAHOO.util.Dom.get("marker").innerHTML=htmlListing;buildTooltip();if(count>1){changeList(currKey)}}}};var handleListingMapFailure=function(o){if(YAHOO.util.Dom.inDocument("wait")){YAHOO.ps.container.wait.hide()}map.closeExtInfoWindow();if(o.responseText!==undefined){updateMessage("Error: Unable to load listing(s)","message",true)}};var listingMapCallback={success:handleListingMapSuccess,failure:handleListingMapFailure,timeout:12000};var closeInfoWindow=function(){if(!Dom.hasClass("contentMap","yui-hidden")){map.closeExtInfoWindow()}};var checkMapSize=function(){if(!Dom.hasClass("contentMap","yui-hidden")){map.checkResize()}};var ttIds=[],ttItem=null;var addTooltipId=function(id){ttIds.push(id)};var clearTooltip=function(){if(YAHOO.lang.isObject(ttItem)){ttItem.destroy()}ttItem=null;ttIds=[]};var buildTooltip=function(){ttItem=new YAHOO.widget.Tooltip("ttItem",{context:ttIds,effect:false})};var initMapResults=function(){YAHOO.ps.Viewport.expandMap("mapImage",10,304);map=new GMap2(document.getElementById("mapImage"));geo=new GClientGeocoder();map.addControl(new ImageZoomControl());map.addControl(new ImageLegendControl());map.addControl(new ImageMapTypeControl());map.enableContinuousZoom();map.enableDoubleClickZoom();updateResultsFromValues();Ev.addListener(window,"unload",GUnload);GEvent.addListener(map,"zoomend",mapChange);GEvent.addListener(map,"dragend",mapChange);GEvent.addListener(map,"maptypechanged",mapChange);if(YAHOO.env.ua.ie!=6){GEvent.addListener(map,"click",function(){$("#legendButton, #helpButton").qtip("hide")});GEvent.addListener(map,"dragstart",function(){$("#legendButton, #helpButton").qtip("hide")})}GEvent.addListener(map,"extinfowindowclose",function(){map.returnToSavedPosition()});onInitMapResults.unsubscribe(initMapResults)};var initListResults=function(){updateResultsFromValues();onInitListResults.unsubscribe(initListResults)};var showMapResults=function(){onInitMapResults.fire();checkMapSize()};var showListResults=function(){onInitListResults.fire();Dom.addClass("listNavTop","hide");Dom.addClass("listNavBottom","hide")};var initTabs=function(){var currValues=YAHOO.ps.Realestate.criteria.getValues();resultsTab=new YAHOO.widget.TabView("boxResults");resultsTab.addListener("activeTabChange",tabChange);resultsTab.selectTab(parseInt(currValues.view,10))};var initPaginator=function(){paginator=new YAHOO.widget.Paginator({alwaysVisible:false,containers:["pageNavTop","pageNavBottom"],firstPageLinkLabel:"First",previousPageLinkLabel:"Prev",nextPageLinkLabel:"Next",lastPageLinkLabel:"Last"});paginator.subscribe("changeRequest",function(state){paginator.setState(state);listChange(state.page)});paginator.render()};Ev.onDOMReady(function(){resultsMsg=Dom.get("resultsMessage");orderTop=Dom.get("orderTop");orderBottom=Dom.get("orderBottom");limitTop=Dom.get("limitTop");limitBottom=Dom.get("limitBottom");listNavResults=Dom.get("listNavResults");Ev.addListener(["orderTop","orderBottom","limitTop","limitBottom"],"change",listChange);onInitMapResults.subscribe(initMapResults);onInitListResults.subscribe(initListResults)});Rs.initTabs=initTabs;Rs.checkMapSize=checkMapSize;Rs.initPaginator=initPaginator;Rs.setConfig=setConfig;Rs.updateMessage=updateMessage;Rs.clearMessage=clearMessage;Rs.getMapLocation=getMapLocation;Rs.updateFromValues=updateResultsFromValues;Rs.showDetails=showDetails;Rs.closeInfoWindow=closeInfoWindow})();