var GoogleMap={map:null,data:[],pointId2marker:[],domNode:null,openInfoWindowOnMouseOver:false,markerIcon:null,onDragEndFunction:null,createMap:function(b,c,a){if(c){this.datasrc=c;var d=$("#"+this.datasrc).get(0);if(d){this.parse(d)}}this.domNode=$("#"+b).get(0);this.map=new GMap2(this.domNode);this.map.addControl(new GSmallMapControl());this.map.addControl(new GScaleControl());this.map.addControl(new GMapTypeControl());this.map.enableScrollWheelZoom();this.map.enableContinuousZoom();if(a){this.render()}else{this.map.setCenter(new GLatLng(39.10662,-94.578209),4)}$(window).unload(function(){GUnload()})},parse:function(b){this.data=[];for(var a=0;a<b.childNodes.length;a++){if(!b.childNodes[a].nodeName||b.childNodes[a].nodeType==3){continue}var c=b.childNodes[a];var e=(c.getAttribute("description")!=null?c.getAttribute("description"):c.innerHTML);var d={pointId:c.getAttribute("id"),lat:parseFloat(c.getAttribute("lat")),lng:parseFloat(c.getAttribute("lng")),description:e};this.data.push(d)}},render:function(){this.map.checkResize();if(this.data.length==0){this.map.setCenter(new GLatLng(39.10662,-94.578209),4);return}this.map.clearOverlays();var b=new GLatLngBounds();var c=this.data;for(var a=0;a<c.length;a++){b.extend(new GLatLng(c[a].lat,c[a].lng))}this.map.setCenter(this.findCenter(b),Math.min((this.map.getBoundsZoomLevel(b)-1),14));for(var a=0;a<this.data.length;a++){this.plot(this.data[a])}},findCenter:function(b){if(this.data.length==1){return(new GLatLng(this.data[0].lat,this.data[0].lng))}var c=(b.getNorthEast().lat()+b.getSouthWest().lat())/2;var a=(b.getNorthEast().lng()+b.getSouthWest().lng())/2;return(new GLatLng(c,a))},createPinpoint:function(f,c,d){var e={bouncy:true};if(d){e.icon=d}else{if(this.markerIcon){e.icon=this.markerIcon}}if(this.onDragEndFunction){e.draggable=true}var a=new GMarker(f,e);var b=this;if(e.draggable){GEvent.addListener(a,"dragstart",function(){b.map.closeInfoWindow()});GEvent.addListener(a,"dragend",function(){b.onDragEndFunction(a)})}if(c){GEvent.addListener(a,"click",function(){a.openInfoWindowHtml("<div>"+c+"</div>")});if(this.openInfoWindowOnMouseOver){GEvent.addListener(a,"mouseover",function(){a.openInfoWindowHtml("<div>"+c+"</div>")});GEvent.addListener(a,"mouseout",function(){b.map.closeInfoWindow()})}}return a},plot:function(e){var c=new GLatLng(e.lat,e.lng);var f=e.description||null;var b=e.icon;var a=this.createPinpoint(c,f,b);if(e.pointId!=null){this.pointId2marker[e.pointId]=a}this.map.addOverlay(a)},findAddressGeoLocation:function(a,d,c){var b=new GClientGeocoder();if(c){b.setBaseCountryCode(c)}b.getLocations(a,function(e){if(!e||e.Status.code!=200){d(null)}else{d(e.Placemark)}})},plotAddress:function(a,d,c){var b=this;b.findAddressGeoLocation(function(e){if(e==null){alert('The address "'+a+'" was not found.');return}for(var f=0;f<e.length;f++){var g={lat:e[f].Point.coordinates[1],lng:e[f].Point.coordinates[0],description:e[f].address};b.data.push(g)}b.render()})},clearOverlays:function(){this.data=[];this.map.clearOverlays()},jumpToPoint:function(a){var b=this.pointId2marker[a];if(!b){alert("Marker #"+a+" has not been found");return}var c=Math.max(this.map.getZoom(),14);if(c==this.map.getZoom()){this.map.panTo(b.getLatLng())}else{this.map.setCenter(b.getLatLng(),c)}GEvent.trigger(b,"click")}};var baseIcon=new GIcon();baseIcon.shadow="http://www.google.com/mapfiles/shadow50.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);baseIcon.image="/media/nhfa_marker.png";var premiumIcon=new GIcon();premiumIcon.shadow="http://www.google.com/mapfiles/shadow50.png";premiumIcon.iconSize=new GSize(23,23);premiumIcon.shadowSize=new GSize(37,34);premiumIcon.iconAnchor=new GPoint(9,34);premiumIcon.infoWindowAnchor=new GPoint(9,2);premiumIcon.infoShadowAnchor=new GPoint(18,25);premiumIcon.image="/media/nhfa_premium_marker.png";function populateFormFromHash(d){var e=d.replace(/&$/,"").split("&");for(var b=0;b<e.length;b++){var a=e[b].split("=",1)[0];var c=e[b].substring(a.length+1);c=unescape(c).replace(/\+/g," ");$("#locatorSearchForm").find("*[name="+a+"]").each(function(){var f=$(this);if(f.attr("type")=="checkbox"||f.attr("type")=="radio"){if(f.val()==c){this.checked=true;if(f.attr("name")=="keywords"&&!$("#advanced_search").is(":visible")){$("#advanced_search").slideToggle("fast")}}return}if(f.attr("name")=="submit"){return}f.val(c)})}}var lastSubmitTime=new Date();function handleSubmit(){$("#locatorSearchForm").submit(function(){var a=new Date();if(lastSubmitTime.getTime()+3000>a.getTime()){return false}lastSubmitTime=a;var b=getSearchFormData(this);$.historyLoad(b);return false})}function sortRetailers(a){$(".retailerSortBy").val(a);$(window).scrollTop(0);$("#locatorSearchForm").submit();return false}function getSearchFormData(a){var b="";$("*[name]",a).each(function(){var c=$(this);if((c.attr("type")=="checkbox"||c.attr("type")=="radio")&&!c.attr("checked")){return}if(c.attr("type")=="submit"){return}b=b+c.attr("name")+"="+encodeURIComponent(c.val()).replace(/%20/g,"+")+"&"});return b.replace(/&$/g,"")}function findRetailers(b,a){$.ajax({method:"get",url:b,dataType:"json",data:a,beforeSend:function(){$("#loading").fadeIn("fast");document.body.style.cursor="wait"},complete:function(){$("#loading").fadeOut("fast");document.body.style.cursor="default"},success:function(g){$("#search_results").hide();$("#search_results_size").html(g.totalSizeMsg);$(".jq_sort_search_results").html(g.sort=="byDistance"?'<a href="javascript:void(0);" onclick="return sortRetailers(\'byType\');">Sort by retailer type</a>':'<a href="javascript:void(0);" onclick="return sortRetailers(\'byDistance\');">Sort by distance</a>');$("#messageArea").html(g.msgs);$("#search_results_locations").empty();GoogleMap.clearOverlays();var e=g.locations.length;var h=$("#addressSearchField").val();for(i=0;i<e;i++){var d=g.locations[i];var c=getLocationAddress(d);var j=convertLocationToHTML(h,e,d,c);$("#search_results_locations").append(j);if(d.a!=0){var f='<ol><li><h2><a href="/retailer/'+d.cd+'" target="_blank">'+d.n+"</a></h2></li>"+c+"</ol>";GoogleMap.data.push({pointId:"store"+d.i,lat:d.lt,lng:d.lg,description:f,icon:(d.pm?premiumIcon:baseIcon)})}}$("#search_results").fadeIn("fast");GoogleMap.render()},error:function(d,c,e){if(typeof console!="undefined"&&typeof console.debug!="undefined"){console.debug(d,c,e)}}})}function getLocationAddress(a){var b=new Array();if(a.fp){b.push("<li>"+a.fp+"</li>")}if(a.p){b.push("<li>"+a.p+"</li>")}if(a.a1){b.push("<li>"+a.a1+"</li>")}if(a.a2){b.push("<li>"+a.a2+"</li>")}if(a.a3){b.push("<li>"+a.a3+"</li>")}b.push("<li>"+a.c+", ");b.push(a.s+" ");b.push(a.z+"</li>");b.push("<li>("+a.d+" miles)</li>");return b.join("")}function handleScroll(){if($(window).scrollTop()>$("#search_map_blocker").offset({scroll:false}).top){$("#search_map").css("position",$.browser.msie?"absolute":"fixed");var a=($.browser.msie?$(window).scrollTop()-$("#search_map_blocker").offset({scroll:false}).top+$("#search_map_blocker").position().top:0);$("#search_map").css("top",a)}else{$("#search_map").css("position",$.browser.msie?"static":"relative");$("#search_map").css("top","0px")}}function createMap(){GoogleMap.createMap("map_canvas")}function showPopUp(c,g,d,h){var a="height="+h+",innerHeight="+h+",width="+d+",innerWidth="+d;if(window.screen){var f=(screen.availHeight-30);var b=(screen.availWidth-10);var j=((b-d)/2);var e=((f-h)/2);a+=",left="+j+",screenX="+j+",top="+e+",screenY="+e}w=window.open(c,g,a+",toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,alwaysRaised=yes,dependent=yes");w.focus();return w};jQuery.extend({historyCurrentHash:undefined,historyCallback:undefined,historyIframeSrc:undefined,historyNeedIframe:jQuery.browser.msie&&(jQuery.browser.version<8||document.documentMode<8),historyInit:function(e,d){jQuery.historyCallback=e;if(d){jQuery.historyIframeSrc=d}var c=location.hash.replace(/\?.*$/,"");jQuery.historyCurrentHash=c;if(jQuery.historyNeedIframe){if(jQuery.historyCurrentHash==""){jQuery.historyCurrentHash="#"}jQuery("body").prepend('<iframe id="jQuery_history" style="display: none;" src="javascript:false;"></iframe>');var a=jQuery("#jQuery_history")[0];var b=a.contentWindow.document;b.open();b.close();b.location.hash=c}else{if(jQuery.browser.safari){jQuery.historyBackStack=[];jQuery.historyBackStack.length=history.length;jQuery.historyForwardStack=[];jQuery.lastHistoryLength=history.length;jQuery.isFirst=true}}if(c){jQuery.historyCallback(c.replace(/^#/,""))}setInterval(jQuery.historyCheck,100)},historyAddHistory:function(a){jQuery.historyBackStack.push(a);jQuery.historyForwardStack.length=0;this.isFirst=true},historyCheck:function(){if(jQuery.historyNeedIframe){var a=jQuery("#jQuery_history")[0];var d=a.contentDocument||a.contentWindow.document;var f=d.location.hash.replace(/\?.*$/,"");if(f!=jQuery.historyCurrentHash){location.hash=f;jQuery.historyCurrentHash=f;jQuery.historyCallback(f.replace(/^#/,""))}}else{if(jQuery.browser.safari){if(jQuery.lastHistoryLength==history.length&&jQuery.historyBackStack.length>jQuery.lastHistoryLength){jQuery.historyBackStack.shift()}if(!jQuery.dontCheck){var b=history.length-jQuery.historyBackStack.length;jQuery.lastHistoryLength=history.length;if(b){jQuery.isFirst=false;if(b<0){for(var c=0;c<Math.abs(b);c++){jQuery.historyForwardStack.unshift(jQuery.historyBackStack.pop())}}else{for(var c=0;c<b;c++){jQuery.historyBackStack.push(jQuery.historyForwardStack.shift())}}var e=jQuery.historyBackStack[jQuery.historyBackStack.length-1];if(e!=undefined){jQuery.historyCurrentHash=location.hash.replace(/\?.*$/,"");jQuery.historyCallback(e)}}else{if(jQuery.historyBackStack[jQuery.historyBackStack.length-1]==undefined&&!jQuery.isFirst){if(location.hash){var f=location.hash;jQuery.historyCallback(location.hash.replace(/^#/,""))}else{var f="";jQuery.historyCallback("")}jQuery.isFirst=true}}}}else{var f=location.hash.replace(/\?.*$/,"");if(f!=jQuery.historyCurrentHash){jQuery.historyCurrentHash=f;jQuery.historyCallback(f.replace(/^#/,""))}}}},historyLoad:function(d){var e;d=decodeURIComponent(d.replace(/\?.*$/,""));if(jQuery.browser.safari){e=d}else{e="#"+d;location.hash=e}jQuery.historyCurrentHash=e;if(jQuery.historyNeedIframe){var a=jQuery("#jQuery_history")[0];var c=a.contentWindow.document;c.open();c.close();c.location.hash=e;jQuery.lastHistoryLength=history.length;jQuery.historyCallback(d)}else{if(jQuery.browser.safari){jQuery.dontCheck=true;this.historyAddHistory(d);var b=function(){jQuery.dontCheck=false};window.setTimeout(b,200);jQuery.historyCallback(d);location.hash=e}else{jQuery.historyCallback(d)}}}});