(function($){$.fn.filterMenu=function(menu_selector,options){var opts=$.extend({},$.fn.filterMenu.defaults,options);return this.each(function(){$this=$(this);$this.data('menu',menu_selector);var $menu=$(menu_selector);var o=$.meta?$.extend({},opts,$this.data()):opts;$menu.find('ul').each(function(){$(this).wrap("<div class=\"shadow_offset\"></div>");});$this.click(showMenu);$('body').click(function(){$menu.css({display:'none'});});$menu.find('li').each(function(){var isSelected=false;var isAllItem=false;if($(this).html()==o.allItemHtml)
isAllItem=true;if($(this).hasClass(o.selectedClass)){isSelected=true;}
$(this).data('itemData',{menu:$menu,menuTitle:$this,options:o,selected:isSelected,allItem:isAllItem});$(this).hover(o.onItemHover,o.onItemHoverOut);$(this).click(baseItemClick);});setMenuTitle($menu,$this);});};function showMenu(e){var el=$(e.target);var m=$(el.data('menu'));$('body').trigger('click');m.css({display:'none'});m.css({left:el.position().left+'px',top:el.position().top+el.height()+'px'});m.css({display:'block'});return false;};function itemHover(e){var el=$(e.target);var hoverClass=el.data('itemData').options.hoverClass;if(!el.hasClass(hoverClass))
el.addClass(hoverClass);};function itemHoverOut(e){var el=$(e.target);var hoverClass=el.data('itemData').options.hoverClass;if(el.hasClass(hoverClass))
el.removeClass(hoverClass);};function baseItemClick(e){var el=$(e.target);var itemData=el.data('itemData');var o=itemData.options;if(itemData.selected){if(o.exclusiveOptions)
return;if(itemData.allItem)
return;setItemIsSelected(el,false);if(selectedItemsCount(itemData.menu)==0)
setAllItemIsSelected(itemData.menu,true);}else{if(o.exclusiveOptions||itemData.allItem)
clearSelectedItems(itemData.menu);setItemIsSelected(el,true);if(!o.exclusiveOptions&&!itemData.allItem)
setAllItemIsSelected(itemData.menu,false);}
setMenuTitle(itemData.menu,itemData.menuTitle);o.onItemClick(e);};function setMenuTitle(menu,menuTitle){var title;var selectedCount=0;menu.find('li').each(function(){var itemData=$(this).data('itemData');if(itemData.selected){selectedCount++;title=jQuery.trim($(this).html());if(itemData.options.exclusiveOptions)
return false;}});if(selectedCount>1)
title="(multiple)";menuTitle.html(title);};function selectedItemsCount(menu){var count=0;menu.find('li').each(function(){var itemData=$(this).data('itemData');if(itemData.selected)
count++;});return count;};function setItemIsSelected(item,selected){var itemData=item.data('itemData');var o=itemData.options;if(selected){itemData.selected=true;if(!item.hasClass(o.selectedClass))
item.addClass(o.selectedClass);}else{itemData.selected=false;if(item.hasClass(o.selectedClass));item.removeClass(o.selectedClass);}};function setAllItemIsSelected(menu,selected){menu.find('li').each(function(){var itemData=$(this).data('itemData');if(itemData.allItem){setItemIsSelected($(this),selected);return false;}});};function itemClick(e){var el=$(e.target);el.find('>a').each(function(){if(this.href)
window.location=this.href;});return false;};function clearSelectedItems(menu){menu.find('li').each(function(){var itemData=$(this).data('itemData');if(itemData.selected){itemData.selected=false;if($(this).hasClass(itemData.options.selectedClass));$(this).removeClass(itemData.options.selectedClass);}});};$.fn.filterMenu.defaults={hoverClass:'menuItemHover',selectedClass:'menuItemSelected',exclusiveOptions:false,allItemHtml:null,onItemHover:itemHover,onItemHoverOut:itemHoverOut,onItemClick:itemClick};})(jQuery);eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(';(3($){$.31.1o({12:3(b,d){5 c=Y b=="1w";d=$.1o({},$.D.1L,{11:c?b:14,w:c?14:b,1D:c?$.D.1L.1D:10,Z:d&&!d.1x?10:3U},d);d.1t=d.1t||3(a){6 a};d.1q=d.1q||d.1K;6 I.K(3(){1E $.D(I,d)})},M:3(a){6 I.X("M",a)},1y:3(a){6 I.15("1y",[a])},20:3(){6 I.15("20")},1Y:3(a){6 I.15("1Y",[a])},1X:3(){6 I.15("1X")}});$.D=3(o,r){5 t={2N:38,2I:40,2D:46,2x:9,2v:13,2q:27,2d:3x,2j:33,2o:34,2e:8};5 u=$(o).3f("12","3c").P(r.24);5 p;5 m="";5 n=$.D.2W(r);5 s=0;5 k;5 h={1z:B};5 l=$.D.2Q(r,o,1U,h);5 j;$.1T.2L&&$(o.2K).X("3S.12",3(){4(j){j=B;6 B}});u.X(($.1T.2L?"3Q":"3N")+".12",3(a){k=a.2F;3L(a.2F){Q t.2N:a.1d();4(l.L()){l.2y()}A{W(0,C)}N;Q t.2I:a.1d();4(l.L()){l.2u()}A{W(0,C)}N;Q t.2j:a.1d();4(l.L()){l.2t()}A{W(0,C)}N;Q t.2o:a.1d();4(l.L()){l.2s()}A{W(0,C)}N;Q r.19&&$.1p(r.R)==","&&t.2d:Q t.2x:Q t.2v:4(1U()){a.1d();j=C;6 B}N;Q t.2q:l.U();N;3A:1I(p);p=1H(W,r.1D);N}}).1G(3(){s++}).3v(3(){s=0;4(!h.1z){2k()}}).2i(3(){4(s++>1&&!l.L()){W(0,C)}}).X("1y",3(){5 c=(1n.7>1)?1n[1]:14;3 23(q,a){5 b;4(a&&a.7){16(5 i=0;i<a.7;i++){4(a[i].M.O()==q.O()){b=a[i];N}}}4(Y c=="3")c(b);A u.15("M",b&&[b.w,b.H])}$.K(1g(u.J()),3(i,a){1R(a,23,23)})}).X("20",3(){n.18()}).X("1Y",3(){$.1o(r,1n[1]);4("w"2G 1n[1])n.1f()}).X("1X",3(){l.1u();u.1u();$(o.2K).1u(".12")});3 1U(){5 b=l.26();4(!b)6 B;5 v=b.M;m=v;4(r.19){5 a=1g(u.J());4(a.7>1){v=a.17(0,a.7-1).2Z(r.R)+r.R+v}v+=r.R}u.J(v);1l();u.15("M",[b.w,b.H]);6 C}3 W(b,c){4(k==t.2D){l.U();6}5 a=u.J();4(!c&&a==m)6;m=a;a=1k(a);4(a.7>=r.22){u.P(r.21);4(!r.1C)a=a.O();1R(a,2V,1l)}A{1B();l.U()}};3 1g(b){4(!b){6[""]}5 d=b.1Z(r.R);5 c=[];$.K(d,3(i,a){4($.1p(a))c[i]=$.1p(a)});6 c}3 1k(a){4(!r.19)6 a;5 b=1g(a);6 b[b.7-1]}3 1A(q,a){4(r.1A&&(1k(u.J()).O()==q.O())&&k!=t.2e){u.J(u.J()+a.48(1k(m).7));$.D.1N(o,m.7,m.7+a.7)}};3 2k(){1I(p);p=1H(1l,47)};3 1l(){5 c=l.L();l.U();1I(p);1B();4(r.2U){u.1y(3(a){4(!a){4(r.19){5 b=1g(u.J()).17(0,-1);u.J(b.2Z(r.R)+(b.7?r.R:""))}A u.J("")}})}4(c)$.D.1N(o,o.H.7,o.H.7)};3 2V(q,a){4(a&&a.7&&s){1B();l.2T(a,q);1A(q,a[0].H);l.1W()}A{1l()}};3 1R(f,d,g){4(!r.1C)f=f.O();5 e=n.2S(f);4(e&&e.7){d(f,e)}A 4((Y r.11=="1w")&&(r.11.7>0)){5 c={45:+1E 44()};$.K(r.2R,3(a,b){c[a]=Y b=="3"?b():b});$.43({42:"41",3Z:"12"+o.3Y,2M:r.2M,11:r.11,w:$.1o({q:1k(f),3X:r.Z},c),3W:3(a){5 b=r.1r&&r.1r(a)||1r(a);n.1h(f,b);d(f,b)}})}A{l.2J();g(f)}};3 1r(c){5 d=[];5 b=c.1Z("\\n");16(5 i=0;i<b.7;i++){5 a=$.1p(b[i]);4(a){a=a.1Z("|");d[d.7]={w:a,H:a[0],M:r.1v&&r.1v(a,a[0])||a[0]}}}6 d};3 1B(){u.1e(r.21)}};$.D.1L={24:"3R",2H:"3P",21:"3O",22:1,1D:3M,1C:B,1a:C,1V:B,1j:10,Z:3K,2U:B,2R:{},1S:C,1K:3(a){6 a[0]},1q:14,1A:B,E:0,19:B,R:", ",1t:3(b,a){6 b.2C(1E 3J("(?![^&;]+;)(?!<[^<>]*)("+a.2C(/([\\^\\$\\(\\)\\[\\]\\{\\}\\*\\.\\+\\?\\|\\\\])/2A,"\\\\$1")+")(?![^<>]*>)(?![^&;]+;)","2A"),"<2z>$1</2z>")},1x:C,1s:3I};$.D.2W=3(g){5 h={};5 j=0;3 1a(s,a){4(!g.1C)s=s.O();5 i=s.3H(a);4(i==-1)6 B;6 i==0||g.1V};3 1h(q,a){4(j>g.1j){18()}4(!h[q]){j++}h[q]=a}3 1f(){4(!g.w)6 B;5 f={},2w=0;4(!g.11)g.1j=1;f[""]=[];16(5 i=0,30=g.w.7;i<30;i++){5 c=g.w[i];c=(Y c=="1w")?[c]:c;5 d=g.1q(c,i+1,g.w.7);4(d===B)1P;5 e=d.3G(0).O();4(!f[e])f[e]=[];5 b={H:d,w:c,M:g.1v&&g.1v(c)||d};f[e].1O(b);4(2w++<g.Z){f[""].1O(b)}};$.K(f,3(i,a){g.1j++;1h(i,a)})}1H(1f,25);3 18(){h={};j=0}6{18:18,1h:1h,1f:1f,2S:3(q){4(!g.1j||!j)6 14;4(!g.11&&g.1V){5 a=[];16(5 k 2G h){4(k.7>0){5 c=h[k];$.K(c,3(i,x){4(1a(x.H,q)){a.1O(x)}})}}6 a}A 4(h[q]){6 h[q]}A 4(g.1a){16(5 i=q.7-1;i>=g.22;i--){5 c=h[q.3F(0,i)];4(c){5 a=[];$.K(c,3(i,x){4(1a(x.H,q)){a[a.7]=x}});6 a}}}6 14}}};$.D.2Q=3(e,g,f,k){5 h={G:"3E"};5 j,y=-1,w,1m="",1M=C,F,z;3 2r(){4(!1M)6;F=$("<3D/>").U().P(e.2H).T("3C","3B").1J(2p.2n);z=$("<3z/>").1J(F).3y(3(a){4(V(a).2m&&V(a).2m.3w()==\'2l\'){y=$("1F",z).1e(h.G).3u(V(a));$(V(a)).P(h.G)}}).2i(3(a){$(V(a)).P(h.G);f();g.1G();6 B}).3t(3(){k.1z=C}).3s(3(){k.1z=B});4(e.E>0)F.T("E",e.E);1M=B}3 V(a){5 b=a.V;3r(b&&b.3q!="2l")b=b.3p;4(!b)6[];6 b}3 S(b){j.17(y,y+1).1e(h.G);2h(b);5 a=j.17(y,y+1).P(h.G);4(e.1x){5 c=0;j.17(0,y).K(3(){c+=I.1i});4((c+a[0].1i-z.1c())>z[0].3o){z.1c(c+a[0].1i-z.3n())}A 4(c<z.1c()){z.1c(c)}}};3 2h(a){y+=a;4(y<0){y=j.1b()-1}A 4(y>=j.1b()){y=0}}3 2g(a){6 e.Z&&e.Z<a?e.Z:a}3 2f(){z.2B();5 b=2g(w.7);16(5 i=0;i<b;i++){4(!w[i])1P;5 a=e.1K(w[i].w,i+1,b,w[i].H,1m);4(a===B)1P;5 c=$("<1F/>").3m(e.1t(a,1m)).P(i%2==0?"3l":"3k").1J(z)[0];$.w(c,"2c",w[i])}j=z.3j("1F");4(e.1S){j.17(0,1).P(h.G);y=0}4($.31.2b)z.2b()}6{2T:3(d,q){2r();w=d;1m=q;2f()},2u:3(){S(1)},2y:3(){S(-1)},2t:3(){4(y!=0&&y-8<0){S(-y)}A{S(-8)}},2s:3(){4(y!=j.1b()-1&&y+8>j.1b()){S(j.1b()-1-y)}A{S(8)}},U:3(){F&&F.U();j&&j.1e(h.G);y=-1},L:3(){6 F&&F.3i(":L")},3h:3(){6 I.L()&&(j.2a("."+h.G)[0]||e.1S&&j[0])},1W:3(){5 a=$(g).3g();F.T({E:Y e.E=="1w"||e.E>0?e.E:$(g).E(),2E:a.2E+g.1i,1Q:a.1Q}).1W();4(e.1x){z.1c(0);z.T({29:e.1s,3e:\'3d\'});4($.1T.3b&&Y 2p.2n.3T.29==="3a"){5 c=0;j.K(3(){c+=I.1i});5 b=c>e.1s;z.T(\'3V\',b?e.1s:c);4(!b){j.E(z.E()-28(j.T("32-1Q"))-28(j.T("32-39")))}}}},26:3(){5 a=j&&j.2a("."+h.G).1e(h.G);6 a&&a.7&&$.w(a[0],"2c")},2J:3(){z&&z.2B()},1u:3(){F&&F.37()}}};$.D.1N=3(b,a,c){4(b.2O){5 d=b.2O();d.36(C);d.35("2P",a);d.4c("2P",c);d.4b()}A 4(b.2Y){b.2Y(a,c)}A{4(b.2X){b.2X=a;b.4a=c}}b.1G()}})(49);',62,261,'|||function|if|var|return|length|||||||||||||||||||||||||data||active|list|else|false|true|Autocompleter|width|element|ACTIVE|value|this|val|each|visible|result|break|toLowerCase|addClass|case|multipleSeparator|moveSelect|css|hide|target|onChange|bind|typeof|max||url|autocomplete||null|trigger|for|slice|flush|multiple|matchSubset|size|scrollTop|preventDefault|removeClass|populate|trimWords|add|offsetHeight|cacheLength|lastWord|hideResultsNow|term|arguments|extend|trim|formatMatch|parse|scrollHeight|highlight|unbind|formatResult|string|scroll|search|mouseDownOnSelect|autoFill|stopLoading|matchCase|delay|new|li|focus|setTimeout|clearTimeout|appendTo|formatItem|defaults|needsInit|Selection|push|continue|left|request|selectFirst|browser|selectCurrent|matchContains|show|unautocomplete|setOptions|split|flushCache|loadingClass|minChars|findValueCallback|inputClass||selected||parseInt|maxHeight|filter|bgiframe|ac_data|COMMA|BACKSPACE|fillList|limitNumberOfItems|movePosition|click|PAGEUP|hideResults|LI|nodeName|body|PAGEDOWN|document|ESC|init|pageDown|pageUp|next|RETURN|nullData|TAB|prev|strong|gi|empty|replace|DEL|top|keyCode|in|resultsClass|DOWN|emptyList|form|opera|dataType|UP|createTextRange|character|Select|extraParams|load|display|mustMatch|receiveData|Cache|selectionStart|setSelectionRange|join|ol|fn|padding|||moveStart|collapse|remove||right|undefined|msie|off|auto|overflow|attr|offset|current|is|find|ac_odd|ac_even|html|innerHeight|clientHeight|parentNode|tagName|while|mouseup|mousedown|index|blur|toUpperCase|188|mouseover|ul|default|absolute|position|div|ac_over|substr|charAt|indexOf|180|RegExp|100|switch|400|keydown|ac_loading|ac_results|keypress|ac_input|submit|style|150|height|success|limit|name|port||abort|mode|ajax|Date|timestamp||200|substring|jQuery|selectionEnd|select|moveEnd'.split('|'),0,{}))
storeLocation=function(){var location;var initialized=false;var init=function(){if(!initialized){$('#location_edit').jqm();$('#new_store_location_customization').validate({submitHandler:submitLocationCustomizationForm,rules:{"store_location_customization[name]":{required:true},"store_location_customization[address]":{required:true},"store_location_customization[city]":{required:true},"store_location_customization[state]":{required:true,minlength:2,maxlength:2},"store_location_customization[zip]":{required:true,zipcode:true}},messages:{"store_location_customization[name]":{required:'Please specify a store name.'},"store_location_customization[address]":{required:'Please specify an address.'},"store_location_customization[city]":{required:'Please specify a city.'},"store_location_customization[state]":{required:'Please specify a state abbreviation.',minlength:jQuery.format('A state abbreviation should be {0} characters.'),maxlength:jQuery.format('A state abbreviation should be {0} characters.')},"store_location_customization[zip]":{required:'Please specify a zip code.',zipcode:'Please specify a valid zip code.'}}});initialized=true;}};var getLocationInfoContainerHtml=function(){return"<div class=\"store_location_info\"></div>";};var getLocationInfoHtml=function(){var html="<div class=\"store_logo\">";html+="<img src=\"/images/"+location.store.icon+".png\" alt=\""+location.store.name+"\" title=\""+location.store.name+"\" />";html+="</div>";html+="<div class=\"store_info\">";html+="<p><b><a href=\"/locations/"+globalUI.slug(location.store.name)+"/"+location.id+"\">"+location.store.name+"</a></b>";html+="<span class=\"inline-rating\"";if($.browser.msie)
html+=" onclick=\"storeLocation.rate(event)\"";html+=">";var width=0,rating=location.average_rating;var classNames="current-rating";if(location.user_rating){rating=location.user_rating;classNames="current-rating user-rating";}
width=rating*20;html+="<ul class=\"star-rating small-star\">";html+="<li class=\""+classNames+"\" style=\"width:"+width+"%\">Currently "+rating+"/5 Stars.</li>";html+="<li><a href=\"#\" title=\"1 star out of 5\" class=\"one-star\">1</a></li>";html+="<li><a href=\"#\" title=\"2 stars out of 5\" class=\"two-stars\">2</a></li>";html+="<li><a href=\"#\" title=\"3 stars out of 5\" class=\"three-stars\">3</a></li>";html+="<li><a href=\"#\" title=\"4 stars out of 5\" class=\"four-stars\">4</a></li>";html+="<li><a href=\"#\" title=\"5 stars out of 5\" class=\"five-stars\">5</a></li>";html+="</ul>";html+="</span>";html+="<br/>"+location.address+"<br/>";html+=location.city+", "+location.state+" "+location.zip;if(location.description)
html+="<br/><i>"+location.description+"</i>";html+="</p>";html+="</div>";html+="<div class=\"store_controls\">";if(location.favorite){html+="<img src=\"/images/favorite.png\" alt=\"Favorite\" class=\"favorite_toggle\" ";if($.browser.msie)
html+="onclick=\"storeLocation.favtog()\"";html+="/>";}
else{html+="<img src=\"/images/favorite_off.png\" alt=\"Favorite Off\" class=\"favorite_toggle\" ";if($.browser.msie)
html+="onclick=\"storeLocation.favtog()\"";html+="/>";}
html+="<img src=\"/images/edit.png\" alt=\"Edit Location\" class=\"edit_trigger\" ";if($.browser.msie)
html+="onclick=\"storeLocation.edit()\"";html+="/>";html+="<img src=\"/images/hide.png\" alt=\"Hide\" class=\"hidden_toggle\" ";if($.browser.msie)
html+="onclick=\"storeLocation.hidtog()\"";html+="/>";if(location.customized||!location.verified)
html+="<img src=\"/images/user_modified.png\" alt=\"User Modified\"/>";html+="</div>";return html;};var toggleFavorite=function(e){if(!AUTHED){loginHelper.showLogin();return;}
var params={store_location_id:location.id};if(location.favorite){$.dJSON('/user_favorites/'+location.favorite_id,params,function(json){location.favorite=false;updateFavoriteControl();});}else{$.pJSON('/user_favorites/',params,function(json){location.favorite=true;updateFavoriteControl();});}};var updateFavoriteControl=function(){$('.favorite_toggle').each(function(){var img=$(this);if(location.favorite){img.attr({src:'/images/favorite.png',alt:'Favorite'});}else{img.attr({src:'/images/favorite_off.png',alt:'Favorite Off'});}});};var toggleHidden=function(e){if(!AUTHED){loginHelper.showLogin();return;}
var params={store_location_id:location.id};if(location.hidden){$.dJSON('/hidden_locations/'+location.hidden_id,params,function(json){location.hidden=false;locationMapper.refreshMap(false);});}else{if(!AUTHED){globalUI.flashError("Access Denied!");return;}
globalUI.confirm("You are about to hide this location.",function(){$.pJSON('/hidden_locations/',params,function(json){location.hidden=true;locationMapper.refreshMap(false);});});}};var showLocationCustomizationForm=function(e){if(!AUTHED){loginHelper.showLogin();return;}
$('#store_location_customization_name').val(location.store.name);$('#store_location_customization_address').val(location.address);$('#store_location_customization_city').val(location.city);$('#store_location_customization_state').val(location.state);$('#store_location_customization_zip').val(location.zip);$('#store_location_customization_description').val(location.description);$('#store_location_customization_store_location_id').val(location.id);$('#location_edit').jqmShow();};var resetStoreInfoHtml=function(e){unbindEvents();$('.store_location_info').html(getLocationInfoHtml());bindEvents();};var submitLocationCustomizationForm=function(submitForm){var form=$(submitForm);var url=form.attr('action');var data=form.serializeArray();$.pJSON(url,data,function(json){location.store.name=json.store_location_customization.name;location.address=json.store_location_customization.address;location.city=json.store_location_customization.city;location.state=json.store_location_customization.state;location.zip=json.store_location_customization.zip;location.description=json.store_location_customization.description;location.customized=true;resetStoreInfoHtml();$('#location_edit').jqmHide();});return false;};var submitRating=function(e){if(!AUTHED){loginHelper.showLogin();return false;}
var node=e.srcElement;if(!node)node=e.target;if(node.nodeName.toLowerCase()!='a')
return false;var a=$(node);var rating=parseInt(a.attr('title').substring(0,1));var url='/ratings';var data={rateable_id:location.id,rateable_type:'StoreLocation',rating:rating};$.pJSON(url,data,function(json){location.user_rating=json.rating;$('.current-rating').each(function(){var width=(location.user_rating*20)+'%';$(this).css('width',width);if(location.user_rating==0){if($(this).hasClass('user-rating'))
$(this).removeClass('user-rating');}else{if(!$(this).hasClass('user-rating'))
$(this).addClass('user-rating');}});});return false;};var controlClicked=function(e){var target=$(e.target);if(target.hasClass('favorite_toggle')){toggleFavorite(e);}else if(target.hasClass('hidden_toggle')){toggleHidden(e);}else if(target.hasClass('edit_trigger')){showLocationCustomizationForm(e);}};var unbindEvents=function(){if(!$.browser.msie){$('.inline-rating').unbind('click');$('.store_controls').unbind('click');}};var bindEvents=function(){if(!$.browser.msie){$('.inline-rating').click(submitRating);$('.store_controls').click(controlClicked);}};return{location:location,getLocation:function(){return location;},setLocation:function(loc){init();unbindEvents();location=loc;},wireEvents:function(){bindEvents();},favtog:function(e){toggleFavorite(e);},hidtog:function(e){toggleHidden(e);},edit:function(e){showLocationCustomizationForm(e);},rate:function(e){submitRating(e);},id:function(){return location.id;},html:function(){var locInfo=$(getLocationInfoContainerHtml());locInfo.append(getLocationInfoHtml());return locInfo.outerHTML();}}}();locationMapper=function(){var map;var listeners=[];var stores=[];var filteredStores=[];var locations;var infoWindowOpening=false;var DEFAULT_ZOOM=13;var activeLocation=storeLocation;var defaultStoreInfoHtml;var updateSearchLocation=function(latlng){map.setCenter(latlng);if(latlng.lat()!=$.cookie('lat')||latlng.lng()!=$.cookie('lng')){$.cookie('lat',latlng.lat());$.cookie('lng',latlng.lng());refresh();}};var getStores=function(){var params={};var url="/stores";$.gJSON(url,params,function(json){stores=[];$.each(json,function(i,val){stores.push({id:val.store.id,name:val.store.name});});buildStoreFilter();$('#store_location_customization_name').autocomplete(stores,{matchContains:true,autoFill:true,formatItem:function(row,i,max){return row.name;}});$('#store_location_name').autocomplete(stores,{matchContains:true,autoFill:true,formatItem:function(row,i,max){return row.name;}});$('#store_location_name').result(function(event,data,formatted){$('#store_location_store_id').val(data.id);});});};var buildStoreFilter=function(){if($.cookie('store_filter')){var f=$.cookie('store_filter').split(',');for(var i=0;i<f.length;i++)
filteredStores.push(parseInt(f[i]));}
var fl=$('#store_chooser > ul:first');$.each(stores,function(i,val){var item=$('<li>'+val.name+"</li>");item.data('store_id',val.id);if($.inArray(parseInt(val.id),filteredStores)!=-1)
item.addClass($.fn.filterMenu.defaults.selectedClass);fl.append(item);});fl.append($('<hr/>'))
var all=$('<li>All</li>');if(filteredStores.length==0)
all.addClass($.fn.filterMenu.defaults.selectedClass);fl.append(all);$('#store_filter').filterMenu('#store_chooser',{allItemHtml:'All',onItemClick:filterStore});};var refresh=function(){var params={};$.gJSON('/',params,function(json){locations=json;mapLocations();});};var mapLocations=function(){resetOverlays();$.each(locations,function(i,val){if(!val.store_location.hidden)
if(filteredStores.length==0||$.inArray(val.store_location.store_id,filteredStores)!=-1)
createMarker(val.store_location);});var opts={draggable:true};var searchNearby=new GMarker(new GLatLng($.cookie('lat'),$.cookie('lng')),opts);searchNearby.enableDragging();var listener=GEvent.addListener(searchNearby,'dragend',function(latlng){updateSearchLocation(latlng);});listeners.push(listener);map.addOverlay(searchNearby);};var createMarker=function(location){var point=new GLatLng(location.latitude,location.longitude);var storeIcon=new GIcon(G_DEFAULT_ICON);storeIcon.image="images/"+location.store.icon+".png";var markerOptions={icon:storeIcon};var marker=new GMarker(point,markerOptions);var listener=GEvent.addListener(marker,'click',function(){infoWindowOpening=true;activeLocation.setLocation(location);if(!$.browser.msie)
marker.openInfoWindow(activeLocation.html());$('#store_info_container').html(activeLocation.html());});listeners.push(listener);listener=GEvent.addListener(marker,'infowindowopen',activeLocation.wireEvents);listeners.push(listener);map.addOverlay(marker);};var resetOverlays=function(){$.each(listeners,function(i,val){GEvent.removeListener(val);});listeners=[];map.clearOverlays();};var updateDistance=function(e){$.cookie('dist',$(e.target).html());refresh();};var filterStore=function(e){filteredStores=[];$('#store_chooser > div > ul > li').each(function(){if($(this).data('itemData').selected){var store=$(this).html();if(store!='All')
filteredStores.push(parseInt($(this).data('store_id')));}});$.cookie('store_filter',filteredStores.join(','));mapLocations();};var reset=function(e){$.cookie('lat',null);$.cookie('lng',null);$.cookie('dist',null);$.cookie('zoom',null);$.cookie('search',null);$.cookie('store_filter',null);refresh();};var search=function(e){if(!$('#search_form').valid())return;var searchText=$('#search').val();if(!searchText){alert("Please enter an address or location.");return;}
var geocoder=new GClientGeocoder();geocoder.getLatLng(searchText,function(latlng){if(!latlng)
alert(searchText+" not found. Please try again.");else{$.cookie('search',searchText);updateSearchLocation(latlng);}});};var showLocationAddForm=function(e){if(!AUTHED){loginHelper.showLogin();return;}
$('#store_location_name').val('');$('#store_location_store_id').val('0');$('#store_location_address').val('');$('#store_location_city').val('');$('#store_location_state').val('');$('#store_location_zip').val('');$('#store_location_description').val('');$('#location_add').jqmShow();};var submitAddLocationForm=function(submitForm){var form=$(submitForm);var url=form.attr('action');var data=form.serializeArray();var geocoder=new GClientGeocoder();var address=$('#store_location_address').val();address+=", "+$('#store_location_city').val();address+=", "+$('#store_location_state').val();address+=" "+$('#store_location_zip').val();geocoder.getLatLng(address,function(latlng){if(!latlng)
alert(searchText+" not found. Please try again.");else{data.push({name:'store_location[latitude]',value:latlng.lat()});data.push({name:'store_location[longitude]',value:latlng.lng()});$.pJSON(url,data,function(json){locations.push(json);mapLocations();$('#location_add').jqmHide();globalUI.flashNotice("New location added.");map.setCenter(latlng);});}});return false;};return{init:function(){if(!GBrowserIsCompatible())
return;$(window).unload(GUnload);defaultStoreInfoHtml=$('#store_info_container').html();loginHelper.setOptions({loggedIn:function(){globalUI.flashNotice("Welcome "+USERNAME);refresh();}});$('#distance_chooser > ul > li').each(function(){var o=parseFloat($(this).html());var d=parseFloat($.cookie('dist'));if(o==d)
$(this).addClass($.fn.filterMenu.defaults.selectedClass);});$('#location_add').jqm();$('#new_store_location').validate({submitHandler:submitAddLocationForm,rules:{store_location_name:{required:true},"store_location[address]":{required:true},"store_location[city]":{required:true},"store_location[state]":{required:true,minlength:2,maxlength:2},"store_location[zip]":{required:true,zipcode:true}},messages:{store_location_name:{required:'Please specify a store name.'},"store_location[address]":{required:'Please specify an address.'},"store_location[city]":{required:'Please specify a city.'},"store_location[state]":{required:'Please specify a state abbreviation.',minlength:jQuery.format('A state abbreviation should be {0} characters.'),maxlength:jQuery.format('A state abbreviation should be {0} characters.')},"store_location[zip]":{required:'Please specify a zip code.',zipcode:'Please specify a valid zip code.'}}});$('.add_location').click(showLocationAddForm);if($.cookie('search')){$('#search').val($.cookie('search'));$('#search').css('color','');}
$('#search_form').validate({rules:{search:{required:true,notwatermark:true}},messages:{search:'Please enter an address or location.'},errorLabelContainer:'#search_error',onkeyup:false});$('#search_button').click(search);$('#search_form').keypress(function(e){if(e.keyCode==13){$('#search_button').trigger('click');return false;}});$('#reset_cookies').click(reset);$('#distance_filter').filterMenu('#distance_chooser',{exclusiveOptions:true,onItemClick:updateDistance});var zoom=$.cookie('zoom');if(!zoom){zoom=DEFAULT_ZOOM;$.cookie('zoom',zoom);}
var start=new GLatLng($.cookie('lat'),$.cookie('lng'));map=new GMap2($('#map_canvas')[0]);map.enableScrollWheelZoom();map.disableDoubleClickZoom();map.addControl(new GLargeMapControl());map.addControl(new GMapTypeControl());map.addControl(new GScaleControl());map.setCenter(start,parseInt(zoom));GEvent.addListener(map,'infowindowclose',function(){$('#store_info_container').html(defaultStoreInfoHtml);});GEvent.addListener(map,'zoomend',function(){$.cookie('zoom',map.getZoom());});GEvent.addListener(map,'dblclick',function(overlay,latlng){updateSearchLocation(latlng);});getStores();refresh();},addLocation:function(e){showLocationAddForm();return false;},refreshMap:function(fromServer){fromServer?refresh():mapLocations();}}}();$(document).ready(function(){jQuery.validator.addMethod("zipcode",function(value,element){return this.optional(element)||/^\d{5}([\-]\d{4})?$/.test(value);},'Please enter a valid zip code.');jQuery.validator.addMethod("notwatermark",function(value,element){return this.optional(element)||$(element).val()!=element.title;},'Please enter a value.');globalUI.init();ajaxHelper.init();loginHelper.init();locationMapper.init();});