
(function($){$.suggest_ns={};$.fn.suggest=function(config){var defaultConfig={container:$('#suggest'),url:$('#url')};this._num=-1;this._suggestUrl='http://so.1616.net/qsearch/?n=0,7&ns=$.suggest_ns.';this.CONFIG=$.extend(defaultConfig,config);var _self=this,container=this.CONFIG.container,url=this.CONFIG.url;this.init=function(){$(_self).focus().keyup(function(e){_self._suggest(e,$(this));}).blur(function(){setTimeout(function(){container.hide();_self._num=-1;},200);});};this._suggest=function(e,$input){var key=e.keyCode,dd=container.find('>dd');if(!$.trim($input.val()))container.hide();if(key!=38&&key!=40&&key!=13){$.getScript(_self._suggestUrl+"&q="+encodeURIComponent($input.val()),function(){_self._num=-1;});}else{if(key!=13){key==38&&_self._num--;key==40&&_self._num++;if(_self._num<0)_self._num=dd.length-1;if(_self._num>dd.length-1)_self._num=0;highlight(_self._num)}else{dd.eq(_self._num).click();}}
function highlight(num){dd.css({background:"#ECF5FF"});dd.eq(num).css({background:"#88C4FF"});}};$.suggest_ns.qsearch_cb=function(data){if(data.length==1){container.hide();this._num=-1;return;}
var _this=this,$input=$(_self),$url=url,val=$input.val(),v0=data[0].split('|')[0];if(!v0||v0!=val)return;var htm=[];$.each(data,function(i,v){if(i==0)return;var str=v[3];redstr=str.slice(v[0],v[1]+1);str=str.replace(redstr,"<b style='color:red; margin:0;'>"+redstr+"</b>")
htm[htm.length]="<dd style='"
+"' index='"
+(i-1)
+"'><a rec='"
+v[4]
+"'>"
+str
+"</a></dd>";});$("#suggest").html(htm.join("")).show().css({position:'absolute',zIndex:'500',left:$input.offset().left,top:$input.offset().top+$input.outerHeight(),width:$input.innerWidth()}).find("dd").mouseover(function(){container.find('>dd').css({background:"#ECF5FF"});$(this).css({background:"#88C4FF"});_this._num=$(this).attr("index");}).click(function(){$input.val($(this).find("a").text());$url.val($(this).find("a").attr("rec"));container.hide();_this._num=-1;})};this.init();}})(jQuery);