
var map;var minimap;var IMG_BASE_URL="/images/gmap/";var LISTING_MARKERS=new Object();var baseIcon=new GIcon();baseIcon.shadow=IMG_BASE_URL+"marker_shdw.png";baseIcon.iconSize=new GSize(20,34);baseIcon.shadowSize=new GSize(37,34);baseIcon.iconAnchor=new GPoint(9,34);baseIcon.infoWindowAnchor=new GPoint(9,2);baseIcon.infoShadowAnchor=new GPoint(18,25);function parse_get_string()
{var params=[];var regex=/[\?&]([^=]+)=([a-z0-9_]*)/ig;while((results=regex.exec(window.location.href))!=null)
params.push([results[1],results[2]]);return params;}
function sortSearchResults(sortby)
{var found_sort=false;var get_string_values;var outstring="?";get_string_values=parse_get_string();for(var i=0;i<get_string_values.length;i++)
{if(get_string_values[i][0]=='SORT_order')
{outstring+="SORT_order="+sortby+"&";found_sort=true;}
else{outstring+=get_string_values[i][0]+"="+get_string_values[i][1]+"&";}}
if(!found_sort){outstring+="SORT_order="+sortby;}
window.location=outstring;}
function attachSearchResultsEvents(){$$('.submit_on_change').each(function(selectobj){selectobj.observe('change',function(){var sortby=$(selectobj).getValue();sortSearchResults(sortby);});});if($("featured_order_by")){$("featured_order_by").observe('change',function(){$("featured_order_form").submit();});}
$$('.btn_contact, .btn_visit').each(function(s){$(s).observe('click',function(event){popWindow(s);Event.stop(event);});});}
function createListingMarker(letter,mls_id,mls_no,point,page,lpp,index_on_page,total_listings,featured_order_by,listing_id,content_index){if(!page){page=null;}
if(!lpp){lpp=null;}
if(!index_on_page){index_on_page=null;}
if(!total_listings){total_listings=null;}
var letteredIcon=new GIcon(baseIcon);letteredIcon.image=IMG_BASE_URL+"marker"+letter+".png";markerOptions={icon:letteredIcon};var listingmarker=new GMarker(point,markerOptions);if($("FeaturedMap")){listingmarker.id=listing_id;}else{listingmarker.id=mls_id+"_"+mls_no;}
listingmarker.active=false;GEvent.addListener(listingmarker,"mouseover",function(){if(listingmarker.active!=true){listingmarker.setImage(IMG_BASE_URL+"marker"+letter+"_teal.png");}});GEvent.addListener(listingmarker,"mouseout",function(){if(listingmarker.active!=true){listingmarker.setImage(IMG_BASE_URL+"marker"+letter+".png");}});GEvent.addListener(listingmarker,"click",function(){if(listingmarker.active!=true){CURRENT_LISTING_ID=listingmarker.id;listingmarker.active=true;listingmarker.setImage(IMG_BASE_URL+"marker"+letter+"_green.png");var infowindow_html;var infowindow_url="?";if($("FeaturedMap")){new Ajax.Request(infowindow_url,{method:'post',parameters:{controller:'FeaturedListings',product:'web',action:'details',acnt:ACNT,listing_id:listing_id,featured_order_by:featured_order_by,content_index:content_index,infowindow:1},onSuccess:function(transport){infowindow_html=transport.responseText;listingmarker.openInfoWindowHtml(infowindow_html);},onFailure:function(){alert("The ajax request failed - was trying to retrieve this listing's information to show in the info window.");}});}
else{new Ajax.Request(infowindow_url,{method:'post',parameters:{controller:'ListingSearch',product:'web',action:'details',acnt:ACNT,mls_id:mls_id,mls_no:mls_no,page:page,lpp:lpp,index:index_on_page,total_listings:total_listings,infowindow:1},onSuccess:function(transport){infowindow_html=transport.responseText;listingmarker.openInfoWindowHtml(infowindow_html);},onFailure:function(){alert("The ajax request failed - was trying to retrieve this listing's information to show in the info window.");}});}}});GEvent.addListener(listingmarker,"infowindowclose",function(){if(listingmarker.active==true){listingmarker.active=false;listingmarker.setImage(IMG_BASE_URL+"marker"+letter+".png");}else{listingmarker.active=false;}});return listingmarker;}
function setupListingMarkers(){var bounds=new GLatLngBounds();var index;var locate_buttons=$$('a.btn_locate');locate_buttons.each(function(s){if(s.rel!=''){var params=s.rel.split(",");var letter=params[0];var mls_id=params[1];var mls_no=params[2];var lat=params[3];var lng=params[4];var page=params[5];var lpp=params[6];var index_on_page=params[7];var total_listings=params[8];var featured_order_by=params[9];var listing_id=params[10];var content_index=params[11];var listing_point=new GLatLng(parseFloat(lat),parseFloat(lng));if(!bounds.containsLatLng(listing_point)){bounds.extend(listing_point);}
var marker=createListingMarker(letter,mls_id,mls_no,listing_point,page,lpp,index_on_page,total_listings,featured_order_by,listing_id,content_index);var listing_index="";if($("FeaturedMap")){listing_index=listing_id;}else{listing_index=mls_id+"_"+mls_no;}
LISTING_MARKERS[listing_index]=marker;map.addOverlay(marker);$(s).observe('click',function(event){GEvent.trigger(LISTING_MARKERS[listing_index],"click");});$(s).up(1).next('a.btn_locate_marker').observe('click',function(event){GEvent.trigger(LISTING_MARKERS[listing_index],"click");});}});if(locate_buttons){var bounds_center=bounds.getCenter();var bounds_zoom=map.getBoundsZoomLevel(bounds);map.setCenter(bounds_center,bounds_zoom);}}
function load(){if(GBrowserIsCompatible()){var starting_centerpoint=$F("starting_centerpoint");var starting_zoom=8;var starting_type=G_NORMAL_MAP;var ctrpt=starting_centerpoint.split(",");map=new GMap2($("Map"));map.setCenter(new GLatLng(parseFloat(ctrpt[0]),parseFloat(ctrpt[1])),starting_zoom,starting_type);map.addControl(new GLargeMapControl());map.addControl(new GMapTypeControl());setupListingMarkers.delay(3);}}
Event.observe(window,'load',function(){attachSearchResultsEvents();if($("Map")){load();}
$$('a.btn_locate_marker').invoke('pngFix');});Event.observe(window,'unload',function(){GUnload();});