$j(document).ready( function() {
    $j('#sli_search_1').each(function() {
        window.sliAutocomplete.extend({stubInit:function(){if(!this.opts.target){this.opts.target=["sli_search_1"]}this.select.init(this.opts);this.input.init(this.opts,this.select)},select:{parent:undefined,visible:false,urls:[],opts:{defaults:{width:430},"offset-x":0,"offset-y":0,onsubmit:function(){}},selector:"",selected:null,focus:false,currentSelected:-1,value:undefined,valueStop:"",stopQuery:false,dropdown:undefined,init:function(a){var b=this;var c=document.createElement("ul");c.id="sli_autocomplete";c.className="rich";document.body.appendChild(c);b.dropdown=jQuery(c);b.dropdown.css("z-index",30000);b.dropdown.css("display","none");if(a["offset-x"]){b.opts["offset-x"]=a["offset-x"]}if(a["offset-y"]){b.opts["offset-y"]=a["offset-y"]}if(a.width){b.opts.width=a.width}if(a.onsubmit){b.opts.onsubmit=a.onsubmit}b.parent=jQuery("#"+a.target[0]);b.dropdown.click(b.selectCurrent.slibind(b))},position:function(){var d=this.parent;var h=this.dropdown;var a=d.outerHeight();var g=d.offset();var f=g.left+this.opts["offset-x"];var e=g.top+a+this.opts["offset-y"];h.css("left",f+"px");h.css("top",e+"px");var c=this.opts.defaults.width;if(this.opts.width){if(this.opts.width>c){c=this.opts.width}else{if(this.opts.width=="parent"){var b=d.outerWidth();if(b>c){c=b}}}}h.css("width",c+"px")},moveSelect:function(c){var d=this;var a=d.dropdown.find(d.selector);var b=a.length;if(d.currentSelected>=0){jQuery(a[d.currentSelected]).removeClass("sli_ac_active")}d.currentSelected+=c;if(d.currentSelected<0){d.currentSelected=-1}if(d.currentSelected>=b){d.currentSelected=b-1}if(d.currentSelected>=0&&d.currentSelected<b){jQuery(a[d.currentSelected]).addClass("sli_ac_active")}},next:function(){this.moveSelect(1)},prev:function(){this.moveSelect(-1)},pageDown:function(){this.moveSelect(10)},pageUp:function(){this.moveSelect(-10)},show:function(){this.dropdown.show();this.visible=true},hide:function(){this.dropdown.hide();this.visible=false},selectCurrent:function(){if(this.currentSelected<0){return false}var a={url:this.urls[this.currentSelected]+"&asug="+this.parent.val(),query:this.parent.val()};if(this.opts.onsubmit(a)!==false){document.location=a.url;this.hide()}return true},mouseOver:function(d){var a=this;var b=a.dropdown.find(a.selector);var c=b.length;if(a.currentSelected>=0){jQuery(b[a.currentSelected]).removeClass("sli_ac_active")}b.each(function(e,f){if(f==d){a.currentSelected=e}});if(a.currentSelected<0){a.currentSelected=-1}if(a.currentSelected>=c){a.currentSelected=0}if(a.currentSelected>=0&&a.currentSelected<c){jQuery(b[a.currentSelected]).addClass("sli_ac_active")}},addData:function(a,e,g){var d=this;if(!d.focus){return}d.urls=a;d.selector=g;var h=d.value.split(/\s+/);var c=[];var f=h.length;for(var i=0;i<f;i++){var b=new RegExp("(\\b"+h[i]+")(?=[^>]*<(?!/h2))","gi");c.push(b)}for(r in c){e=e.replace(c[r],"<b>$1</b>")}d.dropdown.html(e);d.dropdown.find(d.selector).mouseover(function(){d.mouseOver(this)});d.currentSelected=-1;d.show();if(d.urls.length<1){d.hide();d.valueStop=d.value;d.stopQuery=true}else{d.valueStop="";d.stopQuery=false}},doRequest:function(b){var a=this.valueStop;if(b==this.value){if(this.urls.length>0){this.show()}return false}if(this.stopQuery){if(b.length>a.length&&b.substr(0,a.length)==a){return false}}return true}},input:{lastKeyPressCode:undefined,hasFocus:undefined,timeout:null,ajax:null,select:undefined,opts:{delay:200,base:"",target:[],params:"/search?ts=rac&w="},KEY:{UP:38,DOWN:40,DEL:46,TAB:9,RETURN:13,ESC:27,PAGEUP:33,PAGEDOWN:34,BACKSPACE:8},init:function(c,a){var d=this;d.select=a;if(c.delay){d.opts.delay=c.delay}if(c.params){d.opts.params=c.params}if(c.base){d.opts.base=c.base.replace(/\/+$/,"")+d.opts.params}if(c.target){d.opts.target=c.target}var b=jQuery("#"+c.target[0]);b.bind((jQuery.browser.opera?"keypress":"keydown"),d.keyChange.slibind(d)).blur(function(){setTimeout(d.onBlur.slibind(d),d.opts.delay+50)}).focus(function(){d.select.focus=true;d.select.position()});d.select.position()},onChange:function(){var a=jQuery("#"+this.opts.target[0]);var b=a[0].value;b=b.replace(/^\s\s*/,"").replace(/\s\s*$/,"");if(!this.select.doRequest(b)){return}if(this.ajax!=null){this.ajax.abort()}this.select.value=b;if(b.length==0){this.select.hide()}else{b=encodeURIComponent(b);this.ajax=jQuery.ajax({url:this.opts.base+b,dataType:"script",cache:true})}},onBlur:function(){this.select.focus=false;this.select.hide()},keyChange:function(a){this.hasFocus=1;this.lastKeyPressCode=a.keyCode;switch(a.keyCode){case this.KEY.UP:a.preventDefault();if(this.select.visible){this.select.prev()}else{this.onChange(0,true)}break;case this.KEY.DOWN:a.preventDefault();if(this.select.visible){this.select.next()}else{this.onChange(0,true)}break;case this.KEY.PAGEUP:a.preventDefault();if(this.select.visible){this.select.pageUp()}else{this.onChange(0,true)}break;case this.KEY.PAGEDOWN:a.preventDefault();if(this.select.visible){this.select.pageDown()}else{this.onChange(0,true)}break;case this.KEY.TAB:case this.KEY.RETURN:if(this.select.selectCurrent()){a.preventDefault();blockSubmit=true;return false}break;case this.KEY.ESC:this.select.hide();break;default:clearTimeout(this.timeout);this.timeout=setTimeout(this.onChange.slibind(this),this.opts.delay);break}}}});window.sliAutocomplete.stubInit();
    });
});

