$('document').ready(function(){var def_catId='',def_zoomLevel=7,def_jsonFile='locator/locations_json',def_maxDistance=100,def_LatLng=new GLatLng(37.5,-86);if(GBrowserIsCompatible()){var map=new GMap2(document.getElementById("map"));map.setCenter(def_LatLng,def_zoomLevel);geocoder=new GClientGeocoder();map.addControl(new GSmallMapControl());map.addControl(new GMapTypeControl());var baseIcon=new GIcon();baseIcon.image="/images/site/map-building.png";baseIcon.shadow="/images/site/map-shadow.png";baseIcon.iconSize=new GSize(18,30);baseIcon.shadowSize=new GSize(25,30);baseIcon.iconAnchor=new GPoint(9,30);baseIcon.infoWindowAnchor=new GPoint(9,9);baseIcon.infoShadowAnchor=new GPoint(0,2);var associateIcon=new GIcon();associateIcon.image="/images/site/map-dude.png";associateIcon.shadow="/images/site/map-shadow.png";associateIcon.iconSize=new GSize(18,30);associateIcon.shadowSize=new GSize(25,30);associateIcon.iconAnchor=new GPoint(9,30);associateIcon.infoWindowAnchor=new GPoint(9,9);associateIcon.infoShadowAnchor=new GPoint(0,2);function formatBubble(input){var html="<div class=\"bubble\">";html+="<h3 class=\"bubble\"><a href=\"/locator/detail/"+input.url+"\">"+input.name+"</a></h3>";html+="<p>"+input.address1+"<br/>"+input.city+", "+input.state+" "+input.zip+"<br />"+input.phone+"</p>";html+="</div>";return html};function add_marker(latlng,loc,icon_num){var marker=new GMarker(latlng,{icon:baseIcon});if(loc.category==75){marker=new GMarker(latlng,{icon:baseIcon})}else if(loc.category==74)marker=new GMarker(latlng,{icon:associateIcon});map.addOverlay(marker);GEvent.addListener(marker,'click',function(){if(loc.address2!='')address2=loc.address2+"<br/>";marker.openInfoWindowHtml(formatBubble(loc))});return marker};function get_points(filter){var bounds=new GLatLngBounds();if(filter=='')filter='/locator/locations_json';map.clearOverlays();$('#searchResults').html('');$.getJSON(filter,function(data){$.each(data.locations,function(i,loc){if(loc.geo_lat!=''&&loc.geo_lng!=''){var point=new GLatLng(parseFloat(loc.geo_lat),parseFloat(loc.geo_lng));add_marker(point,loc);bounds.extend(point)}else{var searchAddress=loc.address1+", "+loc.city+", "+loc.state+" "+loc.zip;geocoder.getLatLng(searchAddress,function(point){if(!point);else{add_marker(point,loc,null);bounds.extend(point);$.getJSON('/locator/locations_update/'+loc.id+'/'+point.lat()+'/'+point.lng(),function(json){})}})}})});map.setCenter(def_LatLng,def_zoomLevel)};$('#searchLocations').submit(function(){var address=$('#addressInput').val();geocoder.getLatLng(address,function(latlng){if(!latlng);else searchLocationsNear(latlng)});return false});function searchLocationsNear(center){var searchUrl='/locator/locations_search/'+center.lat()+'/'+center.lng()+'/'+def_catId;$.getJSON(searchUrl,function(json){map.clearOverlays();$('#searchResults').remove();$('#gMap').after('<ol id="searchResults"></ol>');if(json.locations.length==0){$('#locationList').html('Error getting results.');return};var bounds=new GLatLngBounds();$.each(json.locations,function(i,loc){var point=new GLatLng(parseFloat(loc.geo_lat),parseFloat(loc.geo_lng)),marker=add_marker(point,loc,(i+1));createSidebarEntry(marker,loc,(i+1));bounds.extend(point)});map.setCenter(bounds.getCenter(),map.getBoundsZoomLevel(bounds))})};function createSidebarEntry(marker,loc,mapNum){if(loc.category==75){icon='/images/site/map-building.png'}else if(loc.category==74)icon='/images/site/map-dude.png';var address2='';if(loc.address2!='')address2=loc.address2+"<br />";var distance=parseFloat(loc.distance);$('#searchResults').append('<li id="location_'+loc.id+'" class="locationItem"><img src="'+icon+'" alt="icon" /><p><a href="/locator/detail/'+loc.url+'" name="map_'+loc.id+'"><strong>'+loc.name+'</strong></a><br />'+loc.address1+'<br />'+loc.city+', '+loc.state+' '+loc.zip+'<br />'+loc.phone+'</p></li>');GEvent.addDomListener(document.getElementById('location_'+loc.id),'click',function(){GEvent.trigger(marker,'click')});GEvent.addDomListener(marker,'click',function(){$('.locationItem').css('background-color','transparent');$('#location_'+loc.id).css('background-color','#eeeeee')})};$("#nav-sidebar a[@rel='history']").click(function(){var hash=this.href;hash=hash.replace(/^.*#/,'');$.historyLoad(hash);return false});function pageload(hash){$('#subnav li').attr('id','');if(hash&&hash!='main'&&hash!=''){def_catId=(hash=='store')?'75':'74';$('#map-'+hash+'-link').parent('li').attr('id','current');get_points('/locator/locations_json_'+hash)}else if(location.hash.slice(1)){if(location.hash.slice(1)!='main'){def_catId=(location.hash.slice(1)=='store')?'75':'74';$('#map-'+location.hash.slice(1)+'-link').parent('li').attr('id','current');get_points('/locator/locations_json_'+location.hash.slice(1))}else{def_catId='';get_points('/locator/locations_json')}}else{def_catId='';get_points('/locator/locations_json')}};$.historyInit(pageload);$("a[@rel='history']").click(function(){return false})}})