(function(b){var a=function(o,f,l){this.$input=o;this.$map_elt=f;var i={acBox:{create:true,klass:"",id:"the-map-ac",position:"after",selector:"#the-map-ac",width:360},height:160,streets:true,lat:null,lng:null,accuracy:null,form_elts_prefix:null,clearable:false};this.cfg=l=b.extend(true,{},i,l);l.prefix=l.form_elts_prefix?l.form_elts_prefix+"-":"";if(l.acBox.create){var n=(l.acBox.klass?' class="'+l.acBox.klass+'"':""),j=(l.acBox.id?' id="'+l.acBox.id+'"':""),k='<div class="yui-skin-sam yui-ac"><div'+j+n+"></div></div>";o[l.acBox.position](k)}var d,h=new GClientGeocoder(),c=h.getCache(),r={1:3,2:5,3:8,4:10,5:10};var m=function(s){if(!f||!f.size()){throw new Error("did not specify map element","did not specify map element")}if(d){return d}if(l.height){f.height(l.height)}f.show();d=new GMap2(f.get(0));var u=new GLatLng(l.lat||37.4419,l.lng||-122.1419);d.setCenter(u,r[l.accuracy]||13);if(s){d.addOverlay(new GMarker(u))}var t=d.getDefaultUI();b.extend(t.controls,{largemapcontrol3d:false,smallzoomcontrol3d:true,maptypecontrol:false,menumaptypecontrol:false,scalecontrol:false});d.setUI(t);return d};var p=function(){return{address:"",lat:"",lng:"",accuracy:0,country_name_code:""}};var g;var q=function(){if(l.prefix){b(":input[id^=id_"+l.prefix+"-]").val("")}};if(l.clearable){g=b('<a class="btn-box" href="#" onclick="return false">Clear</a>').click(function(){o.val("").data("GEO_LOCATION",p());q();if(d){d.clearOverlays()}});o.after(g)}if(l.lat&&l.lng){m(true)}var e=function(u,s){if(typeof(u[s])!="undefined"){return u[s]}var t,v;for(t in u){if(typeof(u[t])=="object"&&u[t]!==null){v=e(u[t],s);if(typeof(v)!="undefined"){break}}}return v};this.enhancePlacemark=function(t){t.point=new GLatLng(t.Point.coordinates[1],t.Point.coordinates[0]);if(t.ExtendedData&&t.ExtendedData.LatLonBox){var s=t.ExtendedData.LatLonBox;t.bounds=new GLatLngBounds(new GLatLng(s.south,s.west),new GLatLng(s.north,s.east))}else{t.bounds=newGLatLngBounds();t.bounds.extend(t.point)}if(!l.streets&&t.AddressDetails.Accuracy>=6){var u=e(t,"ThoroughfareName");if(u&&t.address.substring(0,u.length)==u){t._address=t.address;t.address=t.address.substring(u.length).replace(/^[\s,\-]+/,"")}}if(!l.streets&&t.AddressDetails.Country.CountryNameCode=="US"){if(!t._address){t._address=t.address}t.address=t.address.replace(/ \d{5}, USA$/,", USA")}t.data={address:t.address,lat:t.Point.coordinates[1],lng:t.Point.coordinates[0],accuracy:t.AddressDetails.Accuracy,country_name_code:(t.AddressDetails.Country?t.AddressDetails.Country.CountryNameCode:"")};return t};this.xhrFunc=function(s,t){return h.getLocations(s,t)};this.acActivate=function(z,y,w){if(d){d.clearOverlays()}var x;if(w=="custom"){x=p();x.address=o.val();x.custom_location=1;o.val(x.address).data("GEO_LOCATION",x)}else{x=w.data;x.custom_location=0;o.val(x.address).data("GEO_LOCATION",x);m();var v=new GMarker(w.point),t,u;d.addOverlay(v);d.setCenter(w.bounds.getCenter(),d.getBoundsZoomLevel(w.bounds))}if(l.form_elts_prefix||l.no_form_prefix){q();for(var s in x){b("#id_"+l.prefix+s).val(x[s]||"")}}b("body").trigger("cancel.hunchac");return false}};b.acmap={errors:{none:"Please enter an address and select a location from the dropdown.",unselected:"Please update your location by selecting it from the dropdown."}};b.fn.extend({acmap:function(f,c){var e=new a(b(this),b(f),c);c=e.cfg;var d=this;if(c.form_elts_prefix||c.add_submit_func){b(this).closest("form").submit(function(){if(b(d).val()!=b("#id_"+c.prefix+"address").val()){window.scrollTo(0,b(d).addError({msg:b.acmap.errors.unselected}).parent().offset().top);return false}return true})}return b(this).hunchac({timeout:300,container:e.cfg.acBox.selector,render:function(n,g,m){var l=b("<ul/>"),i=(e.cfg.acBox.width?' style="width:'+e.cfg.acBox.width+'px;"':""),k=n.Placemark,o=0,j;if(n.status==620){l.append('<li class="ac-header ac-first-header">You have exceeded the map query quota!</li>')}else{if(k&&k.length){b.each(k,function(){e.enhancePlacemark(this);j=b('<li class="ac-element">'+this.address+"</li>");b.data(j[0],b.hunchac.ORIGINAL_OBJECT,this);l.append(j)});o=k.length}else{l.append('<li class="ac-header ac-first-header"><em>No matches found…</em></li>');o=0}}j=b('<li class="ac-element">Use a custom location (won’t help with local)</li>');b.data(j[0],b.hunchac.ORIGINAL_OBJECT,"custom");l.append(j);o+=1;g.html("<div"+i+' class="yui-ac-content" /><div class="yui-ac-shadow" />');var h=b(".yui-ac-content",g);h.append(l);b(".yui-ac-shadow",g).height(h.height()+2).width(h.width()+2);return o},jsonListAttr:"",xhrFunc:e.xhrFunc,activate:e.acActivate})},acmapLocation:function(){return b(this).data("GEO_LOCATION")}})})(jQuery);