//b68426cdc649ae8df504f3a6ec5f7e2b
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.sliders.vint=new Slider($("vintage-gutter"),$("vintage-slider"),{steps:16,onChange:function(B){if(B>1){$("vint-disp").set("html","<p>wines from <strong>"+(B+1993)+"</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){if(this.bypass.vint==0){if(B>1){this.tbt("2",Number(B)+1993)}else{if(B==1){this.tbt("2","NV")}else{this.tbt("2","")}}}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();$("srun").addEvent("click",function(B){this.run($("sstr").value,1);new Event(B).stop()}.bind(this));$("sform").addEvent("submit",function(B){this.run($("sstr").value,1);new Event(B).stop()}.bind(this));$("search-filter").addEvent("submit",function(B){this.run($("sstr").value,1);new Event(B).stop()}.bind(this));if($("partner-search-help")){$("partner-search-help").removeEvents("click");$("partner-search-help").addEvent("click",function(){show_generic_bubble("Help &rsaquo; Partner Search","If these boxes are checked when you perform a search on Snooth, we'll include results from WineZap.com and Wine-Searcher.com to your search.  Those websites will open in new windows behind this window")})}this.changed_ready=true},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("other")){this.use_search_box(B)}else{if(C.hasClass("all")){this.tbt(B,"")}else{this.tbt(B,C.get("text"))}}new Event(D).stop()}.bind(this))},this)},this);["ps_zap","ps_ws","lb_mcountry_select","all-wines","sort"].each(function(A){if($(A)){$(A).removeEvents("change");$(A).addEvent("change",this.changed.bind(this))}}.bind(this));if($("loc-zip")){$("loc-zip").removeEvents("focus");$("loc-zip").addEvent("focus",this.changed.bind(this))}$("refine-button").addEvent("click",function(A){new Event(A).stop();this.run($("sstr").value,1)}.bind(this))},transition:function(A){if(A==1){ztop_vis(0);grayOut(true,{opacity:"50"});$("loader").setStyle("top",Math.round(window.getHeight()/2-225));$("loader").setStyle("left",Math.round(window.getWidth()/2-175));$("loader").setStyle("display","block");$("result-set").get("tween",{property:"opacity",link:"chain",duration:400}).start(0).chain(function(){$("result-set").setStyle("visibility","hidden");this.callChain()}.bind(this))}else{ztop_vis(1);$("recap-block").set("html",$("recap-block-replacement").innerHTML);$("loader").setStyle("display","none");grayOut(false,{opacity:"50"});$("result-set").setStyle("visibility","visible");$("result-set").get("tween",{property:"opacity",link:"chain",duration:400}).start(1).chain(function(){this.callChain()}.bind(this))}return this},full_slide:function(A){if(A!=null){if(this.openslide!=null){this.openslide.toggle();this.openslide=null}if(A.wrapper.offsetHeight==0||A.wrapper.offsetWidth==0){A.element.setStyle("display","block");this.sliders.refine.start([this.sliders.refine.element.getStyle(this.sliders.refine.margin).toInt(),this.sliders.refine.wrapper.getStyle(this.sliders.refine.layout).toInt()],[0,A.offset+this.sliders.refine.offset+rcht-this.irht]);this.openslide=A}else{this.sliders.refine.start([this.sliders.refine.element.getStyle(this.sliders.refine.margin).toInt(),this.sliders.refine.wrapper.getStyle(this.sliders.refine.layout).toInt()],[0,this.sliders.refine.offset+rcht-this.irht]).chain(function(){A.element.setStyle("display","none")})}A.toggle()}},rm_controls:function(B){var A=new Array();rcht=0;$$("#remove_terms_hidden div.rt").each(function(D){var C=D.getProperty("id").match(/remove_terms_(\d+)/);$$("#"+D.getProperty("id")+" div a").each(function(E){if(C[1]!=11){E.removeEvents("click");E.addEvent("click",function(G){var F=$(C[1]+"_holder").get("text").split(",");for(i=0;i<F.length;i++){this.rfs(F[i]-i)}this.run($("sstr").value);G=new Event(G).stop()}.bind(this))}},this)},this);$$("a.pt").each(function(D){var C=D.getProperty("id").match(/pt_(d|v|p|)([\w\d]+)/);D.addEvent("click",function(F){if(C[1]=="v"){var E=$("2_holder").get("text").split(",")}else{if(C[1]=="p"){var E=$("8_holder").get("text").split(",")}else{if(C[1]=="d"){var E=$("13_holder").get("text").split(",")}else{var E=$(C[2]+"_tholder").get("text").split(",")}}}for(i=0;i<E.length;i++){this.rfs(E[i]-i)}this.run($("sstr").value);F=new Event(F).stop()}.bind(this))},this);for(i=0;i<A.length;i++){$("side_remove_"+A[i]).empty();if($("remove_terms_"+A[i])!=null){$("remove_terms_"+A[i]).getChildren().injectInside("side_remove_"+A[i]);rcht+=1}rcht+=$("side_remove_"+A[i]).offsetHeight}},up_tss:function(A){A=trim(A);if(A.indexOf("wine")==-1&&A.indexOf("Wine")==-1){A=A+" wine"}A=A.substr(0,1).toUpperCase()+A.substr(1,A.length);if($("all-wines").checked){document.title=A+" reviews, ratings, and wine labels"}else{document.title="Buy "+A+" online"}},_last_tbt:{},tbt:function(B,D,A){if(_remove_all[B]!=null){A=1;delete _remove_all[B]}if($defined(this._last_tbt[B])){this.remove_from_search(this._last_tbt[B])}this._last_tbt[B]=D;if($(B+"_holder")==null||$(B+"_holder").get("text")==""){this.add_to_search(D)}else{if((B!=7&&B!=11)||D==""||A!=null){var C=$(B+"_holder").get("text").split(",");for(i=0;i<C.length;i++){this.rfs(C[i]-i)}}this.add_to_search(D)}},get_slider:function(A){if(A==4){return this.sliders.type}if(A==5){return this.sliders.varietal}if(A==6){return this.sliders.region}if(A==7){return this.sliders.tags}return null},rfs:function(B){var A=$("sstr").value.split(" ");if(A[B]!=null){A.splice(B,1)}$("sstr").value=A.join(" ")},add_to_search:function(C){var A=1;var B=C;if(!B){B=""}if($("sstr").value!=""){if(B!=""){B+=" "}B+=$("sstr").value}$("sstr").value=B.clean()},remove_from_search:function(B){var A=$("sstr").value.replace(B,"");$("sstr").value=A.clean()},set_vintage:function(){if($("2_holder")!=null){var D=$("2_holder").innerHTML.split(",");var B=$("sstr").value.split(" ");if(B[D[0]]!=null){var C=0;var A=B[D[0]];var E=Number(A);if(A.length<4){if(E<20){A="20"+A}else{A="19"+A}E=Number(A)}if(E>=1995&&E<2010){C=E-1993}else{if(E<1995||E>=2010){$("vint-disp").set("html","<p>wines from <strong>"+E+"</strong></p>");C=0}else{if(E!=0){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(){if($("8_holder")!=null){var B=$("8_holder").get("text").split(",");var A=$("sstr").value.split(" ");if(A[B[1]]!=null){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}},use_search_box:function(A){this.winscroll.toTop();$("sstr").value=trim($("sstr").value)+" ";$("sstr").focus();if(this.fx.sbhl==null){this.fx.sbhl=new Fx.Morph("sstr",{duration:2000,transition:"quad:out"})}this.fx.sbhl.start({"background-color":["#aa385d","#ffffff"],color:["#000000","#aa385d"]})},more_links:function(){if($("groups-help")){$("groups-help").removeEvents("click");$("groups-help").addEvent("click",function(A){show_bubble("group-help");new Event(A).stop()})}},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.stop()})}else{B.addEvents({mouseover:function(){this.setStyle("border","1px solid #aa385d");this.setStyle("padding","8px 6px 0 6px")},mouseout:function(){this.setStyle("border","none");this.setStyle("border-bottom","1px solid #ddd");this.setStyle("padding","9px 7px 0 7px")},click:function(F){var D=$("wname"+C).get("text");var E=$("wname"+A).get("text");if(confirm("Are you sure you want to merge "+E+" into "+D+"?")){new Request({url:snooth.options.site_url+"/dedupe-wines/",onComplete:function(G){alert("Thank you! Those wines have been set to merge. It may take 24 hours for the results to appear on the site."+G);searchpage.stop_dedupe()}}).post({mwid:C,slvid:A})}F.stop()}})}})},stop_dedupe:function(A){$$("li.result").each(function(B){B.setStyle("border","none");B.setStyle("border-bottom","1px solid #ddd");B.setStyle("padding","9px 7px 0 7px");B.removeEvents("mouseover");B.removeEvents("mouseout");B.removeEvents("click")})},changed_ready:false,changed:function(){if(!this.changed_ready){return }if(this.did_change){return }this.did_change=1;$("refine-button").pulsate("#355722","#8ed966",1000)}});