!function(window,$){var Config=window.YF_BROWSER.config,Base=window.YF_BROWSER.base,Controllers=(window.Common,window.YF_BROWSER.controllers),URLS=(Controllers.menuTree,{DEL_CHASE:"http://www.yunfan.com/api/cli/yfedelchase.php",CHASE_CLOUD:"http://www.yunfan.com/api/cli/chasecloud.php",ADD_CHASE:"http://www.yunfan.com/api/cli/yfechaseadd.php",UPLOAD_CHASE:"http://www.yunfan.com/api/cli/yfechasemove.php"}),zhuiPian={zhuiPianRender:!1,tipTimeOut:null,init:function(){this.uploadZhuiPian(),this.onEvents()},onEvents:function(){var _me=this,$navtree=$("#zhuipian");$navtree.on("click",".remove_zhuipian",function(e){e.stopPropagation();var _data,_src=$(this).parent().siblings(".jstree-title").data("src"),_classid=Base.getAttr(_src,"classid"),_docid=Base.getAttr(_src,"docid");_data={"class":_classid,docid:_docid},debug(_data),_me.removeZhuiPian(_data),$(this).parent().parent().remove()}),$navtree.on("click",".jstree-wholerow",function(){var _src=$(this).siblings(".jstree-title").data("src"),_docid=Base.getAttr(_src,"docid"),_num=(Base.getAttr(_src,"classid"),Base.getAttr(_src,"playlink"),Base.getAttr(_src,"num")),_query=(Base.getAttr(_src,"total"),{docid:_docid}),tips=Base.getAttr(_src,"tips"),_data={docid:_docid,num:_num};debug(_data),tips>0&&_me.updateZhuiPian(_query,_data)}),Controllers.menuTree.oldPlayEvents($navtree)},ajaxZhuiPian:function(data){for(var _me=this,result=data.reverse(),_arr=[],i=0,len=result.length;len>i;i++){var item=result[i],elem={docid:item.docid,"class":item["class"]};_arr.push(elem)}var _data={url:Config.URLS.ZHUIPIAN+"?uid="+Base.getBrowserUid(),params:"&chasedata="+JSON.stringify(_arr),tpl:$("#zhuipian")},callback=function(data,$tpl){_me.zhuiPianRender=!0,$("#menu-tree").trigger("click"),data.length>0&&_me.renderZpTpl(data,$tpl)};Base.getJsonP(_data,callback)},getChaseFromColud:function(){var self=this;$.getJSON(URLS.CHASE_CLOUD+"?callback=?&uid="+Base.getBrowserUid()+"&num=10",function(json){var data=json.data;self.zhuiPianRender=!0,$("#menu-tree").trigger("click"),data.length>0&&(self.setChaseData(data),self.renderZpTpl(data,$("#zhuipian")))})},setChaseData:function(data){var rs=Plugins.Storage.get(CHASE_STORAGE);rs=rs?rs:[];for(var i=0,len=data.length;len>i;i++){for(var inIt=!1,n=0,l=rs.length;l>n;n++)rs[n].docid==data[i].docid&&(inIt=!0);if(!inIt){var _data={docid:data[i].docid,num:data[i].num};Plugins.Storage.append(CHASE_STORAGE,_data,100)}}},removeZhuiPian:function(data){var tempCount=0,delChaseFn=function(){return tempCount>2?!1:(tempCount++,void $.getJSON(URLS.DEL_CHASE+"?callback=?&uid="+Base.getBrowserUid()+"&docid="+data.docid,function(json){json.result||setTimeout(delChaseFn,1e4)}))};delChaseFn()},renderZpTpl:function(data,$tpl){var _html=Base.getTpl(data,'<span style="color:#54B64F;">[追剧]&nbsp;</span>',!0);$tpl.html(_html)},addZhuiPian:function(data){var tempCount=0,addChaseFn=function(){return tempCount>2?!1:(tempCount++,void $.getJSON(URLS.ADD_CHASE+"?callback=?&uid="+Base.getBrowserUid()+"&docid="+data.docid+"&classid="+data.classid+"&num="+data.num,function(json){json.result||setTimeout(addChaseFn,1e4)}))};addChaseFn()},uploadZhuiPian:function(){var rs=Plugins.Storage.get(ZHUIPIAN_STORAGE);if(rs){for(var data=rs,_arr=[],tempCount=0,i=0,l=data.length;l>i;i++)_arr.push({"class":data[i]["class"],docid:data[i].docid});var str=JSON.stringify(_arr),uploadChaseFn=function(){return tempCount>2?!1:(tempCount++,void $.getJSON(URLS.UPLOAD_CHASE+"?callback=?&uid="+Base.getBrowserUid()+"&chasedata="+str,function(json){json.result?Plugins.Storage.remove(ZHUIPIAN_STORAGE):setTimeout(uploadChaseFn,1e4)}))};uploadChaseFn(),this.ajaxZhuiPian(data)}else this.getChaseFromColud()},updateZhuiPian:function(_query,data){var result=Plugins.Storage.get(CHASE_STORAGE);if(result&&$.isArray(result)){for(var i=0,len=result.length;len>i;i++){var item=result[i];if(item.docid==_query.docid){result.splice(i,1,data);break}}Plugins.Storage.set(CHASE_STORAGE,result)}}};window.YF_BROWSER.controllers.zhuiPian=zhuiPian}(window,$);