(function(n){var i=Math.max(parseInt(external.config("CPU"),10)*3-1,6),t;n.openBook=function(t){n.searchApp.open(t)},n.openReader=function(n){external.tabopen($(n).data("url"))},n.bookUrl=function(n){return"mz://reader/?url="+escape(n)},n.authorUrl=function(n){return"mz://search/?key="+escape(n)+"&t=author"},n.searchUrl=function(n,t){return"mz://search/?key="+escape(n)+(t?"&"+t:"")},n.searchApp=new function(){function s(n,i){var r=$(n);return r.attr("title",i).cluetip({cluetipClass:"jtip",width:"400px",sticky:!0,local:!0,showTitle:!0,dropShadow:!1,arrows:!0,mouseOutClose:!0,closePosition:"title",closeText:"X",titleAttribute:"title",onActivate:function(){var n;return(n=r.data("tip"))||(n="",t.getChapter(r.attr("title"),function(t){n+=e(t)}),r.data("tip",n)),$("#siteList").html(n),!0}})}var u=this,t,r,f=n.mzTpl("tpl_search_li"),e=n.mzTpl("tpl_search_pop"),o=n.mzTpl("tpl_search_site");return u.open=function(n){var t,i,r;n&&(r=$(n),t||(t=r.data("url")),i||(i=r.data("title"))),$e.tabopen("mz://reader/?url="+escape(t)+"&title="+escape(i))},this.run=function(u,e,h){var a=config("showResultNum",50),c=0,l=$("#bookList"),v=(new Date).getTime(),y,p;if(l.length<1){for(l=$('<div id="bookList"><\/div>').appendTo($("#search_table"));c<a;)l.append($('<ul id="bookLine'+ ++c+'"><\/ul>').hide());c=0}t=new searchModule({onShowRecord:function(n,t,i,r){var u=t.title,e;return t.showTitle=(r?u.replace(r,"<em>"+r+"<\/em>"):u).sub(12,"..."),t.showChapter=t.num==-1?t.chapter:"第"+t.num+"章",e=s(o({num:i}),u),$("#bookLine"+ ++c).html(f(t)).appendTo(l).show().find(".c1").append(e),c>=a?!0:!1},onBeforeShowResult:function(){c=0,v=(new Date).getTime()},onAfterShowResult:function(){for($("#search_list_tab").html($("#search_list_tab").data("text")+"("+c+")");c<a;)$("#bookLine"+ ++c).hide();debugtime("showOnce:"+((new Date).getTime()-v))}}),r=new searchThread(u,e,{searchSites:h?h.split("|"):[],thread:i,onGetResult:function(n,i){for(var u=n,r;r=i[--u];)t.addResult(r)},onOver:function(n){$(".search_list_tip").text("搜索完毕，所有搜索结果都是自动筛选最新章节和匹配最快速度的网站.").removeClass("tip_loading"),__log("search",e+(h?"_"+h.split("|").length:""),u,n)},onSiteStart:function(n){t.addSite(n)},onSiteOver:function(){}}),r.start(),y=n.mzTpl("tpl_key"),extraThread=$e.run({_name:"search_extra",_file:"search_extra.dst",key:u,_runecho:function(n,t){if(t.search(":")==0){if(t=t.substring(1),t.toLowerCase()==u.toLowerCase())return;$("#hot_key").append(y({key:t,color:getRandomColor()}))}},_runover:function(){$.trim($("#hot_key").text())!==""&&$("#hot_key").prepend("<span>相关作品：<\/span>").show()}}),p=n.mzTpl("tpl_search_txt"),extraThread=$e.run({_name:"search_txt",_file:"search_txt.dst",key:u,action:"search",_runecho:function(n,t){var i=t.substring(1).split(/\|\|/ig),r;if(t.search(/:/g)!=0){debugtime(t);return}r={url:i[0],title:i[1],size:i[2],md5:$e.md5(i[0]),author:"",type:""},i.length>3&&(r.author=i[3],r.type=i[4]),$("#search_txt ul").append(p(r))},_runover:function(){var n=$("#search_txt li").length;$("#search_txt_tab").html($("#search_txt_tab").html()+"("+n+")"),$(".search_txt_tip").html(n>0?'点击文件，魔爪为您下载并自动阅读(文件越大,作品完整度越高)，阅读后您可以在<a href="javascript:void" _click="tabopen" data-url="mz://shelf/?shelf_local">离线作品<\/a>中找到。':"魔爪没有搜索到相关的txt文件,请换其它的关键词再搜索试试？").removeClass("tip_loading")}})},this.stop=function(){r.stop()},this},n.searchApp.run($GET.key,$GET.t,$GET.site),n.stopSearch=function(){n.searchApp.stop()},t=[],n._openTxt=function(n){var r=$(n).data("url"),e=$(n).data("title"),u=$(n).data("md5"),i=$("#txt_"+u).addClass("loading"),f="download_txt_"+u;if(_.find(t,function(n){return n.threadName==f?($e.stop(n.tid),!0):!1}))return!1;i.find("i").html("下载中,再次点击停止下载..."),__log("search","txt_downstart",r,e),t.push({threadName:f,tid:$e.run({_name:f,_file:"search_txt.dst",url:r,md5:u,title:e,action:"download",_runecho:function(n,t){t.search(/error:/i)>-1&&i.find("i").html('<font color="red">'+t.substring(6)+"<\/font>")},_showspeed:function(n,t,r){debugtime(t),i.find("i").html(t+(r>-1?"&nbsp;&nbsp;&nbsp;"+r+"%":""))},_runover2:function(n,u,f,e){if(t=_.filter(t,function(t){return t.tid!=n}),i.removeClass("loading"),u){i.find("i").html("暂停下载."),__log("search","txt_downstop",r);return}if(f){i.find("i").html("下载成功，正在导入.");function o(n){var t=$e.importBook(n,e),u;t?($e.tabopen("mz://reader/?url="+t,{checkExists:!0}),i.find("i").html("下载成功，导入成功."),$e.deleteFile(n),__log("search","txt_downsucc",r)):(u=$('<font class="pointer" >导入失败，点击重试<\/font>').on("click",function(){o(n)}).attr("title",n),i.find("i").html("").append(u),__log("search","txt_importfail",r))}o(f)}else __log("search","txt_downfail",r)}})})},$("#tab_box").mzTab({beforeTabClick:function(n){switch(n){case"search_online":$("#search_online_iframe").length==0&&$("#search_online").append('<iframe id="search_online_iframe" frameborder="0" height="200" width="98%" src="'+$e.config("serverurl")+"?do=search&action=list&key="+$e.urlencode($GET.key,!0)+"&type="+$GET.t+'"><\/iframe>')}}})})(window,document)