$host='http://client.pc.letv.com';
if(typeof Base=='undefined'){window.Base={}}
(function(){var topics={},caches={},observer,cache;observer=function(id){var callbacks,topic=id&&topics[id];if(!topic){callbacks=$.Callbacks();topic={publish:callbacks.fire,subscribe:callbacks.add,unsubscribe:callbacks.remove};if(id){topics[id]=topic}}return topic};cache=function(id){var cacheObj=id&&caches[id];if(!cacheObj){var os=Base.observer(id);var _value=null;cacheObj={set:function(value){_value=value;os.publish(value)},get:function(){return _value},subscribe:os.subscribe,unsubscribe:os.unsubscribe};if(id){caches[id]=cacheObj}}return cacheObj};Base.observer=observer;Base.cache=cache})();
(function(){window.pcEvent=function(type,param){if(!type)return;Base.observer('pcEvent-'+type).publish(param)};var isPc=false;try{window.external.jsToPc('js:checkIsPc');isPc=true}catch(e){isPc=false}Base.CustomEvent={resize:function(handle){if(isPc){Base.observer('pcEvent-resize').subscribe(handle)}else{$(window).resize(handle)}},wndModeSwitch:function(handle){Base.observer('pcEvent-wndModeSwitch').subscribe(handle)},minimize:function(handle){Base.observer('pcEvent-minimize').subscribe(handle)},unbind:function(type,handle){switch(type){case'resize':if(isPc){Base.observer('pcEvent-resize').unsubscribe(handle)}else{$(window).unbind('resize',handle)}break;case'minimize':Base.observer('pcEvent-minimize').unsubscribe(handle)}}}})();
(function(){Base.CustomEvent.resize(dyCss)})();
(function(){var Json={toStr:function(obj){switch(typeof(obj)){case'string':return'"'+obj.replace(/(["\\])/g,'\\$1')+'"';case'array':return'['+obj.map(arguments.callee).join(',')+']';case'object':if(obj instanceof Array){var strArr=[];var len=obj.length;for(var i=0;i<len;i++){strArr.push(arguments.callee(obj[i]))}return'['+strArr.join(',')+']'}else if(obj==null){return'null'}else{var string=[];for(var property in obj)string.push(arguments.callee(property)+':'+arguments.callee(obj[property]));return'{'+string.join(',')+'}'}case'number':return obj;case false:return obj;case undefined:return''}},toJson:function(str){return eval('('+str+')')}};Base.Json=Json})();
(function(){var handles={};window.pcToJs=function(){var param=Base.Json.toJson(arguments[1]);var handle=handles[param.to];if(!handle)return;for(var i=0,len=handle.length;i<len;i++){handle[i](param)}};window.addPcListener=function(type,handle){if(typeof handle!='function')return;if(!handles[type]){handles[type]=[]}handles[type].push(handle)};var pcInterface=function(type,setting){type=type||'';setting=setting||{};var param;switch(type){case'playVideo':param={to:'player',cmd:'play',vsource:'letv',url:$host+'/play/'+setting.vid+(setting.htime?'?htime='+setting.htime:''),follow:''};break;case'saveHistory':param={to:'webHistory',cmd:'save',url:location.href,type:$config.$product};break;case'fullPreview':param={to:'fullPreview',cmd:'action',url:location.href};break;case'wndModeContrller':param={to:'wndModeContrller',cmd:''};break;default:param={}}try{$.extend(param,setting);param=Base.Json.toStr(param);window.external.jsToPc(param);try{console.log('jsToPc: '+Base.Json.toStr(param))}catch(e){}}catch(e){if($.browser.msie&&$.browser.version==6)return;try{console.log('pc客户端接口jsToPc异常：'+Base.Json.toStr(param))}catch(e){}}};var pcSynInterface={getMacId:function(){try{var macidStr=window.external.getMacId().split(',');return{macid_md5:macidStr[0],macid:macidStr[1]}}catch(e){return{macid_md5:'error',macid:'error'}}},getClientLc:function(){try{return window.external.getLc()}catch(e){return'error'}},isPlaying:function(){try{return window.external.isPlaying()}catch(e){return'1'}},getLog:function(size){try{size=(size||10)*1024;return window.external.getLog(size)}catch(e){return'error'}},selectFolder:function(){try{return window.external.selectFolder()}catch(e){return'error'}},openUrl:function(tabName,url){if(!url)return;try{switch(tabName){case'userCenter':window.external.openUserCenterTab(url);break;case'playRecorder':window.external.openPlayRecorderTab(url);break;case'player':window.external.openPlayerWebTab(url);break;case'home':default:window.external.openHomeTab(url)}}catch(e){window.open(url,'_blank')}},openPage:function(type){try{window.external.openPage(type)}catch(e){}},openFolder:function(path){try{window.external.openFolder(path)}catch(e){}}};Base.pcInterface=pcInterface;Base.pcSynInterface=pcSynInterface})();
(function(){Base.pcInterface('saveHistory')})();
$(document).ready(function(){$(document).bind('contextmenu',function(){return false})});
(function(){var Tpl=function(templet,mix){this.tpl=templet;this.mix=mix};Tpl.prototype={render:function(data,mix){if(!this.tpl){return''}if(!data)return this.tpl;mix=mix||this.mix;data=data instanceof Array?data:[data];if(typeof mix=='function'){for(var i=0,len=data.length;i<len;i++){mix(data[i],i)}}return this.parseData(data)},parseData:function(data){var html=[],i,len=data.length,key,mstr,reg;for(i=0;i<len;i++){mstr=this.tpl;for(key in data[i]){reg=new RegExp('\{'+key+'\}','gi');mstr=mstr.replace(reg,function(){return data[i][key]})}html.push(mstr)}return html.join('')}};Base.Tpl=Tpl})();
if(typeof Model=='undefined'){window.Model={}}
(function(){var Template={totalInfo:['<dl id="total-{id}" c-id="{id}" class="w180 {statusStyle}" status="{status}" channel="{channel}" taskid="{taskid}">','<dt>','<a href="javascript:void(0);">','<img src="{picture}" onerror="javascript:this.src=\'css\/images\/defaultImg.jpg\';this.onerror=null;">','<u class="u-bg"></u>','<u class="u-t"></u>','<u class="u-r"></u>','<u id="total-percent-{id}" style="width:{percent}%;" class="u-rt"></u>','<u id="total-statusMsg-{id}" class="u-tx">{statusMsg}</u>','<u class="u-yes"></u>','<u class="u-file"></u>','<u class="u-vdo"></u>','<b class="bg"></b>','<u class="u-num" style="display: none"><em class="n-l"></em><em class="n-c"></em><em class="n-r"></em></u>','</a>','</dt>','<dd class="d-t">','<b><a href="#">{albumTitle}</a></b>','</dd>','<dd id="total-progress-{id}" class="d-i">{progressMsg}</dd>','<dd class="d-p"></dd>','</dl>'].join(''),jujiDetail:['<li id="taskid-{taskid}" class="{statusStyle}" taskid="{taskid}" status="{status}">','<a href="#">','<b>{title}</b>','<i id="detail-statusMsg-{taskid}" class="i">{statusMsg}</i>','<em><small id="detail-speed-{taskid}">{speedMsg}</small></em>','<u id="detail-percent-{taskid}" style="width:{percent}%;" class="u-rt"></u>','<u class="u-yes"></u>','</a>','</li>'].join(''),zongyiDetail:['<li id="taskid-{taskid}" class="{statusStyle}" taskid="{taskid}" status="{status}">','<a href="#">','<span>{title}</span>','<em id="detail-statusMsg-{taskid}">{statusMsg}</em>','<u id="detail-percent-{taskid}" class="u-rt" style="width:{percent}%;"></u>','<u class="u-yes"></u>','</a>','</li>'].join(''),jujiConS:'<div id="detail-{id}" c-id="{id}" style="display: none" class="num-list"><ul><li type="all" style="display: none;"><a href="#" title="">全选</a></li>',jujiConE:'</ul></div>',zongyiConS:'<div id="detail-{id}" c-id="{id}" style="display: none" class="txt-list"><ul><li type="all" style="display: none;" class="all"><a href="#" title="">全选</a></li>',zongyiConE:'</ul></div>'};var Request={add:function(setting){var param={"to":"downloader","fromPage":"","cmd":"add","id":"","pid":"","channel":"","vtype":"","picture":"","albumtitle":"","quality":"","deloriginal":"none","items":[]};$.extend(param,setting);param.id=param.channel=='other'?new Date().getTime()+'':param.pid+'';param.albumtitle=param.channel=='other'?param.items[0]&&param.items[0].title:param.albumtitle;param.channel=param.channel=='other'?'movie':param.channel;Base.pcInterface('',param)},reload:function(taskid){var param={"to":"downloader","cmd":"reload","items":taskid};Base.pcInterface('',param)},start:function(taskid){taskid=taskid instanceof Array?taskid:[taskid];var param={"to":"downloader","cmd":"start","items":taskid};Base.pcInterface('',param)},pause:function(taskid){taskid=taskid instanceof Array?taskid:[taskid];var param={"to":"downloader","cmd":"pause","items":taskid};Base.pcInterface('',param)},del:function(taskid){taskid=taskid instanceof Array?taskid:[taskid];var param={"to":"downloader","cmd":"delete","items":taskid};Base.pcInterface('',param)},play:function(taskid){var param={"to":"downloader","cmd":"play","items":taskid};Base.pcInterface('',param)},openFolder:function(taskid){var param={"to":"downloader","cmd":"openFolder","items":taskid};Base.pcInterface('',param)},init:function(){var param={"to":"downloader","cmd":"init"};Base.pcInterface('',param)},update:function(){var param={"to":"downloader","cmd":"update"};Base.pcInterface('',param)}};var Response={_handles:{},_errorHandles:{},addListener:function(type,handle){if(!this._handles[type]){this._handles[type]=[]}if(typeof handle!='function')return;this._handles[type].push(handle)},addErrorListener:function(type,handle){if(!this._errorHandles[type]){this._errorHandles[type]=[]}if(typeof handle!='function')return;this._errorHandles[type].push(handle)}};window.addPcListener('downloadui',function(param){if(param.cmd){var fns=Response._handles[param.cmd]||[];for(var i=0,len=fns.length;i<len;i++){fns[i](param)}}else if(param.error){var errors=param.error;for(var i=0,len=errors.length;i<len;i++){var fns=Response._errorHandles[errors[i].cmd]||[];for(var j=0,len2=fns.length;j<len2;j++){fns[j](errors[i])}}}});Model.Download={Template:Template,Request:Request,Response:Response}})();
if(typeof Widget=='undefined'){window.Widget={}}
(function(){var _scrollToolList={};var scrollTool=function(id,config){if(!_scrollToolList[id]){if(!config)return;_scrollToolList[id]=new ScrollTool(config)}return _scrollToolList[id]};$(document).keydown(function(evt){var step=0;switch(evt.keyCode){case 38:step=-100;break;case 40:step=100;break;default:return}var coreScroll=[],secondaryScroll=[];for(var k in _scrollToolList){var scrollObj=_scrollToolList[k];if(!scrollObj.isCore&&scrollObj.isMouseInContainer){secondaryScroll.push(scrollObj)}else if(scrollObj.isCore){coreScroll.push(scrollObj)}}var targetScroll=secondaryScroll.length?secondaryScroll:coreScroll;$.each(targetScroll,function(i,scrollObj){var startTop=parseInt(scrollObj.scrollBtn.css('top'));scrollObj.moveByStep(step)})});$(document).mouseenter(function(){for(var k in _scrollToolList){_scrollToolList[k].scrollBtn.stop().css('opacity',1)}}).mouseleave(function(){for(var k in _scrollToolList){_scrollToolList[k].scrollBtn.animate({'opacity':0},300)}});var ScrollTool=function(config){this.enable=typeof config.enable=='undefined'?true:config.enable;this.isCore=typeof config.isCore=='undefined'?true:config.isCore;this.isMouseInContainer=false;this.container=config.container;this.content=config.content;this.scrollCon=config.scrollCon;this.scrollBtn=config.scrollBtn;this.containerOffsetTop=config.containerOffsetTop||0;this.scrollConOffsetTop=config.scrollConOffsetTop||0;this.scrollBtnMain=this.scrollBtn.find('span.s-cn');this.scrollBtnOffsetHeight=this.scrollBtn.find('span.s-up').height()+this.scrollBtn.find('span.s-bt').height();this.scrollBtnMinHeight=120;this._topOffsetMin=0;this._topOffsetMax=0;this.btnRadio=0;this.mouseScrollTarget=config.mouseScrollTarget=='container'?this.container:$('body');this.bindFn={atBottom:[],scroll:[]};this.resizeFn=config.resizeFn?config.resizeFn:function(self){var wh=$(window).height();var containerHeight=wh>(self.containerOffsetTop+1)?wh-self.containerOffsetTop-1:1,scrollHeight=wh>(self.scrollConOffsetTop+1)?wh-self.scrollConOffsetTop-1:1;self.container.height(containerHeight);self.scrollCon.height(scrollHeight);self.refresh()};this.init()};ScrollTool.prototype={init:function(){this.addEvent();this.resizeFn(this)},refresh:function(){this.scrollCon.css('overflow','auto').css('overflow','hidden');var containerHeight=this.container.get(0).offsetHeight,contentHeight=this.content.get(0).scrollHeight;if(containerHeight<=0||contentHeight<=0||contentHeight<=containerHeight){this.scrollCon.hide();this.content.css('top',0);this._topOffsetMin=this._topOffsetMax=0;return}else{this.scrollCon.show()}var scrollConHeight=this.scrollCon.get(0).offsetHeight;var scrollBtnHeight=scrollConHeight*(containerHeight/contentHeight);scrollBtnHeight=scrollBtnHeight<this.scrollBtnMinHeight?this.scrollBtnMinHeight:scrollBtnHeight;var scrollBtnMainHeight=scrollBtnHeight-this.scrollBtnOffsetHeight;this.scrollBtnMain.height(scrollBtnMainHeight);this.btnRadio=(contentHeight-containerHeight)/(scrollConHeight-scrollBtnHeight);this._topOffsetMax=this.scrollCon.get(0).offsetHeight-scrollBtnHeight;var offsetTop=-parseInt(this.content.css('top'))*(1/this.btnRadio);offsetTop=offsetTop>this._topOffsetMax?this._topOffsetMax:offsetTop;this.moveTo(offsetTop)},moveByStep:function(step){if(!this.enable){return}step=step||100;var startTop=parseInt(this.content.css('top')),offset=startTop-step;this.moveTo(offset,'content')},moveTo:function(offsetTop,type){if(this.scrollBtn.css('top')==this._topOffsetMax){return}type=type||'scroll';offsetTop=type=='scroll'?offsetTop:-offsetTop/this.btnRadio;if(offsetTop<this._topOffsetMin){offsetTop=this._topOffsetMin}else if(offsetTop>this._topOffsetMax){offsetTop=this._topOffsetMax;for(var i=0,len=this.bindFn.atBottom.length;i<len;i++){var fnObj=this.bindFn.atBottom[i];fnObj.fn(fnObj.data)}}this.content.css('top',-offsetTop*this.btnRadio);this.scrollBtn.css('top',offsetTop);for(var i=0,len=this.bindFn.scroll.length;i<len;i++){var fnObj=this.bindFn.scroll[i];fnObj.fn(fnObj.data)}},bind:function(type){var data,fn;if(typeof arguments[1]!='function'&&typeof arguments[2]=='function'){data=arguments[1];fn=arguments[2]}else if(typeof arguments[1]=='function'){fn=arguments[1]}if(this.bindFn[type]){this.bindFn[type].push({fn:fn,data:data})}},unbind:function(type,fn){if(this.bindFn[type]){if(typeof fn!='function'){this.bindFn[type]=[]}else{var i=0;while(this.bindFn[type][i]){if(this.bindFn[type][i].fn==fn){this.bindFn[type].splice(i,1)}else{i++}}}}},addEvent:function(){var offset=0,self=this;var doDrag=function(evt){self.moveTo(evt.clientY-offset)};var stopDrag=function(){isScrollBtnClick=false;self.scrollCon.removeClass('scr-hov');if(self.scrollBtn[0].releaseCapture){self.scrollBtn.unbind('mousemove').unbind('mouseup');self.scrollBtn[0].releaseCapture()}else{$(document).unbind('mousemove').unbind('mouseup')}document.onselectstart=null};var isScrollBtnClick=false;this.scrollBtn.mousedown(function(evt){isScrollBtnClick=true;offset=evt.clientY-$(this).offset().top;document.onselectstart=function(){return false};if(this.setCapture){$(this).bind({mousemove:doDrag,mouseup:stopDrag});this.setCapture()}else{$(document).bind({mousemove:doDrag,mouseup:stopDrag})}}).click(function(evt){evt.stopPropagation()});this.scrollCon.mouseenter(function(){$(this).addClass('scr-hov')}).mouseleave(function(){$(this).removeClass('scr-hov')});this.container.parent().mouseenter(function(){self.isMouseInContainer=true}).mouseleave(function(){self.isMouseInContainer=false}).mousemove(function(){self.isMouseInContainer=true;$(this).unbind('mousemove')});var scrollFunc=function(evt){evt=evt||window.event;var delta=0;if(evt.originalEvent.wheelDelta){delta=-evt.originalEvent.wheelDelta/120;if(window.opera&&window.opera.version()<10)delta=delta}else if(evt.originalEvent.detail){delta=evt.originalEvent.detail/3}var step=delta*100;self.moveByStep(step)};if($.browser.mozilla){this.mouseScrollTarget.bind('DOMMouseScroll',scrollFunc)}else{this.mouseScrollTarget.bind('mousewheel',scrollFunc)}var clickFunc=function(evt){var offset=evt.clientY-self.scrollConOffsetTop-parseInt(self.scrollBtn.height())/2;self.moveTo(offset)};this.scrollCon.click(clickFunc);Base.CustomEvent.resize(function(){self.resizeFn(self);self.refresh()})}};Widget.scrollTool=scrollTool})();
(function(){var formatSpeed=function(value){if(typeof value=='undefined'){return''}if(value==0){return'0KB/s'}var kb=value/1024;if(kb<1){return'1 KB/s'}var Mb=kb/1024;if(Mb<1&&kb<1000){return kb.toFixed(0)+'KB/s'}else{return Mb.toFixed(1)+'MB/s'}};var formatSize=function(value){if(typeof value=='undefined'||value===''){return''}if(value==0){return'0 KB'}var kb=(value/1024);if(kb<1){return'1 KB'}var Mb=kb/1024;if(Mb<1&&kb<1000){return kb.toFixed(0)+' KB'}var Gb=Mb/1024;if(Gb<1&&Mb<1000){return Mb.toFixed(0)+' MB'}else{return Gb.toFixed(2)+' G'}};var formatTime=function(second){if(!second){return'0秒'}var min=Math.floor(second/60),hour=Math.floor(min/60);if(hour>=1){return hour+'时'+min%60+'分'+second%60+'秒'}else{if(min>=1){return min+'分'+second%60+'秒'}else{return second+'秒'}}};var getParamFromUrl=function(){var url=decodeURIComponent(location.href),indexW=url.indexOf('?'),indexJ=url.indexOf('#');var objW={},objJ={};var str,param,i,len,tmp;if(indexW==-1){objW=null}else{str=url.substring(indexW+1,indexJ==-1?url.length:indexJ);param=str.split('&');for(i=0,len=param.length;i<len;i++){tmp=param[i].split('=');objW[tmp[0]]=tmp[1]}}if(indexJ==-1){objJ=null}else{str=url.substring(indexJ+1,url.length);param=str.split('&');for(i=0,len=param.length;i<len;i++){tmp=param[i].split('=');objJ[tmp[0]]=tmp[1]}}return{w:objW,j:objJ}};var sendLog=function(url){var img=new Image();img.onload=function(){img=null};img.src=url;setTimeout(function(){},1000)};Base.tool={formatSpeed:formatSpeed,formatSize:formatSize,formatTime:formatTime,getParamFromUrl:getParamFromUrl,sendLog:sendLog}})();
(function(){var nodes={noListCon:$('#no-list-con'),downloadList:$('#download-list')};Model.Download.Response.addListener('init',function(data){Dialogs.loading.hide();initHtml(data.albums)});Model.Download.Response.addListener('add',function(result){if(result.msgType=='data'&&Base.cache('filterType').get()=='all'){addHtml(result.albums);Base.observer('update').publish(result)}});Base.observer('addCompleteData').subscribe(function(data){addHtml(data)});Base.observer('custom').subscribe(function(data){Dialogs.loading.hide();initHtml(data.albums)});var scroll=Widget.scrollTool('main',{container:$('#main-con'),content:$('#main-con div.abs-info'),scrollCon:$('#scroll'),scrollBtn:$('#scroll div.scr-post'),containerOffsetTop:50});function initHtml(datas){nodes.downloadList.html('');var filterType=Base.cache('filterType').get();if(filterType=='complete'){datas=filterData(datas)}if(datas.length){nodes.downloadList.show();nodes.noListCon.hide()}else{nodes.noListCon.show();nodes.downloadList.show()}function compareItems(data1,data2){return parseInt(data1.title)-parseInt(data2.title)}$.each(datas,function(i,obj){if(obj.channel=='juji'||obj.channel=='zongyi'){obj.items.sort(compareItems)}});var html=[],htmlDetail=[];for(var i=0,len=datas.length;i<len;i++){var tmp=datas[i],items;html.push(new Base.Tpl(Model.Download.Template.totalInfo).render(formatDataTotal(tmp)));if(tmp.channel=='juji'){items=tmp.items;htmlDetail.push(new Base.Tpl(Model.Download.Template.jujiConS).render({id:tmp.id}));for(var k=0,len2=items.length;k<len2;k++){htmlDetail.push(new Base.Tpl(Model.Download.Template.jujiDetail).render(formatDataDetail(items[k],tmp.channel)))}htmlDetail.push(new Base.Tpl(Model.Download.Template.jujiConE).render({id:tmp.id}))}else if(tmp.channel=='zongyi'){items=tmp.items;htmlDetail.push(new Base.Tpl(Model.Download.Template.zongyiConS).render({id:tmp.id}));for(var k=0,len2=items.length;k<len2;k++){htmlDetail.push(new Base.Tpl(Model.Download.Template.zongyiDetail).render(formatDataDetail(items[k],tmp.channel)))}htmlDetail.push(new Base.Tpl(Model.Download.Template.zongyiConE).render({id:tmp.id}))}}nodes.downloadList.html(html.join('')+htmlDetail.join(''));scroll.refresh();Base.observer('resize').publish()}function filterData(originalData){var datas=$.extend(true,[],originalData);var filter={'1':false,'2':false,'3':true,'4':false,'5':false,'6':false};var i=0,k=0;while(datas[i]){var tmp=datas[i];var items=tmp.items;k=0;while(items[k]){if(!filter[items[k].status]){items.splice(k,1)}else{k++}}if(!items.length){datas.splice(i,1)}else{i++;tmp.status='3'}}return datas}function addHtml(datas){var html=[],htmlDetail=[];$.each(datas,function(l,data){var id=data.id,channel=data.channel;var totalNode=nodes.downloadList.find('#total-'+id);if(!totalNode.length){html.push(new Base.Tpl(Model.Download.Template.totalInfo).render(formatDataTotal(data)))}if(channel!='movie'){var detalNode=nodes.downloadList.find('#detail-'+id);var items=data.items,i,len;if(!detalNode.length){if(channel=='juji'){htmlDetail.push(new Base.Tpl(Model.Download.Template.jujiConS).render({id:id}));for(i=0,len=items.length;i<len;i++){htmlDetail.push(new Base.Tpl(Model.Download.Template.jujiDetail).render(formatDataDetail(items[i],channel)))}htmlDetail.push(new Base.Tpl(Model.Download.Template.jujiConE).render({id:id}))}else if(channel=='zongyi'){htmlDetail.push(new Base.Tpl(Model.Download.Template.zongyiConS).render({id:id}));for(i=0,len=items.length;i<len;i++){htmlDetail.push(new Base.Tpl(Model.Download.Template.zongyiDetail).render(formatDataDetail(items[i],channel)))}htmlDetail.push(new Base.Tpl(Model.Download.Template.zongyiConE).render({id:id}))}}else{if(channel=='juji'){var liList=detalNode.find('li'),liListLen=liList.length,liIndexList=[];liList.each(function(){liIndexList.push(parseInt($(this).find('a b').html()))});var k,len2=liIndexList.length,htmlModel={};for(i=0,len=items.length;i<len;i++){var title=parseInt(items[i].title),tmp=new Base.Tpl(Model.Download.Template.jujiDetail).render(formatDataDetail(items[i],channel));for(k=0;k<len2;k++){if(title<liIndexList[k]){if(!htmlModel[k]){htmlModel[k]=[]}htmlModel[k].push(tmp);break}else if(k==len2-1){if(!htmlModel[len2]){htmlModel[len2]=[]}htmlModel[len2].push(tmp)}}}for(var index in htmlModel){index=parseInt(index);if(index==liListLen){$(liList[liListLen-1]).after(htmlModel[index].join(''))}else{$(liList[index]).before(htmlModel[index].join(''))}}}else if(channel=='zongyi'){var htmlModel=[];for(i=0,len=items.length;i<len;i++){htmlModel.push(new Base.Tpl(Model.Download.Template.zongyiDetail).render(formatDataDetail(items[i],channel)))}detalNode.find('ul').append(htmlModel.join(''))}}}});nodes.downloadList.append(html.join('')+htmlDetail.join(''));nodes.noListCon.hide();nodes.downloadList.show();scroll.refresh();Base.observer('resize').publish()}function formatDataTotal(data){switch(data.status){case'1':data.statusStyle='ply';data.statusMsg=Base.tool.formatSpeed(data.speed);break;case'2':data.statusStyle='spd';data.statusMsg='已暂停';break;case'3':data.statusStyle='vdo';data.statusMsg='';break;case'4':data.statusStyle='ing';data.statusMsg='排队中';break;case'6':data.statusStyle='err';data.statusMsg='下载失败'}if(data.channel=='movie'){data.taskid=data.items[0].taskid;data.speedMsg=Base.tool.formatSpeed(data.items[0].speed);data.progressMsg=(data.status=='3')?Base.tool.formatSize(data.size):Base.tool.formatSize(data.progress)+'/'+Base.tool.formatSize(data.size)}else{data.taskid='';var filterType=Base.cache('filterType').get();data.progressMsg='共'+(filterType=='all'?data.size:data.progress)+'集';data.statusStyle+=' sp'}return data}function formatDataDetail(data,channel){switch(data.status){case'1':data.statusStyle='ply';if(channel=='juji'){data.statusMsg='下载中';data.speedMsg=Base.tool.formatSpeed(data.speed)}else if(channel=='zongyi'){data.statusMsg='下载 '+Math.floor(data.percent)+'%'+' '+Base.tool.formatSpeed(data.speed)}break;case'2':data.statusStyle='spd';data.statusMsg='已暂停';data.speedMsg='';break;case'3':data.statusStyle='vdo';data.statusMsg='';data.speedMsg='';break;case'4':data.statusStyle='ing';data.statusMsg='排队中';data.speedMsg='';break;case'6':data.statusStyle='err';data.statusMsg='下载失败';data.speedMsg='';break}return data}})();
(function(){var nodes={noListCon:$('#no-list-con'),downloadList:$('#download-list')};var scroll=Widget.scrollTool('main');Model.Download.Response.addListener('statusChange',statusChange);Model.Download.Response.addListener('update',updateProgress);Base.observer('update').subscribe(statusChange);function statusChange(originalData){originalData=originalData.albums||originalData;var data=$.extend(true,[],originalData);var filterType=Base.cache('filterType').get();if(filterType=='complete'){var addData=[];for(var i=0,len=data.length;i<len;i++){var tmp=data[i],channel=tmp.channel,items=tmp.items,id=tmp.id,idStatus=tmp.status;if(idStatus=='3'){if(channel!='movie'){$('#total-progress-'+id).html('共'+(filterType=='all'?tmp.size:tmp.progress)+'集')}}else if(idStatus=='5'){$('#total-'+id).remove();$('#detail-'+id).remove();continue}var k=0;while(items[k]){if(items[k].status!='3'){if(items[k].status=='5'){$('#taskid-'+items[k].taskid).remove()}items.splice(k,1)}else{k++}}if(items.length){addData.push(tmp)}Base.observer('addCompleteData').publish(addData)}}else{for(var i=0,len=data.length;i<len;i++){var tmp=data[i],channel=tmp.channel,items=tmp.items,id=tmp.id,idStatus=tmp.status;var style,msg,progress;switch(idStatus){case'1':style='ply';msg=Base.tool.formatSpeed(tmp.speed);break;case'2':style='spd';msg='已暂停';break;case'3':style='vdo';msg='';break;case'4':style='ing';msg='排队中';break;case'5':$('#total-'+id).remove();$('#detail-'+id).remove();continue;case'6':style='err';msg='下载失败';break}style=$('#total-'+id).attr('class').replace(/ply|spd|vdo|ing|err/,style);if(channel=='movie'){progress=idStatus=='3'?Base.tool.formatSize(tmp.size):Base.tool.formatSize(tmp.progress)+'/'+Base.tool.formatSize(tmp.size)}else{progress='共'+(filterType=='all'?tmp.size:tmp.progress)+'集'}$('#total-'+id).attr({'class':style,'status':idStatus});$('#total-percent-'+id).css('width',tmp.percent+'%');$('#total-statusMsg-'+id).html(msg);$('#total-progress-'+id).html(progress);if(channel=='movie')continue;for(var k=0,len2=items.length;k<len2;k++){var tmp2=items[k],taskid=tmp2.taskid,status=tmp2.status,speed=Base.tool.formatSpeed(tmp2.speed);switch(status){case'1':style='ply';if(channel=='zongyi'){msg='下载 '+Math.floor(tmp2.percent)+'%'+' '+speed}else{msg='下载中'}break;case'2':style='spd';msg='已暂停';break;case'3':style='vdo';msg='';break;case'4':style='ing';msg='排队中';break;case'5':$('#taskid-'+taskid).remove();continue;case'6':style='err';msg='下载失败';break}style=$('#taskid-'+taskid).attr('class').replace(/ply|spd|vdo|ing|err/,style);$('#taskid-'+taskid).attr({'class':style,'status':status});$('#detail-statusMsg-'+taskid).html(msg);if(status=='1'){$('#detail-speed-'+taskid).html(speed)}else{$('#detail-speed-'+taskid).html('')}}}}if(!nodes.downloadList.children().length){nodes.downloadList.hide();nodes.noListCon.show()}Base.observer('resize').publish();scroll.refresh()}function updateProgress(data){data=data.albums;for(var i=0,len=data.length;i<len;i++){var tmp=data[i],items=tmp.items,channel=tmp.channel,status=tmp.status,id=tmp.id;if(status!='1')return;if(channel=='movie'){var progress=Base.tool.formatSize(tmp.progress)+'/'+Base.tool.formatSize(tmp.size);$('#total-progress-'+id).html(progress)}$('#total-percent-'+id).css('width',tmp.percent+'%');$('#total-statusMsg-'+id).html(Base.tool.formatSpeed(tmp.speed));if(channel=='movie')continue;for(var k=0,len2=items.length;k<len2;k++){var videoData=items[k],taskid=videoData.taskid;$('#detail-percent-'+taskid).css('width',videoData.percent+'%');var speed=Base.tool.formatSpeed(videoData.speed);if(tmp.channel=='juji'){$('#detail-speed-'+taskid).html(speed)}else if(tmp.channel=='zongyi'){var msg='下载 '+Math.floor(videoData.percent)+'%'+' '+speed;$('#detail-statusMsg-'+taskid).html(msg)}}}}})();
(function(){window.isEdit=false;var nodes={editBtn:$('#edit'),editCancelBtn:$('#edit-cancel'),normalTab:$('#normal-tab'),editTab:$('#edit-tab'),editCommand:$('#edit-command'),selectAll:$('#select-all'),downloadList:$('#download-list')};var taskList=[];var scroll=Widget.scrollTool('main');nodes.editBtn.click(function(){window.isEdit=true;nodes.normalTab.removeClass('active');nodes.editTab.addClass('active');nodes.downloadList.addClass('edit-vdo');nodes.downloadList.find('div.num-list,div.txt-list').each(function(i,elem){$(elem).find('li:first').show()});scroll.refresh()});Base.cache('filterType').subscribe(function(value){var tmp=nodes.editCommand.find('a[type=start],a[type=pause]');if(value=='complete'){tmp.hide()}else{tmp.show()}});nodes.editCancelBtn.click(function(){window.isEdit=false;nodes.editTab.removeClass('active');nodes.normalTab.addClass('active');nodes.downloadList.removeClass('edit-vdo');nodes.downloadList.find('div.num-list,div.txt-list').each(function(i,elem){$(elem).find('li:first').hide()});clearAllChecked();scroll.refresh()});nodes.downloadList.delegate('dl dt,dl dd','click',function(){if(!window.isEdit){return}var targetDlNode=$(this).closest('dl');var channel=targetDlNode.attr('channel');if(channel=='movie'){var taskid=targetDlNode.attr('taskid');if(targetDlNode.hasClass('check')){targetDlNode.removeClass('check');updateDelTask(taskid,'del')}else{targetDlNode.addClass('check');updateDelTask(taskid,'add')}checkSelectAll()}});nodes.downloadList.delegate('li','click',function(){if(!window.isEdit){return}if($(this).attr('type')=='all'){var taskids=[];if($(this).siblings('li').length==$(this).siblings('li.check').length){$(this).siblings().each(function(){$(this).removeClass('check');taskids.push($(this).attr('taskid'))});updateDelTask(taskids,'del')}else{$(this).siblings().each(function(){$(this).addClass('check');taskids.push($(this).attr('taskid'))});updateDelTask(taskids,'add')}}else{var taskid=$(this).attr('taskid');if($(this).hasClass('check')){$(this).removeClass('check');updateDelTask(taskid,'del')}else{$(this).addClass('check');updateDelTask(taskid,'add')}}var id=$(this).closest('div').attr('c-id'),idNode=$('#total-'+id);var checkedLen=$(this).parent().find('li.check').length;if(checkedLen){idNode.find('u.u-num').show().find('em.n-c').html(checkedLen)}else{idNode.find('u.u-num').hide()}checkSelectAll()});nodes.selectAll.click(function(){var checkBox=$(this),hasCheck=checkBox.hasClass('active');taskList=[];hasCheck?checkBox.removeClass('active'):checkBox.addClass('active');nodes.downloadList.find('dl').each(function(){if($(this).attr('channel')=='movie'){if(hasCheck){$(this).removeClass('check')}else{$(this).addClass('check');taskList.push($(this).attr('taskid'))}}});nodes.downloadList.find('div.num-list,div.txt-list').each(function(){var liList=$(this).find('li').not(':first');liList.each(function(){if(hasCheck){$(this).removeClass('check')}else{$(this).addClass('check');taskList.push($(this).attr('taskid'))}});var id=$(this).attr('c-id'),idNode=$('#total-'+id);hasCheck?idNode.find('u.u-num').hide():idNode.find('u.u-num').show().find('em.n-c').html(liList.length)})});nodes.editCommand.delegate('a','click',function(){var type=$(this).attr('type')||'';if(taskList.length){Base.observer('editCommand').publish(type,taskList);nodes.editCancelBtn.click()}});function checkSelectAll(){var isSelectAll=true;nodes.downloadList.find('dl').each(function(){var targetNode=$(this);if(!targetNode.hasClass('sp')&&!targetNode.hasClass('check')){isSelectAll=false;return false}});if(isSelectAll){nodes.downloadList.find('div.num-list li,div.txt-list li').each(function(){var targetNode=$(this);if(targetNode.attr('type')!='all'){if(!targetNode.hasClass('check')){isSelectAll=false;return false}}})}isSelectAll?nodes.selectAll.addClass('active'):nodes.selectAll.removeClass('active')}function clearAllChecked(){taskList=[];nodes.downloadList.find('dl').removeClass('check').find('u.u-num').hide();nodes.downloadList.find('li.check').removeClass('check');nodes.selectAll.removeClass('active')}function updateDelTask(taskids,type){taskids=taskids instanceof Array?taskids:[taskids];if(type=='add'){$.each(taskids,function(i,taskid){var index=$.inArray(taskid,taskList);if(index<0){taskList.push(taskid)}})}else{$.each(taskids,function(i,taskid){var index=$.inArray(taskid,taskList);taskList.splice(index,1)})}}})();
(function(){var nodes={downloadList:$('#download-list')};nodes.downloadList.delegate('dl dt,dl dd','click',function(){if(window.isEdit){return}var targetDlNode=$(this).closest('dl');var channel=targetDlNode.attr('channel'),status=targetDlNode.attr('status');if(channel=='movie'&&(status=="2"||status=="6")){var taskid=targetDlNode.attr('taskid');Model.Download.Request.start(taskid)}});nodes.downloadList.delegate('li','click',function(){if(window.isEdit){return}var taskid=$(this).attr('taskid'),status=$(this).attr('status');if(status=="2"||status=="6"){Model.Download.Request.start(taskid)}});Base.observer('editCommand').subscribe(function(type,taskList){if(type=='start'){Model.Download.Request.start(taskList)}})})();
(function(){var nodes={downloadList:$('#download-list')};nodes.downloadList.delegate('dl dt,dl dd','click',function(){if(window.isEdit){return}var targetDlNode=$(this).closest('dl');var channel=targetDlNode.attr('channel'),status=targetDlNode.attr('status');if(channel=='movie'&&(status=="1"||status=="4")){var taskid=targetDlNode.attr('taskid');Model.Download.Request.pause(taskid)}});nodes.downloadList.delegate('li','click',function(){if(window.isEdit){return}var taskid=$(this).attr('taskid'),status=$(this).attr('status');if(status=="1"||status=="4"){Model.Download.Request.pause(taskid)}});Base.observer('editCommand').subscribe(function(type,taskList){if(type=='pause'){Model.Download.Request.pause(taskList)}})})();
(function(){Base.observer('editCommand').subscribe(function(type,taskList){if(type=='del'){Model.Download.Request.del(taskList)}});Model.Download.Response.addErrorListener('delete',function(param){if(param.status=='E1'){Widget.advise.info('当前视频被占用,无法删除')}else{Widget.advise.info(param.msg)}})})();
(function(){var Dialog=function(model,param){this.dialogNode=model.slice(0,1)=='#'?$(model):$(model).appendTo('body');this.width=param.width||this.dialogNode.outerWidth();this.height=param.height||this.dialogNode.outerHeight();if(param.hasShadow){this.shadow=$('<div class="white-body" style="display: none;"></div>').appendTo('body')}if(param.isOverFlash){this.overFlashFrame=$('<iframe style="position: absolute;visibility: hidden;overflow: hidden;width:'+this.width+'px;height:'+this.height+'px;background-color:#333"></iframe>').appendTo('body')}this.shadowEvent=typeof param.shadowEvent=='undefined'?true:param.shadowEvent;this.hiddenFn=param.hiddenFn;this.addEvent();this.resize()};Dialog.prototype={show:function(){this.dialogNode.css('visibility','visible');this.overFlashFrame&&this.overFlashFrame.css('visibility','visible');this.shadow&&this.shadow.show()},hide:function(){this.dialogNode.css('visibility','hidden');this.overFlashFrame&&this.overFlashFrame.css('visibility','hidden');this.shadow&&this.shadow.hide();this.hiddenFn&&this.hiddenFn()},setCenter:function(){var ww=$(window).width(),wh=$(window).height();this.dialogNode.css('top',(wh-this.height)/2);this.shadow&&this.shadow.css({width:ww,height:wh})},resize:function(){if(this.overFlashFrame){this.overFlashFrame.css({width:this.dialogNode.outerWidth(),height:this.dialogNode.outerHeight(),left:this.dialogNode.offset().left,top:this.dialogNode.offset().top})}},addEvent:function(){var self=this;if(this.shadow&&this.shadowEvent){this.shadow.click(function(){self.hide()})}Base.CustomEvent.resize($.proxy(this.resize,this))}};Widget.Dialog=Dialog})();
(function(){var _dialogs=[];var isShowing=false;function showDialog(){if(!isShowing&&_dialogs.length){isShowing=true;var obj=_dialogs.shift();switch(obj.type){case'info':infoDialog.show(obj.msg,obj.time);break;case'info2':info2Dialog.show(obj.msg,obj.subMsg,obj.time);break;case'alert':alertDialog.show(obj.msg,obj.submsg,obj.cb);break;case'confirm':confirmDialog.show(obj.msg,obj.cb);break;case'confirm2':confirm2Dialog.show(obj.delCb,obj.reloadCb);break}}}function info(msg,time){_dialogs.push({type:'info',msg:msg,time:time});showDialog()}function info2(msg,subMsg,time){_dialogs.push({type:'info2',msg:msg,subMsg:subMsg,time:time});showDialog()}function alert(msg,submsg,cb){_dialogs.push({type:'alert',msg:msg,submsg:submsg,cb:cb});showDialog()}function confirm(msg,cb){_dialogs.push({type:'confirm',msg:msg,cb:cb});showDialog()}function confirm2(delCb,reloadCb){_dialogs.push({type:'confirm2',delCb:delCb,reloadCb:reloadCb});showDialog()}var infoDialog={dialog:null,_model:['<div class="hint ht-250">','<table width="100%" cellspacing="0" cellpadding="0" border="0">','<tbody><tr>','<td class="t-l">&nbsp;</td>','<td class="t-c">&nbsp;</td>','<td class="t-r">&nbsp;</td>','</tr>','<tr>','<td class="c-l">&nbsp;</td>','<td class="c-c"><p id="advise-info-msg" class="p-c">成功追剧到播放单</p></td>','<td class="c-r">&nbsp;</td>','</tr>','<tr>','<td class="b-l">&nbsp;</td>','<td class="b-c">&nbsp;</td>','<td class="b-r">&nbsp;</td>','</tr></tbody>','</table>','</div>'].join(''),initDialog:function(){this.dialog=new Widget.Dialog(this._model,{isOverFlash:true,hiddenFn:function(){isShowing=false;showDialog()}})},show:function(msg,time){if(!this.dialog){this.initDialog()}$('#advise-info-msg').html(msg);this.dialog.show();var self=this;setTimeout(function(){self.dialog.hide()},time||1500)}};var info2Dialog={dialog:null,_model:['<div class="hint ht-400 ht-commen">','<h2 id="advise-info2-msg" class="ht-commen-title"></h2>','<p id="advise-info2-submsg" class="ht-commen-con"></p>','</div>'].join(''),initDialog:function(){this.dialog=new Widget.Dialog(this._model,{isOverFlash:true,hiddenFn:function(){isShowing=false;showDialog()}})},show:function(msg,subMsg,time){if(!this.dialog){this.initDialog()}$('#advise-info2-msg').html(msg||'');$('#advise-info2-submsg').html(subMsg||'');this.dialog.show();var self=this;setTimeout(function(){self.dialog.hide()},time||1500)}};var alertDialog={dialog:null,_model:['<div class="hint ht-400">','<table width="100%" cellspacing="0" cellpadding="0" border="0">','<tbody><tr>','<td class="t-l">&nbsp;</td>','<td class="t-c">&nbsp;</td>','<td class="t-r">&nbsp;</td>','</tr>','<tr>','<td class="c-l">&nbsp;</td>','<td class="c-c"><ul class="ht-file">','<li id="advise-alert-msg" class="li01">无法找到视频文件</li>','<li id="advise-alert-submsg" class="li02">请确认视频文件是否被移动或删除</li>','<li class="li03"><a id="advise-alert-btn" class="btn" title="" href="#">确定</a></li>','</ul></td>','<td class="c-r">&nbsp;</td>','</tr>','<tr>','<td class="b-l">&nbsp;</td>','<td class="b-c">&nbsp;</td>','<td class="b-r">&nbsp;</td>','</tr></tbody>','</table>','</div>'].join(''),initDialog:function(){var self=this;this.dialog=new Widget.Dialog(this._model,{hasShadow:true,hiddenFn:function(){isShowing=false;showDialog()}})},show:function(msg,submsg,cb){var self=this;if(!this.dialog){this.initDialog()}$('#advise-alert-msg').html(msg||'');$('#advise-alert-submsg').html(submsg||'');$('#advise-alert-btn').unbind('click').bind('click',function(){self.dialog.hide();cb&&cb()});this.dialog.show()}};var confirmDialog={dialog:null,_model:['<div class="hint ht-400">','<table width="100%" cellspacing="0" cellpadding="0" border="0">','<tbody><tr>','<td class="t-l">&nbsp;</td>','<td class="t-c">&nbsp;</td>','<td class="t-r">&nbsp;</td>','</tr>','<tr>','<td class="c-l">&nbsp;</td>','<td class="c-c"><dl class="clear-play">','<dt id="advise-confirm-msg">您确定清空播放记录？</dt>','<dd><a id="advise-confirm-submit" class="btn" href="#">确定</a><a id="advise-confirm-cancel" class="btn" href="#">取消</a></dd>','</dl></td>','<td class="c-r">&nbsp;</td>','</tr>','<tr>','<td class="b-l">&nbsp;</td>','<td class="b-c">&nbsp;</td>','<td class="b-r">&nbsp;</td>','</tr></tbody>','</table>','</div>'].join(''),initDialog:function(){var self=this;this.dialog=new Widget.Dialog(this._model,{hasShadow:true,hiddenFn:function(){isShowing=false;showDialog()}});$('#advise-confirm-cancel').click(function(){self.dialog.hide()})},show:function(msg,cb){var self=this;if(!this.dialog){this.initDialog()}$('#advise-confirm-msg').html(msg);$('#advise-confirm-submit').unbind('click').bind('click',function(){self.dialog.hide();cb&&cb()});this.dialog.show()}};var confirm2Dialog={dialog:null,_model:['<div class="dialog" id="reload-advise">','<div class="dialog-bg"></div>','<a id="reload-advise-close" href="#" class="shutdown"></a>','<div class="dialog-con">','<div class="tit-content">该视频已被删除或移动</div>','<div class="btns">','<a id="reload-advise-del" href="#" class="ui-dialog-btns-gray">删除该项</a>','<a id="reload-advise-reload" href="#" class="ui-dialog-btns-gray">重新下载</a>','</div>','</div>','</div>'].join(''),initDialog:function(){var self=this;this.dialog=new Widget.Dialog(this._model,{hasShadow:true,hiddenFn:function(){isShowing=false;showDialog()}});$('#reload-advise-close').click(function(){self.dialog.hide()})},show:function(delCb,reloadCb){var self=this;if(!this.dialog){this.initDialog()}$('#reload-advise-del').unbind('click').bind('click',function(){self.dialog.hide();delCb&&delCb()});$('#reload-advise-reload').unbind('click').bind('click',function(){self.dialog.hide();reloadCb&&reloadCb()});this.dialog.show()}};Widget.advise={info:info,info2:info2,alert:alert,confirm:confirm,confirm2:confirm2}})();
(function(){var nodes={downloadList:$('#download-list')};nodes.downloadList.delegate('dl dt,dl dd','click',function(){if(window.isEdit){return}var targetDlNode=$(this).closest('dl');var channel=targetDlNode.attr('channel'),status=targetDlNode.attr('status');if(channel=='movie'&&status=="3"){var taskid=targetDlNode.attr('taskid');Model.Download.Request.play(taskid)}});nodes.downloadList.delegate('li','click',function(){if(window.isEdit){return}var taskid=$(this).attr('taskid'),status=$(this).attr('status');if(status=="3"){Model.Download.Request.play(taskid)}});Model.Download.Response.addErrorListener('play',function(param){if(param.status=='E2'){var taskid=param.taskid;if(!taskid)return;function delTask(){Model.Download.Request.del(taskid)}function reloadTask(){Model.Download.Request.reload(taskid)}Widget.advise.confirm2(delTask,reloadTask)}else{Widget.advise.alert(param.msg)}})})();
(function(){var nodes={editMenu:$('#edit-menu'),delBtn:$('#edit-menu-del'),folderBtn:$('#edit-menu-folder'),downloadList:$('#download-list')};var targetDlNode=null;var eMw=nodes.editMenu.outerWidth(),eMh=nodes.editMenu.outerHeight();nodes.downloadList.delegate('dl dt,dl dd','contextmenu',function(e){if(window.isEdit)return;targetDlNode=$(this).closest('dl');var channel=targetDlNode.attr('channel');if(channel!='movie')return;showEditMenu(e)});nodes.downloadList.delegate('li','contextmenu',function(e){if(window.isEdit){return}targetDlNode=$(this).closest('li');showEditMenu(e)});nodes.delBtn.click(function(){if(!targetDlNode)return;var taskid=targetDlNode.attr('taskid');Model.Download.Request.del([taskid])});nodes.folderBtn.click(function(){if(!targetDlNode)return;var taskid=targetDlNode.attr('taskid');Model.Download.Request.openFolder(taskid)});function showEditMenu(e){var left=(e.clientX+eMw)<=$(window).width()?e.clientX:(e.clientX-eMw),top=(e.clientY+eMh)<=$(window).height()?e.clientY:(e.clientY-eMh);nodes.editMenu.css({left:left,top:top}).show()}function hideEditMenu(){nodes.editMenu.hide();targetDlNode=null}$(document).click(hideEditMenu);Base.CustomEvent.resize(hideEditMenu)})();
(function(){var nodes={listCon:$('#main-con'),downloadList:$('#download-list')};var scroll=Widget.scrollTool('main',{container:$('#main-con'),content:$('#main-con div.abs-info'),scrollCon:$('#scroll'),scrollBtn:$('#scroll div.scr-post'),containerOffsetTop:$('#main-con').offset().top});var NODE_WIDTH=200,NODE_MARGIN=20;function refresh(){var conWidth=nodes.listCon.width(),lineNum=Math.floor((conWidth+NODE_MARGIN)/NODE_WIDTH);nodes.downloadList.find('dl').each(function(i){var line=Math.ceil((i+1)/lineNum);var targetNode=$('#detail-'+$(this).attr('c-id'));if(targetNode.length){var index=line*lineNum-1;var dlNode=nodes.downloadList.find('dl:eq('+index+')');dlNode=dlNode.length?dlNode:nodes.downloadList.find('dl:last');dlNode.after(targetNode)}})}Base.CustomEvent.resize(refresh);Base.observer('resize').subscribe(refresh);nodes.downloadList.delegate('dl dd,dl dt','click',function(){var targetDlNode=$(this).closest('dl');var id=targetDlNode.attr('c-id'),channel=targetDlNode.attr('channel'),targetNode=$('#detail-'+id);if(targetNode.length&&channel!='movie'){if(targetDlNode.hasClass('active')){targetDlNode.removeClass('active');targetNode.hide()}else{nodes.downloadList.find('dl').removeClass('active');nodes.downloadList.find('div').hide();targetDlNode.addClass('active');targetNode.show();$(targetNode.find('li')[1]).hide().show()}scroll.refresh()}})})();
(function(){var Request={get:function(){var param={"to":"settinger","from":"settingui","cmd":"get"};Base.pcInterface('',param)},set:function(data){var param={"to":"settinger","from":"settingui","cmd":"set","data":data};Base.pcInterface('',param)},setDefault:function(){var param={"to":"settinger","from":"settingui","cmd":"setDefault"};Base.pcInterface('',param)}};var Response={_handles:{},addListener:function(type,handle){if(!this._handles[type]){this._handles[type]=[]}if(typeof handle!='function')return;this._handles[type].push(handle)}};window.addPcListener('settingui',function(param){var fns=Response._handles[param.cmd]||[];for(var i=0,len=fns.length;i<len;i++){fns[i](param)}});Model.Setting={Request:Request,Response:Response}})();
(function(){var nodes={completeShutdown:$('#complete-shutdown')};nodes.completeShutdown.click(function(){$(this).toggleClass('active');Model.Setting.Request.set({completeShutdown:$(this).hasClass('active')?1:0})})})();
(function(){var INTERVAL=2000,_intervalTime;var _downloadingTaskid=[];var nodes={downloadFilter:$('#download-filter')};window.Dialogs={loading:new Widget.Dialog('#loading-advise',{hasShadow:true,shadowEvent:false})};var a='{"from":"downloader","to":"downloadui","cmd":"init","albums":[{"id":"92245","pid":"92245","channel":"juji","picture":"http://i3.letvimg.com/vrs/201405/14/71035e88-5ab7-4a1a-abb3-d99d19985d39.jpg","albumTitle":"古剑奇谭","percent":100.000000,"status":"3","progress":1,"size":1,"speed":0,"items":[{"pcvideopath":"D:\\LETVdownload\\古剑奇谭12.letv","percent":"100","period":"","progress":72317051,"quality":"1000","size":72317051,"speed":0,"status":"3","taskid":"CD789BEC-03C1-4e80-8153-DE0464903A98","title":"12"}]}]}';var isInit=false,addData=null;function main(){addEvent();Base.cache('filterType').set('all');var urlParam=Base.tool.getParamFromUrl();urlParam=urlParam.w||urlParam.j;if(urlParam&&urlParam.isDownload){$.ajax({url:$host+'/api/videoplist',data:{pid:urlParam.pid||0,vid:urlParam.vid},dataType:'jsonp',success:function(result){if(result.code==200){var data=result.data;addData={fromPage:'download',pid:data.pid,albumtitle:data.albumtitle,channel:data.channel,picture:data.picture,items:[{vid:data.vid,title:data.title}]};if(isInit){Model.Download.Request.add(addData)}}}})}}function addEvent(){nodes.downloadFilter.delegate('li','click',function(){if($(this).hasClass('active'))return;$(this).siblings().removeClass('active');$(this).addClass('active');Base.cache('filterType').set($(this).attr('type'))});Model.Download.Response.addListener('blur',function(){nodes.downloadFilter.find('li:first').click()});Base.cache('filterType').subscribe(function(){Dialogs.loading.show();clearInterval(_intervalTime);_downloadingTaskid=[];Model.Download.Request.init()});Model.Download.Response.addListener('init',init);Base.observer('custom').subscribe(init);Model.Download.Response.addListener('add',function(data){if(data.msgType=='data'){var addTaskids=[];data=data.albums;for(var i=0,len=data.length;i<len;i++){var items=data[i].items;$.each(items,function(i,obj){if(obj.status=="1"){addTaskids.push(obj.taskid)}})}updateLoadingTask(addTaskids)}});Model.Download.Response.addListener('statusChange',function(data){var addTaskids=[],delTaskids=[];data=data.albums;for(var i=0,len=data.length;i<len;i++){var items=data[i].items;$.each(items,function(i,obj){if(obj.status=="1"){addTaskids.push(obj.taskid)}else{delTaskids.push(obj.taskid)}})}updateLoadingTask(addTaskids,delTaskids)});Model.Download.Response.addErrorListener('add',function(param){if(param.fromPage!='download')return;if(param.status=='E1'){Widget.advise.info('该视频已在下载列表中')}else{Widget.advise.info(param.msg)}})}function init(data){isInit=true;data=data.albums;for(var i=0,len=data.length;i<len;i++){var tmp=data[i],items=tmp.items;for(var k=0,len2=items.length;k<len2;k++){if(items[k].status==1){_downloadingTaskid.push(items[k].taskid)}}}if(_downloadingTaskid.length){_intervalTime=setInterval(function(){Model.Download.Request.update()},INTERVAL)}if(addData){Model.Download.Request.add(addData);addData=null}}function updateLoadingTask(addTaskids,delTaskids){addTaskids=addTaskids||[];delTaskids=delTaskids||[];var initDownloadingTaskidLength=_downloadingTaskid.length;var index,i,len;for(i=0,len=addTaskids.length;i<len;i++){index=$.inArray(addTaskids[i],_downloadingTaskid);if(index<0){_downloadingTaskid.push(addTaskids[i])}}for(i=0,len=delTaskids.length;i<len;i++){index=$.inArray(delTaskids[i],_downloadingTaskid);if(index>=0){_downloadingTaskid.splice(index,1)}}clearInterval(_intervalTime);if(_downloadingTaskid.length){_intervalTime=setInterval(function(){Model.Download.Request.update()},INTERVAL)}}main()})();
