(function($){AjaxSolr.AutocompleteWidget=AjaxSolr.AbstractSpellcheckWidget.extend({beforeRequest:function(){multiWordRE=new RegExp("^(:?(.* |))([^ ]+)$","g");matches=multiWordRE.exec($.trim($("#edit-search-theme-form-1").val()));this.manager.store.remove('facet.prefix');this.manager.store.remove('spellcheck.q');this.manager.store.remove('spellcheck');this.manager.store.remove('q');if(matches[1]==''){this.manager.store.addByValue('spellcheck',false);this.manager.store.addByValue('spellcheck.q','');this.manager.store.addByValue('facet.prefix',$.trim($("#edit-search-theme-form-1").val().toLowerCase()));}else{this.manager.store.addByValue('spellcheck',false);this.manager.store.addByValue('q',matches[1].toLowerCase());this.manager.store.addByValue('facet.prefix',matches[3].toLowerCase());}
if($('.domain-2').length)this.manager.store.addByValue('fq',"type:news_story");},afterRequest:function(){punctuation=new RegExp("[\/'\\,\\.\\(\\)<>]","g");htmlString="";if(this.manager.response.facet_counts&&$("#edit-search-theme-form-1").val()!=''){cnt=0;add_cnt=0;for(suggestion in this.manager.response.facet_counts.facet_fields.spell){if(cnt%2==0&&!this.manager.response.facet_counts.facet_fields.spell[suggestion].match(punctuation)){htmlString+='<div class="apachesolr_autocomplete suggestion_container';if(cnt==0){searchTerm=this.manager.response.facet_counts.facet_fields.spell[suggestion];if(this.manager.response.responseHeader.params.q)searchTerm=this.manager.response.responseHeader.params.q+searchTerm;oyez_instant_initate(searchTerm);}
htmlString+='"><div class="apachesolr_autocomplete suggestion">';highlightSuggestion='';if(this.manager.response.responseHeader.params.q){highlightSuggestion="<strong>"+this.manager.response.responseHeader.params.q;highlightSuggestion+=this.manager.response.facet_counts.facet_fields.spell[suggestion].replace(this.manager.response.responseHeader.params["facet.prefix"],this.manager.response.responseHeader.params["facet.prefix"]+"</strong>");}else{highlightSuggestion=this.manager.response.facet_counts.facet_fields.spell[suggestion].replace(this.manager.response.responseHeader.params["facet.prefix"],"<strong>"+this.manager.response.responseHeader.params["facet.prefix"]+"</strong>");}
htmlString+=highlightSuggestion+'</div><br style="clear: both;"></div>';add_cnt++;}else{}
cnt++;if(add_cnt>5)break;}}
if(this.manager.response.spellcheck&&this.manager.response.spellcheck.suggestions&&this.manager.response.spellcheck.suggestions.length){htmlString+='<div class="apachesolr_autocomplete suggestion_container">Did you mean: '+this.manager.response.spellcheck.suggestions[1].suggestion[0]+'</div>';}
if(htmlString!=''){$('#oyez_apachesolr_autocomplete').html(htmlString);}else{$('#oyez_apachesolr_autocomplete').html('No suggestions');}
$('#search-theme-form .suggestion_container:first-child').addClass('highlighted');$('#search-theme-form .suggestion_container').mouseover(function(){$('#search-theme-form .suggestion_container').not(this).removeClass('highlighted');$(this).addClass('highlighted');}).click(function(){$('#search-theme-form').submit();});}});})(jQuery);
