yun.tabObjList=function(id){
	this.id=id;
	$(id).onclick=function (){
		var el=event.srcElement;
		if(el.tagName!='DT'||el.className=='rBot'){return}
		with(this){
		var a3=findNode(el,'tabOn');
		if(a3!=null){
			a3[0].className='tabOff';
			a3[1].style.display='none';
		}
		el.className='tabOn';
		try{findNode(el).style.display='block'}catch(e){}
		}
	}.bind(this);
	$(id).onmouseover=$(id).onclick.bind(this);
	this.findNode=function (el,cName){
		var dl=$(this.id)
		var a1=dl.getElementsByTagName('dt');
		var a2=dl.getElementsByTagName('dd');
		for(var n=0;n<a2.length;n++){
			if(cName){if(a1[n].className==cName){return [a1[n],a2[n]]}}
			else{if(el==a1[n]){return a2[n]}}
		}
		return null
	}
	this.doClick=function(n){
		try{var dl=$(this.id).getElementsByTagName('dt')[n].click()}catch(e){}
	}
}
//分类目录菜单
yun.LiteTree=function(id){
	var et=id;
	this.init=function(){
		var a=$(et).getElementsByTagName('li');
		var li;
		var kbd;
		for(var n=0;n<a.length;n++){
			li=a[n];
				kbd=$CE('KBD','&nbsp;');
				li.insertBefore(kbd,li.firstChild);
				if(!this.isRoot(li)){kbd.className='subLeaf'}
			if(this.isSubTree(li)){
				kbd.onclick=this.toggle;
				kbd.className=li.className.indexOf('On')>-1?'subOn':'subOff';
			}
			if(!li.className.test(/On|Off/)){li.className+=' Off'}//将没有指定显示的UL 标记为隐藏
		}
	}
	this.toggle=function(){
		if(!this.className.test(/subOff|subOn/)){return}
		var el=this.parentNode;
		if(el.className.indexOf('On')>-1){
			el.className=el.className.replace(/On/,'');
			el.className+=' Off';this.className='subOff'}
		else{
			el.className=el.className.replace(/Off/,'');
			el.className+=' On';this.className='subOn';
		}
	}
	this.isSubTree=function(li){return li.getElementsByTagName('ul').length>0?1:0}
	this.isRoot=function(li){return li.parentNode.parentNode.tagName=='LI'?0:1}
}

//纯文字浏览模式，toolTip实现
yun.LIColor=function(id,CN1,CN2){
	this.timer=null;
	$(id).onmouseover=function(){
		var el=this.getLIElement(event.srcElement);
		if(!el){return}
		this.showTip();
		var a=Position.getAbsRect(el);
		tp.style.left=getAbsX()+10+'px';
		tp.style.top=a[3]-6+'px';
		el.className=CN1;
		try{if(lastLI==el){return}
		el.title='';
		tp.innerHTML=this.paresId(el)
		lastLI.className=CN2}catch(e){}lastLI=el
		}.bind(this);
	$(id).onmouseout=function(){var el=event.srcElement;try{lastLI.className=''}catch(e){}
	this.hideTip()}.bind(this);

	this.getLIElement=function(el){
		if(el.tagName == 'UL'){
			return;
			}
		while(el.tagName!='LI'){
			if(el.className=='head'){return null}
			el=el.parentNode
			}
	return el.className=='head'?null:el}
	this.hideTip=function(s){
		if(s){tp.className='';return}
		this.timer=setTimeout('tp.className=""',200)}
	this.showTip=function(){
		clearTimeout(this.timer)
		this.timer=setTimeout('tp.className="on"',200)
	}
	tp.onmouseover=function(e){
		this.showTip();
	}.bind(this);
	tp.onmouseout=function(e){this.hideTip()
	}.bind(this);
	this.paresId=function(li){
		var o=li.id.toObject();
		var now=this.getCurrentInfo(li);
		//alert(o['ResourceID'])
		var capImg = o['ResourceID']!=undefined ? 'http://vod.pplive.com/pic/'+o['ResourceID']+'/0/2.jpg' : 'http://pic.pplive.com/capture_' + o.id + '_200_150.html';
		now=now?'<a href="#1" class="playBtn" onclick="yun.playChannel('+o.id+')">&nbsp;</a>'+now:'当前没有节目播出';
		var nxt=o.next;
		//alert(o.next);
nxt=nxt?'<a href="#1" class="playBtnOff">&nbsp;</a><i>'+(o.time?o.time:'')+'</i><a href="channel_'+o.id+'.html">'+o.next+'</a>':'对不起，当前节目没有节目单';
return '<a href="channel_'+o.id+'.html" class="imgLink"><img src="{0}" alt="{0}" /></a><p>{1}</p><p>{2}</p><p>{3}</p>'.format(capImg,
	now,nxt,'<a href="http://www.pplive.com/zh-cn/channelepg.html?' + o.id + '" class="moreIntro">更多节目...</a>')
	}
	this.getCurrentInfo=function(li){return li.getElementsByTagName('h2')[0].innerHTML}
}

//全图片浏览模式
yun.TABColor=function(id,CN1,CN2){
	this.timer=null;
	$(id).onmouseover=function (){
		var el=event.srcElement
		if(el.tagName=='DIV'){return}
		el=this.getTABElement(el);
		if(!el){return}
		el.className=CN1;
		try{if(lastTab==el){return}lastTab.className=CN2}catch(e){}
		lastTab=el
		}.bind(this);
	$(id).onmouseout=function(){var el=event.srcElement;try{lastTab.className=''}catch(e){}}.bind(this);
	this.getTABElement=function(el){while(el.tagName!='TABLE'){el=el.parentNode}return el}
}

yun.toggleInfo=function(el){
	var s=el.parentNode.className;
	el.parentNode.className=s=='On'?'Off':'On';
	if(el.rel=="返回"){
		el.rel=el.innerHTML
		el.innerHTML="返回"
	}
	else{
		el.innerHTML=el.rel;
		el.rel="返回"
	}
}

yun.LIColor2=function(id,CN1,CN2){
	$(id).onmouseover=function(){
		var el=this.getLIElement(event.srcElement);
		if(!el){return}
		el.className=CN1;
		try{if(lastLI==el){return}
		lastLI.className=CN2}catch(e){}lastLI=el}.bind(this);
	$(id).onmouseout=function(){var el=event.srcElement;try{lastLI.className=''}catch(e){}}.bind(this);
	this.getLIElement=function(el){
		while(el.tagName!='LI'){if(el.className=='head'||el.tagName=="UL"){return null}el=el.parentNode}
	return el.className=='head'?null:el}
}

var ctview={
	ar:null,
	grayType:function(){with(this){ar[0].className='icoFlat0';ar[1].className='icoList0';ar[2].className='icoPic0'}},
	graySort:function(){with(this){ar[3].className='icoTime0';ar[4].className='icoHot0';ar[5].className='icoQua0',ar[6].className='icoVote0'}},
	init:function(){
		var s=location.href;
		this.ar=$('viewTypes').getElementsByTagName('a'),
		this.grayType();this.graySort();
		with(this){
		if(s.test(/_textlist/ig)){ar[0].className='icoFlat1'}
		if(s.test(/_complex/ig)){ar[1].className='icoList1'}
		if(s.test(/_imglist/ig)){ar[2].className='icoPic1'}
		if(s.test(/_playtime/ig)){ar[3].className='icoTime1'}
		if(s.test(/_peercount/ig)){ar[4].className='icoHot1'}
		if(s.test(/_quatity/ig)){ar[5].className='icoQua1'}
		if(s.test(/_favorite/ig)){ar[6].className='icoVote1'}
		}
	}
};

//检测播放器
yun.isPPInstalled = 'notchecked';
function checkPPinstall(){
	try{
		SynaObj = new ActiveXObject("Synacast.EWA");
		if(SynaObj.version)	//user have installed PPLive
			{
			yun.isPPInstalled=true;
			//SynaObj.Destroy();
			SynaObj=null;
			return 1;
			}
	}
	catch(e){
		yun.isPPInstalled = false;
		return false;
		}
	//return 0;
}
//checkPPinstall();
//直接的播放函数,不检测
yun.playChannel = function(cid){
	var pf = $('playFrame');
	if(!pf){
		pf = document.createElement('iframe');
		pf.id = 'playFrame';
		pf.style.display = 'none';
		pf.src = 'http://www.pplive.com/public/synacast_' + cid + '.html?r=' + Math.random();
		document.body.appendChild(pf);
		return;
	}
	pf.style.display = 'none';
	pf.src = 'http://www.pplive.com/public/synacast_' + cid + '.html?r=' + Math.random();
}

//检测浏览器与客户端安装的播放函数,检测放在window onload之后,可能会有延迟
yun.cCheckPlay = function(cid){
	//无论是否符合安装条件，都跳转向ikan  2008-07-21 14:10:56
	window.open('http://ikan.pplive.com/play/live/' +cid,'_blank');
	return;
	if(!isIE){
		alert('你不是IE浏览器,请更换为IE浏览器再播放');
		return false;
		}
	//如果还没完成检测
	if(yun.isPPInstalled == 'notchecked'){
		alert('已尝试打开PPLive播放器,如果你还没有安装PPLive客户端,请下载安装之后再尝试');
		yun.playChannel(cid);
		return false;
		}
	//检测完成并且没有安装客户端
	if(!yun.isPPInstalled&&isIE){
		alert('亲爱的用户，您还没有安装pplive最新客户端，无法正常观看网络电视。点击“确定“进入下载页面');
		window.open('http://www.pplive.com/zh-cn/download.html');
		return false;
		}
	//  改由ikan播放2008-07-21 14:00:34
	//yun.playChannel(cid);
	window.open('http://ikan.pplive.com/play/live/' +cid,'_blank');
	}
yun.extend({
	trimStrByWidth:function(str,width,size){
		var l=str.Tlength();
		var reg=/[WM\@\#\&]/g;
		var a=str.match(reg);
		l+=a?(a.length):0;
		reg=/[A-LN-VX-Z]/g;
		a=str.match(reg);
		l+=a?(a.length/1.6):0;
		reg=/[wm]/g;
		a=str.match(reg);
		l+=a?(a.length/1.5):0;
		reg=/[\d]/g;
		a=str.match(reg);
		l+=a?(a.length/2.0):0;
		l=l*(size/2.2);
		if(l>width){
			var n=l-width;
			n=n/(size);
			return str.substring(0,str.length-n-1)+'...'
		}
		return str
	},
	getTimeString:function(t,n,date1,date2){
			var ca=['秒前','分钟前','小时前','天前','个月前'];
			t=t<1?180000:t;
			var vm=[31,28,31,30,31,30,31,31,30,31,30,31];
			switch(n){
				case 0:
					return t+ca[0];
				break;
				case 1:
					return t+ca[1];
				break;
				case 2:
					if(date1.getHours()-t<0){return '昨天'}
					return t+ca[2];
				break;
				case 3:
					if(t>20&&date1.getMonth()-date2.getMonth()>0){return '上个月'}
					return t+ca[3];
				break;
				case 4:
					return t+ca[4];
				break;
				default:
				return '3分钟前'
			}
		},
	parseTime:function(date1,date2){
		date1=Date.load(date1);
		date2=Date.load(date2);
		var arrD=Date.getTimeSpan(date1,date2);
		if(arrD[1]==1){
			arrD[2]+=12;
			if(arrD[2]>10){return '去年'}}
			if(arrD[1]>1){return arrD[1]+'年前'}
			//刚过完一年，相差不到10个月的时候
		var S=1000;
		var Min=60*S;
		var H=Min*60;
		var D=H*24;
		var M=D*30;
		var Y=D*365;
		var ta=[S,Min,H,D,M,Y];
		var ca=['秒前','分钟前','小时前','天前','月前'];
		for(var n=0;n<ta.length;n++){
			if(arrD[0]/ta[n]<1){
				n--;
				try{return (this.getTimeString((arrD[0]/ta[n]).toInt(),n,date1,date2))}
				catch(e){return '1分钟前'}
				}
			}
	}
});
