(function(a){a.suggest=function(r,t){var p=a(r).attr("autocomplete","off");var s;var q=false;var m=0;var d=[];var l=0;if(a.trim(p.val())==""||a.trim(p.val())=="\u4e2d\u6587/\u62fc\u97f3"){p.val("\u4e2d\u6587/\u62fc\u97f3").css("color","#3f7896")}if(!t.attachObject){t.attachObject=a(document.createElement("ul")).appendTo("body")}s=a(t.attachObject);s.addClass(t.resultsClass);n();a(window).load(n).resize(n);p.blur(function(){setTimeout(function(){s.hide()},200)});p.focus(function(){if(a.trim(a(this).val())=="\u4e2d\u6587/\u62fc\u97f3"){a(this).val("").css("color","#3f7896")}if(a.trim(a(this).val())==""){j("")}});p.click(function(){var e=a.trim(a(this).val());j(e);a(this).select()});try{s.bgiframe()}catch(o){}p.keyup(f);function n(){var e=p.offset();s.css({top:(e.top+r.offsetHeight)+"px",left:e.left+"px"})}function f(u){if((/27$|38$|40$/.test(u.keyCode)&&s.is(":visible"))||(/^13$|^9$/.test(u.keyCode)&&c())){if(u.preventDefault){u.preventDefault()}if(u.stopPropagation){u.stopPropagation()}u.cancelBubble=true;u.returnValue=false;switch(u.keyCode){case 38:g();break;case 40:i();break;case 13:b();break;case 27:s.hide();break}}else{if(p.val().length!=m){if(q){clearTimeout(q)}q=setTimeout(k,t.delay);m=p.val().length}}}function k(){var e=a.trim(p.val());j(e)}function j(e){var v="";if(e==""||e=="\u4e2d\u6587/\u62fc\u97f3"){for(h in t.hot_list){if(t.hot_list[h][0]!=null){v+='<li rel="'+t.hot_list[h][0]+'"><a href="#'+h+'"><span>'+t.hot_list[h][2]+"</span>"+t.hot_list[h][1]+"</a></li>"}}v='<div class="gray ac_result_tip">\u8bf7\u8f93\u5165\u4e2d\u6587/\u62fc\u97f3\u6216\u2191 \u2193\u9009\u62e9.</div><ul>'+v+"</ul>"}else{for(var u=0;u<t.source.length;u++){var w=new RegExp("^"+e+".*$","im");if(w.test(t.source[u][0])||w.test(t.source[u][1])||w.test(t.source[u][2])||w.test(t.source[u][3])){v+='<li rel="'+t.source[u][0]+'"><a href="#'+u+'"><span>'+t.source[u][2]+"</span>"+t.source[u][1]+"</a></li>"}}if(v==""){suggest_tip='<div class="gray ac_result_tip">\u5bf9\u4e0d\u8d77\uff0c\u627e\u4e0d\u5230\uff1a'+e+"</div>"}else{suggest_tip='<div class="gray ac_result_tip">'+e+"\uff0c\u6309\u62fc\u97f3\u6392\u5e8f</div>"}v=suggest_tip+"<ul>"+v+"</ul>"}s.html(v).show();s.children("ul").children("li:first-child").addClass(t.selectClass);s.children("ul").children("li").mouseover(function(){s.children("ul").children("li").removeClass(t.selectClass);a(this).addClass(t.selectClass)}).click(function(x){x.preventDefault();x.stopPropagation();b()})}function c(){if(!s.is(":visible")){return false}var e=s.children("ul").children("li."+t.selectClass);if(!e.length){e=false}return e}function b(){$currentResult=c();if($currentResult){p.val($currentResult.children("a").html().replace(/<span.+?<\/span>/i,""));s.hide();if(a(t.dataContainer)){a(t.dataContainer).val($currentResult.attr("rel"))}if(t.onSelect){t.onSelect.apply(p[0])}}}function i(){$currentResult=c();if($currentResult){$currentResult.removeClass(t.selectClass).next().addClass(t.selectClass)}else{s.children("ul").children("li:first-child").addClass(t.selectClass)}}function g(){$currentResult=c();if($currentResult){$currentResult.removeClass(t.selectClass).prev().addClass(t.selectClass)}else{s.children("ul").children("li:last-child").addClass(t.selectClass)}}};a.fn.suggest=function(c,b){if(!c){return}b=b||{};b.source=c;b.hot_list=b.hot_list||[];b.delay=b.delay||0;b.resultsClass=b.resultsClass||"ac_results";b.selectClass=b.selectClass||"ac_over";b.matchClass=b.matchClass||"ac_match";b.minchars=b.minchars||1;b.delimiter=b.delimiter||"\n";b.onSelect=b.onSelect||false;b.dataDelimiter=b.dataDelimiter||"\t";b.dataContainer=b.dataContainer||"#SuggestResult";b.attachObject=b.attachObject||null;this.each(function(){new a.suggest(this,b)});return this}})(jQuery);

