//7c95ca23d2ef244945a318c66c6e47f7
var Searchpage=new Class({Extends:Searcher,Implements:[Chain,Options,Events],initialize:function(A){this.page="search";this.current_search="";this.default_sort="recommended";this.parent(A);this.vintage_start_year=1995;this.current_year=new Date().getFullYear();$("vintage-slider").setStyles({visibility:""});this.sliders.vint=new Slider($("vintage-gutter"),$("vintage-slider"),{steps:(2+this.current_year-this.vintage_start_year),onChange:function(B){B=parseInt(B,10);if(B>1){$("vint-disp").set("html","<p>wines from <strong>"+this.vintage_of_slider_position(B)+"</strong></p>")}else{if(B===1){$("vint-disp").set("html","<p><strong>non-vintage</strong> wines</p>")}else{if(this.bypass.vint===0){$("vint-disp").set("html","<p>wines from <strong>any vintage</strong></p>")}}}this.changed()}.bind(this),onComplete:function(B){B=parseInt(B,10);if(this.bypass.vint===0){this.tbt("2",this.vintage_of_slider_position(B))}else{this.bypass.vint=0}}.bind(this)});if(this.options.search_string){this.rm_controls(1);this.set_vintage();this.set_price();this.more_links();this.pagelinks(this.options.page);this.current_search=this.options.search_string;snooth.cookie.last_search=this.current_search;snooth.store_cookie();this.start_state=this.get_state(this.options.search_string,this.options.page)}this.irht=0;this.openslide=null;this.init_sidebar();$("search-filter").addEvent("submit",function(B){this.run($("swstr").value,1);B=new Event(B);B.stop()}.bind(this));this.changed_ready=true},vintage_of_slider_position:function(B){var A=null;B=parseInt(B,10);if(B>1){A=((this.vintage_start_year-2)+B)}else{if(B===1){A="NV"}else{A=""}}return A},slider_position_of_vintage:function(A){return(A-(this.vintage_start_year-2))},init_sidebar:function(){$("all-wines").addEvent("click",function(A){this.tbt("10","")}.bind(this));$$("#refine_search div.opt_choices").each(function(A){var B=A.getProperty("id").match(/^side_(\d+)_select$/);B=B[1];$$("#"+A.getProperty("id")+" li a").each(function(C){C.addEvent("click",function(D){if(C.hasClass("all")){this.tbt(B,"")}else{this.tbt(B,C.get("text"))}D=new Event(D);D.stop()}.bind(this))},this)},this);["lb_mcountry_select","all-wines","sort"].each(function(A){if($(A)){$(A).setEvent("change",this.changed.bind(this))}}.bind(this));if($("loc-zip")){$("loc-zip").removeEvents("focus");$("loc-zip").addEvent("focus",this.changed.bind(this))}if($("swstr")){$("swstr").removeEvents("focus");$("swstr").addEvent("focus",this.changed.bind(this));$("swstr").addEvent("keyenter",function(){this.run($("swstr").value,1)}.bind(this))}$("refine-button").addEvent("click",function(A){A=new Event(A);A.stop();this.run($("swstr").value,1)}.bind(this))},rm_controls:function(D){var B=[],C,A=0;$$("#remove_terms_hidden div.rt").each(function(F){var E=F.getProperty("id").match(/remove_terms_(\d+)/),G;G=(E&&E[1])?parseInt(E[1],10):0;$$("#"+F.getProperty("id")+" div a").each(function(H){if(G===11){H.setEvent("click",function(K){var J=$(G+"_holder").get("text").split(","),I;for(I=0;I<J.length;I+=1){this.rfs(J[I]-I)}this.run($("swstr").value);K=new Event(K);K.stop()}.bind(this))}},this)},this);$$("a.pt").each(function(F){var E=F.getProperty("id").match(/pt_(d|v|p|)([\w\d]+)/);F.addEvent("click",function(I){var H,G;I=new Event(I);I.stop();if(E[1]==="v"){H=$("2_holder").get("text").split(",")}else{if(E[1]==="p"){H=$("8_holder").get("text").split(",")}else{if(E[1]==="d"){H=$("13_holder").get("text").split(",")}else{H=$(E[2]+"_tholder").get("text").split(",")}}}for(G=0;G<H.length;G+=1){this.rfs(H[G]-G)}this.run($("swstr").value)}.bind(this))},this);for(C=0;C<B.length;C+=1){$("side_remove_"+B[C]).empty();if($("remove_terms_"+B[C])){$("remove_terms_"+B[C]).getChildren().injectInside("side_remove_"+B[C]);A+=1}A+=$("side_remove_"+B[C]).offsetHeight}},up_tss:function(A){A=A.clean();if(!A.match(/wine/i)){A+=" wine"}A=A.ucfirst();if($("all-wines").checked){document.title=A+" reviews, ratings, and wine labels"}else{document.title="Buy "+A+" online"}},_last_tbt:{},tbt:function(B,E,A){var D,C;if(_remove_all[B]){A=1;delete _remove_all[B]}if($defined(this._last_tbt[B])){this.remove_from_search(this._last_tbt[B])}this._last_tbt[B]=E;if(!($(B+"_holder"))||$(B+"_holder").get("text")===""){this.add_to_search(E)}else{if((B!==7&&B!==11)||E===""||A){D=$(B+"_holder").get("text").split(",");for(C=0;C<D.length;C+=1){this.rfs(D[C]-C)}}this.add_to_search(E)}},rfs:function(B){var A=$("swstr").value.split(/\s+/);if(A[B]){A.splice(B,1)}$("swstr").value=A.join(" ")},add_to_search:function(C){var A=1,B=String(C)||"";if($("swstr").value!==""){if(B!==""){B+=" "}B+=$("swstr").value}$("swstr").set("value",B.clean())},remove_from_search:function(B){var A=$("swstr").value.replace(B,"");$("swstr").value=A.clean()},set_vintage:function(){var D,B,C,A,E;if($("2_holder")){D=$("2_holder").innerHTML.split(",");B=$("swstr").value.split(" ");if(B[D[0]]){C=0;A=B[D[0]];E=Number(A);if(A.length<4){if(E<20){A="20"+A}else{A="19"+A}E=Number(A)}if(E>=this.vintage_start_year&&E<=this.current_year){C=this.slider_position_of_vintage(E)}else{if(E<this.vintage_start_year||E<=(this.current_year+1)){$("vint-disp").set("html","<p>wines from <strong>"+E+"</strong></p>");C=0}else{if(A.match(/nv/i)){C=1}}}if(this.sliders.vint.step!==C){this.reset_slider(this.sliders.vint,C)}}}else{$("vint-disp").set("html","<p>wines from <strong>any vintage</strong></p>");this.reset_slider(this.sliders.vint,0);this.bypass.vint=0}},set_price:function(){var B,A;if($("8_holder")){B=$("8_holder").get("text").split(",");A=$("swstr").value.split(" ");if(A[B[1]]){this.reset_slider(this.sliders.price,0,(A[B[1]]/2))}}else{if(!this.bypass.price){this.reset_slider(this.sliders.price,$("price_min_holder").get("text"),$("price_max_holder").get("text"))}this.bypass.price=0;this.bypass.slide=0}},start_dedupe:function(A){searchpage.stop_dedupe();alert('You\'ve selected the "loser" of the merge, now click on the wine you\'d like to keep (the "winner")');$("int-tool").dispose();$$("li.result").each(function(B){var C=B.getProperty("id").match(/^wineID\-(\d+)$/);C=C[1];if(C===A){B.setStyle("border","1px solid #3e5d2a");B.setStyle("padding","8px 6px 0 6px");B.addEvent("click",function(D){if(confirm("End dedupe mode?")){searchpage.stop_dedupe()}D=new Event(D);D.stop()})}else{B.addEvents({mouseover:function(){this.setStyles({border:"1px solid #aa385d",padding:"8px 6px 0 6px"})},mouseout:function(){this.setStyles({padding:"9px 7px 0 7px",border:"none","border-bottom":"1px solid #ddd"})},click:function(G){var D=$("wname"+C).get("text"),F=$("wname"+A).get("text"),E;if(confirm("Are you sure you want to merge "+F+" into "+D+"?")){E=new Request({url:snooth.options.site_url+"/dedupe-wines/",onComplete:function(H){alert("Thank you! Those wines have been set to merge. It may take 24 hours for the results to appear on the site."+H);searchpage.stop_dedupe()}});E.post({mwid:C,slvid:A})}G=new Event(G);G.stop()}})}})},stop_dedupe:function(){$$("li.result").each(function(A){A.setStyles({border:"none","border-bottom":"1px solid #ddd",padding:"9px 7px 0 7px"}).removeEvents("mouseover").removeEvents("mouseout").removeEvents("click")})},changed_ready:false,changed:function(){if(this.changed_ready&&!this.did_change){this.did_change=1;$("refine-button").pulsate("#355722","#8ed966",1000)}}});