$(document).ready(function(){(function(n){function u(n,t){var i={data:t};parseInt(t.channel,10)>0&&(i.cateid=parseInt(t.channel,10)),$("#"+n).html(f(i)),$("html,body").animate({scrollTop:0},400)}function t(n,t){var i=e,r;t=t||{},t.page=t.page||1;switch(n){case"index":i=i+"index_"+t.page+".json?guid="+$e.config("guid");break;case"list":i=i+"list/"+t.cid+"_"+t.page+".json?guid="+$e.config("guid");break;case"classes":i=i+"classes.json"}debugtime(i),r=document.createElement("script"),r.type="text/javascript",r.src=i,document.getElementsByTagName("head")[0].appendChild(r)}function r(){var n=document.location.href,t=$e.config("toppage_tab","top_wrap_total"),i=n.search(/\?/g)>-1?n.substring(n.search(/\?/g)+1,n.length):t;return $('*[data-id="'+i+'"]').length==0&&(i=t),$('*[data-id="'+i+'"]').addClass("active"),t}n.classes=null;var i={},f=mzTpl("temp_top"),e=$e.config("SERVERURL")+"json/";n.switchPage={toPage:function(n,r){var u,f;if($("a[data-id=top_wrap_total]").eq(0).hasClass("active")){if(pg=i.index,n==-1&&(n=Math.min(pg.page+1,pg.pageCount)),n==-2&&(n=Math.max(1,pg.page-1)),n==-3&&(n=pg.pageCount),!r&&i.index.page==n)return;t("index",{page:n})}else u=$(".active[data-id^=top_wrap_]").eq(0),pg=i[u.data("cateid")],n==-1&&(n=Math.min(pg.page+1,pg.pageCount)),n==-2&&(n=Math.max(1,pg.page-1)),n==-3&&(n=pg.pageCount),f=u.data("defid"),t("list",{cid:f,page:n})}},n.getClassName=function(n){for(var t=0;t<classes.length;t++)if(classes[t].cid==n)return classes[t].classname},n.getReadUrl=function(n){return $e.config("SERVERURL")+"?do=go&title="+$e.urlencode(n,!0)+"&from=top"},n.getHits=function(n){return n>1e4?Math.round(n/100)/100+"万+":n>1e3?Math.round(n/10)/100+"千+":"少量"},n.__indexCallBack=function(t){n.classes||(n.classes=t.classes),u("top_wrap_total",t)},n.__listCallBack=function(n){u("top_wrap_"+n.channel,n)},n.__classCallBack=function(t){n.classes||(n.classes=t),$("*[data-id="+r()+"]").trigger("click")},n.openSearch=function(n){var t=$(n).attr("title"),i=$(n).data("type");$e.goSearch(t,i,!0)},n.bookUrl=function(n){return"mz://reader/?url="+escape(n)},n.createPageNav=function(n){i[n.channel]=i[n.channel]||new showPages("switchPage");var t=i[n.channel];return t.pageCount=n.pagecount,t.page=n.page,t.createHtml(2)},n.goClassPage=function(n){var r=$(".active[data-id^=top_wrap_]").eq(0),u=$(n),i=u.data("cid");r.data("defid",i),t("list",{cid:i,page:1})},n.browserClass=function(i){for(var u=parseInt($(i).data("cid"),10),f,r=0;r<n.classes.length;r++)if(u==n.classes[r].cid){f=$("a[data-id=top_wrap_"+n.classes[r].category+"]").eq(0),f.data("defid",u),$("#tab_box > .active").removeClass("active"),f.trigger("click"),t("list",{cid:u,page:1});return}},n.errorImg=function(n){n.style.display="none"},r(),$("#tab_box").mzTab({beforeTabClick:function(i){var r=$("a[data-id="+i+"]").eq(0),u;switch(i){case"top_wrap_1":case"top_wrap_2":case"top_wrap_3":case"top_wrap_4":if(!n.classes){t("classes",{});return}default:r.data("init")||(u=r.data("cateid"),cid=r.data("defid"),r.data("init",1),u=="index"?t("index"):t("list",{cid:cid,page:1})),$e.config("toppage_tab",i,!0)}}}),r=="top_wrap_total"&&t("index");$(document).on("keydown",function(t){(function(t){var i=t.target;if(i.tagName.toLowerCase()!="input")switch(t.keyCode){case 39:return n.switchPage.toPage(-1),!1;case 37:return n.switchPage.toPage(-2),!1}})(t)})})(window)})