

var objMmInfo = null;
var intMmCnt = 0;
var intSelMmCnt=0;
var intActMmCnt=0;
var cActIdx=0;
var cActTit="nAnT";
var strMmInfo ="ExoBUD Media Infomation";

var blnfpl=false;
var blnEnabled= false;
var blnEOT=false;
var arrSelMm=null;
var arrActMm=null;
var intExobudStat =0;
var tidTLab=null;
var tidErr=null;
var tidMsg=null;
var intErrCnt=0;
var blnRept=false;
var blnTrimTit =true;
var intTrimLen =20;
var strTrimTit="";


// 是否自动连续播放
var blnAutoProc =true;

// 设定播放面板上所显示的时间样式,以正常方式(Elapse)抑或倒数方式(Lapse)显示：
var blnElaps=true; 

// 设定播放每首曲目之间的延迟时间(Delay Time)，单位是毫秒(msec)。
// 每100毫秒代表0.1秒，默认值是500毫秒(即0.5秒)，最少也要设为100毫秒。
var intDelay =500;

// wmpInit() 函式: 使用 wmp-obj v7.x 链接库建立环境设定
function wmpInit(){
 var wmps = Exobud.settings;
 var wmpc = Exobud.ClosedCaption;

 wmps.autoStart=true;
 wmps.balance=0;
 wmps.enableErrorDialogs=false;
 wmps.invokeURLs = false;
 wmps.mute=false;
 wmps.playCount=1;
 wmps.rate=1;
 wmps.volume = 100;
 if(blnUseSmi){wmpc.captioningID="capText"; capText.style.display="";}
 Exobud.enabled=true;
}

// mkMmPath()绰 Array俊 涝仿瞪 Multi-object甫 积己钦聪促.
function mkMmPath(u, t, f,s){
 this.mmUrl = u;
 this.mmTit =t;
 this.mmDur =0;
 this.selMm=f;
 this.actMm=f;
 if(blnUseSmi){this.mmSmi=s;}
}

//mkList()绰 Multi-object array甫 积己钦聪促.
function mkList(u,t,s,f){
 var cu=u;
 var ct=t;
 var cs=s;
 var cf=f;
 var idx=0;

 if(objMmInfo == null){ objMmInfo=new Array(); idx=0;}
 else{ idx=objMmInfo.length;}
 if(u=="" || u==null){cu="mms://";}
 if(t=="" || t==null){ct="nAnT";}
 if(f=="f" || f=="F"){cf="f";}
 else{cf="t"; intSelMmCnt=intSelMmCnt+1;}

 if(blnUseSmi){ objMmInfo[idx]=new mkMmPath(cu,ct,cf,cs);}
 else{objMmInfo[idx]=new mkMmPath(cu,ct,cf);}

 intActMmCnt=intSelMmCnt;
 intMmCnt=objMmInfo.length;
}

// mkSel()绰 Selected media array棺 Activated media array甫 积己钦聪促.
function mkSel(){
 arrSelMm=null;
 intSelMmCnt=0;
 var selidx = 0;

 if(intMmCnt<=0){intExobudStat=1; blnEnabled=false; return;} //固叼绢府胶飘傍归俊矾

 arrSelMm=new Array();
 for(var i=0; i<intMmCnt;i++){
	if(objMmInfo[i].selMm =="t"){arrSelMm[selidx]=i;selidx=selidx+1;}
 }
 intSelMmCnt=arrSelMm.length;

 if(intSelMmCnt<=0){blnEnabled=false;intExobudStat=2; arrSelMm=null; return;}
 else{blnEnabled=true; mkAct();}
}

// mkAct()绰 Activated media array甫 积己钦聪促.
function mkAct(){
 arrActMm=null;
 intActMmCnt=0;
 var selidx=0;
 var actidx=0;

 if(blnEnabled){
	arrActMm=new Array();
	for(var i=0; i<intSelMmCnt;i++){
		selidx=arrSelMm[i];
		if(objMmInfo[selidx].actMm=="t"){arrActMm[actidx]=selidx; actidx=actidx+1;}
	}
	intActMmCnt=arrActMm.length;
 }
 else{return;}
 if(intActMmCnt<=0){blnEOT=true;arrActMm=null;}
 else{blnEOT=false;}
}


//chkAllSel()篮 葛电 Item阑 Selected Item栏肺 傈券钦聪促.
function chkAllSel(){
 for(var i=0; i<intMmCnt; i++){
   objMmInfo[i].selMm="t";
   objMmInfo[i].actMm="t";
 }
 mkSel();
}

//chkAllDesel()篮 葛电 Item阑 Deselected Item栏肺 傈券钦聪促.
function chkAllDesel(){
 for(var i=0; i<intMmCnt; i++){
   objMmInfo[i].selMm="f";
   objMmInfo[i].actMm="f";
 }
 mkSel();
}

// chkItemSel()篮 Selected media 甫 汲沥 肚绰 秦力钦聪促.
function chkItemSel(idx){
 if(objMmInfo[idx].selMm =="t"){objMmInfo[idx].selMm="f";objMmInfo[idx].actMm="f";}
 else{objMmInfo[idx].selMm="t";objMmInfo[idx].actMm="t";}
 mkSel();
}

// chkItemAct()绰 Activated等 media甫 悼搬钦聪促.
function chkItemAct(idx){
 objMmInfo[idx].actMm="f";
 mkAct();
}

// mkSelAct()绰 Selected Media甫 activated media肺 汲沥钦聪促.
function mkSelAct(){
 var idx=0;
 for(var i=0; i<intSelMmCnt; i++){
	idx=arrSelMm[i];
	objMmInfo[idx].actMm="t";
 }
 mkAct();
}

// initExobud()绰 ExoBUD MP(II) 胶农赋飘甫 檬扁拳 钦聪促.
function initExobud(){
 wmpInit();
 mkSel();
 blnfpl=false;
 if(blnShowVolCtrl == false) {
	document.images['vmute'].style.display = "none";
	document.images['vdn'].style.display = "none";
	document.images['vup'].style.display = "none";
 }
 if(!blnShowPlist){document.images['plist'].style.display = "none";}

 if(blnRept){imgChange('rept',1);}
 else{imgChange('rept',0);}

 if(blnRndPlay){imgChange('pmode',1);}
 else{imgChange('pmode',0);}
 showTLab();
 disp1.innerHTML="ExoBUD MP(II) v4.1tc+ 网站媒体播放程序";
 if(blnStatusBar){window.status=('椎?曳?瞍?麟郫酗');}
 if(blnAutoStart){startExobud();}

}

// startExobud()绰 扁夯利牢 固叼绢 犁积阑 矫累钦聪促.
function startExobud(){
 var wmps= Exobud.playState;
 if(wmps==2){Exobud.controls.play(); return;} //老矫沥瘤老锭
 if(wmps==3){return;} // 犁积吝老锭 

 blnfpl=false;
 if(!blnEnabled){waitMsg();return;}
 if(blnEOT){mkSelAct();}
 if(intErrCnt>0){intErrCnt=0;tidErr=setTimeout('retryPlay(),1000');return;}
 if(blnRndPlay){rndPlay();}
 else{cActIdx=arrActMm[0]; selMmPlay(cActIdx);}
}


// selMmPlay()绰 Selected - Activated Medium阑 犁积钦聪促.
function selMmPlay(idx){
 clearTimeout(tidErr);
 cActIdx=idx;
 var trknum=idx+1;
 var ctit =objMmInfo[idx].mmTit;
 if(ctit=="nAnT"){ctit="Title 棺 Author 眠么吝..."}
 if(blnUseSmi){Exobud.ClosedCaption.SAMIFileName = objMmInfo[idx].mmSmi;}
 Exobud.URL = objMmInfo[idx].mmUrl;
 cActTit="背景音乐： "+ trknum + ". " + "《"+ctit+"》";
 disp1.innerHTML = cActTit;
 if(blnStatusBar){window.status=(cActTit);}
 chkItemAct(cActIdx); 
}

// wmpPlay()绰 wmp-obj v7.x 犁积窃荐涝聪促.
function wmpPlay(){Exobud.controls.play();}

// wmpStop()篮 犁积阑 吝瘤窍绊 措扁惑怕肺 傈券钦聪促.
function wmpStop(){
 intErrCnt=0;
 clearTimeout(tidErr);
 clearInterval(tidTLab);
 imgChange("stopt",1);
 imgChange("pauzt",0);
 imgChange("scope",0);
 showTLab();
 mkSelAct();
 Exobud.controls.stop();
 Exobud.close();
 disp1.innerHTML="网站媒体播放程序 [就绪]";
 if(blnStatusBar){window.status=('网站媒体播放程序 [就绪]');return true;}
}

// wmpPause()绰 wmp-obj v7.x 老矫沥瘤 窃荐涝聪促.
function wmpPause(){Exobud.controls.pause();}

// wmpPP()绰 老矫沥瘤.犁积阑 困茄 配臂窃荐涝聪促.
function wmpPP(){
	var wmps = Exobud.playState;
	var wmpc=Exobud.controls;
	clearInterval(tidTLab);
	clearTimeout(tidMsg);
	if (wmps == 2) {wmpc.play();}
	if (wmps == 3) {wmpc.pause();disp2.innerHTML="Pause"; tidMsg=setTimeout('rtnTLab()',1500);}
	return;
}


//rndPlay()绰 公累困犁积(Random play)甫 矫累钦聪促.
function rndPlay(){
 if(!blnEnabled){waitMsg();return;}
 intErrCnt=0;
 var idx=Math.floor(Math.random() * intActMmCnt);
 cActIdx= arrActMm[idx];
 selMmPlay(cActIdx);
}

//playAuto()绰 Activated Media甫 磊悼栏肺 背眉钦聪促.
//胶农赋飘 惑窜狼 blnAutoProc 汲沥俊蝶扼 磊悼楷加犁积 汲沥阑 函版且 荐 乐嚼聪促.
function playAuto(){
 if(blnRept){ selMmPlay(cActIdx); return;}
 if(!blnAutoProc){wmpStop();return;}
 if(blnfpl){wmpStop(); return;} //wmpStop()措脚 wmpNext()肺 汲沥窍搁 促弗 犁积 肺流 啊瓷
 if(!blnEnabled){wmpStop();return;}
 if(blnEOT){ if(blnLoopTrk){startExobud();}
	   else{wmpStop();}
 }
 else{  if(blnRndPlay){rndPlay();}
	else{cActIdx= arrActMm[0]; selMmPlay(cActIdx);}
 }
}

// Play a user selected element from the playlist
function selPlPlay(idx){
 blnfpl=true;
 selMmPlay(idx);
}


// playPrev()绰 activated medium 捞傈狼 Selected Medium阑 馆券钦聪促.
function playPrev(){
 var wmps= Exobud.playState;
 if(wmps==2 || wmps==3){Exobud.controls.stop();}
 blnfpl=false;
 if(!blnEnabled){waitMsg();return;}
 if(blnEOT){mkSelAct();}

 intErrCnt=0;
 if(blnRndPlay){rndPlay();}
 else{	var idx=cActIdx;
 	var blnFind=false;
	for(var i=0;i<intSelMmCnt;i++){if(cActIdx==arrSelMm[i]){idx=i-1; blnFind=true;}}
	if(!blnFind){startExobud();return;}
	if(idx<0){idx=intSelMmCnt-1;cActIdx=arrSelMm[idx];}
	else{cActIdx=arrSelMm[idx];}
	selMmPlay(cActIdx);
 }
}

// playNext()绰 activated medium 捞饶狼 Selected Medium阑 馆券钦聪促.
function playNext(){
 var wmps= Exobud.playState;
 if(wmps==2 || wmps==3){Exobud.controls.stop();}
 blnfpl=false;
 if(!blnEnabled){waitMsg();return;}
 if(blnEOT){mkSelAct();}

 intErrCnt=0;
 if(blnRndPlay){rndPlay();}
 else{	var idx=cActIdx;
 	var blnFind=false;
	for(var i=0;i<intSelMmCnt;i++){	if(cActIdx==arrSelMm[i]){idx=i+1; blnFind=true;}}
	if(!blnFind){startExobud();return;}
	if(idx>=intSelMmCnt){idx=0;cActIdx=arrSelMm[idx];}
	else{cActIdx=arrSelMm[idx];}
	selMmPlay(cActIdx);
 }
}


//retryPlay()绰 Activated medium俊 措茄 犁积阑 矫档钦聪促.
function retryPlay(){
  selMmPlay(cActIdx);
}


//chkRept()绰 Activated medium狼 馆汗 犁积 咯何甫 函版钦聪促.
function chkRept(){
 var wmps=Exobud.playState;
 if(wmps == 3){clearInterval(tidTLab);}
 if(blnRept){blnRept=false; imgChange('rept',0);disp2.innerHTML="不重复播放";}
 else{blnRept=true; imgChange('rept',1);disp2.innerHTML="重复播放";}
 tidMsg= setTimeout('rtnTLab()',1000);
}


// chgPMode()绰 犁积葛靛(Sequential / Random)甫 函版钦聪促.
function chgPMode(){
 var wmps=Exobud.playState;
 if(wmps == 3){clearInterval(tidTLab);}
 if(blnRndPlay){blnRndPlay=false; imgChange('pmode',0);disp2.innerHTML="循环播放";}
 else{blnRndPlay=true; imgChange('pmode',1);disp2.innerHTML="随机播放";}
 tidMsg=setTimeout('rtnTLab()',1000); 
}


function evtOSChg(f){
// 0(Undefined) 8(MediaChanging) 9(MediaLocating) 10(MediaConnecting) 11(MediaLoading) 
// 12(MediaOpening) 13(MediaOpen) 20(MediaWaiting) 21(OpeningUnknownURL)

 if(f==8){capText.innerHTML="<br><br><br><br><br><br>ExoBUD MP -II<br> Captioning (SMI)";}
 if(f==13){
	var strTitle = Exobud.currentMedia.getItemInfo("title");
	if(strTitle.length <=0){strTitle = "(力格) 舅荐绝澜"}
	var strAuthor = Exobud.currentMedia.getItemInfo("Author");
	if(strAuthor.length <=0){strAuthor = "(啊荐) 舅荐绝澜"}
	var strCopy = Exobud.currentMedia.getItemInfo("Copyright");
	if(strCopy.length <=0){strCopy = "(历累鼻磊) 舅荐绝澜"}
	var strType = Exobud.currentMedia.getItemInfo("MediaType");
	var strDur=Exobud.currentMedia.durationString;
	var strUrl =Exobud.URL;
	var trknum=cActIdx+1;
	var ctit = objMmInfo[cActIdx].mmTit;
	if(ctit=="nAnT"){ objMmInfo[cActIdx].mmTit = strAuthor + " - " + strTitle;
		ctit=strAuthor + " - " + strTitle;
		cActTit="T"+ trknum + ". " +ctit;
		disp1.innerHTML = cActTit;
	}

	strMmInfo= "Media (Title) : " + strTitle + " (屈侥:" + strType +")" + "\n\n"
	strMmInfo= strMmInfo + "Media (Author) : " + strAuthor + "\n\n"
	strMmInfo= strMmInfo + "Media (URL) : " +strUrl + "\n\n"
	strMmInfo= strMmInfo + "Media (Copyright) : " + strCopy +"\n\n" 
	strMmInfo= strMmInfo + "Media (Duration) : " +strDur +"\n\n";
	strMmInfo= strMmInfo + " (C) Copyright ExoBUD⑩ MPlayer(II) 1999-2003  \n";
	if(blnShowMmInfo){alert(strMmInfo);}
 }
}


function evtPSChg(f){
// 0(Undefined) 1(Stopped) 2 (Paused) 3(Playing) 4(ScanFowrd) 5(ScanReverse)
// 6(Buffering) 7(Waitng) 8(MediaEnded) 9(Transitioning) 10(Redy)

 switch(f){
	case 1:
		evtStop();
		break;
	case 2:
		evtPause();
		break;
	case 3:
		evtPlay();
		break;
	case 8:
		setTimeout('playAuto()', intDelay);
		break;
 }
}


//evtWmpBuff() 函式: 对媒体档案进行缓冲处理(Buffering)的动作
function evtWmpBuff(f){
	 if(f){ disp2.innerHTML = "缓冲处理中";
		var msg="(缓冲处理中) " + cActTit;
		disp1.innerHTML = msg;
		if(blnStatusBar){window.status=(msg);}
	}
	else{ disp1.innerHTML = cActTit; showTLab();}
}


//evtWmpError() 函式: 当无法联机到媒体档案时，显示错误讯息
function evtWmpError(){
 intErrCnt=intErrCnt+1;
 Exobud.Error.clearErrorQueue();
 if(intErrCnt<=3){
	disp2.innerHTML="尝试联机("+intErrCnt+")";
	var msg="(尝试第:" + intErrCnt +"次联机) " +cActTit;
	disp1.innerHTML="<无法播放> " +cActTit;
	if(blnStatusBar){window.status=(msg);}
	tidErr=setTimeout('retryPlay()',1000);
 }
 else{	clearTimeout(tidErr);
	intErrCnt=0;showTLab();
	var msg="已放弃尝试再联机。现在将会播放下一首曲目。";
	if(blnStatusBar){window.status=(msg);}	
	setTimeout('playAuto()',1000);}
}

function evtStop(){
	clearTimeout(tidErr);
	clearInterval(tidTLab);
	showTLab();
	intErrCnt=0;
	imgChange("pauzt",0);
	imgChange("playt",0);
	imgChange("scope",0);
	disp1.innerHTML="ExoBUD MP(II) v4.1tc+ [等待播放下一首曲目]";
	if(blnStatusBar){window.status=(' ');return true;}
}

function evtPause(){
 imgChange("pauzt",1)
 imgChange("playt",0);
 imgChange("stopt",0);
 imgChange("scope",0);
 clearInterval(tidTLab);
 showTLab();
}

function evtPlay(){
 imgChange("pauzt",0)
 imgChange("playt",1);
 imgChange("stopt",0);
 imgChange("scope",1);
 tidTLab=setInterval('showTLab()',1000);
}

//showTLab() 函式: 显示时间长度
function showTLab(){
 var ps=Exobud.playState;
 if(ps==2 || ps==3){
	var cp=Exobud.controls.currentPosition
	var cps=Exobud.controls.currentPositionString
	var dur=Exobud.currentMedia.duration;
	var durs=Exobud.currentMedia.durationString;
	if(blnElaps){disp2.innerHTML= cps+" | "+durs;
		var msg=cActTit + " ("+cps+" | "+durs+ ")";
		if(ps==2){msg="(暂停) "+ msg;}
		if(blnStatusBar){window.status=(msg);return true;}
	}
	else{var laps= dur-cp; 
		var strLaps=wmpTime(laps);
		disp2.innerHTML= strLaps + " | "+durs;
		var msg= cActTit + " (" + strLaps + " | "+durs + ")";
		if(ps==2){msg="(暂停) "+ msg;}
		if(blnStatusBar){window.status=(msg);return true;}
	}

 }
 else{disp2.innerHTML="00:00 | 00:00";}
}

// chgTimeFmt() 函式: 变更时间长度的显示方式
function chgTimeFmt(){
 var wmps=Exobud.playState;
 if(wmps == 3){clearInterval(tidTLab);}
 if(blnElaps){blnElaps=false; disp2.innerHTML="Laps";}
 else{blnElaps=true;disp2.innerHTML="ELaps";}
 tidMsg=setTimeout('rtnTLab()',1000); 
}

// rtnTLab() 函式: 传回时间长度
function rtnTLab(){
clearTimeout(tidMsg);
var wmps=Exobud.playState;
if(wmps == 3){tidTLab=setInterval('showTLab()',1000);}
else{showTLab();}
}

function wmpTime(dur){
	var hh, min, sec, timeLabel
	hh = Math.floor(dur/3600);
	min = Math.floor(dur / 60)%60;
	sec = Math.floor(dur % 60);
	if (isNaN(min)){ return "00:00"; }
	if (isNaN(hh) || hh==0){timeLabel="";}
	else{
		if(hh >9){timeLabel = hh.toString()+":";}
		else{timeLabel="0"+hh.toString() +":";}
	}
  	if ( min > 9 ){  timeLabel = timeLabel + min.toString() + ":"; }
	else {timeLabel = timeLabel + "0" +min.toString() + ":";}
	if ( sec > 9 ){timeLabel = timeLabel + sec.toString();}
	else{timeLabel = timeLabel + "0" + sec.toString();}
	return timeLabel;
}


// wmpVolUp(), wmpVolDn(), wmpMute() 这几个都是用来调校音量的函式。(单位：％)
// vmax 代表最大音量(100), vmin 代表最小音量(0), vdep 代表调校音量的间隔(建议设为5至20之间)
// 您只可以在 vmin, vmax, vdep 设为0至100之间的整数数值，vmin 和 vdep 数值不可以大过 vmax。


var vmax = 100;
var vmin=0;
var vdep = 10;

function wmpVolUp(){  
	var wmps=CnSideBud.playState;
	if(wmps == 3){clearInterval(tidTLab);}
	var ps = CnSideBud.settings;
	if(ps.mute){ps.mute = false; disp2.innerHTML="Speach";imgChange('vmute',0);}
	else{
		if (ps.volume >= (vmax-vdep)) {ps.volume = vmax;}
		else {  ps.volume = ps.volume + vdep;}
		disp2.innerHTML="Vol. " + ps.volume +"%";
	}
	tidMsg=setTimeout('rtnTLab()',1000);
}

function wmpVolDn(){ // ExoBUD⑩ MP(II) Volume Down 
	var wmps=Exobud.playState;
	if(wmps == 3){clearInterval(tidTLab);}
	var ps = Exobud.settings;
	if(ps.mute){ps.mute = false;disp2.innerHTML="Speach";imgChange('vmute',0);}
	else{
		if (ps.volume <= vdep){ ps.volume = vmin;}
		else{ps.volume = ps.volume - vdep;}
		disp2.innerHTML="Vol. " + ps.volume +"%";
	}
	tidMsg=setTimeout('rtnTLab()',1000);
}


function wmpMute(){ // ExoBUD⑩ MP(II) Mute 
	var wmps=Exobud.playState;
	if(wmps == 3){clearInterval(tidTLab);}
	var ps = Exobud.settings;
	if(!ps.mute){ps.mute = true;disp2.innerHTML="Mute On"; imgChange("vmute", 1);}
	else {ps.mute = false;disp2.innerHTML="Mute Off"; imgChange("vmute", 0)}
	tidMsg=setTimeout('rtnTLab()',1000);
}

function waitMsg(){
 capText.innerHTML="ExoBUD⑩ MP(II) Captioning(SMI)";
 if(intExobudStat ==1){disp1.innerHTML="无法播放 － 播放清单上没有设定任何曲目。";}
 if(intExobudStat ==2){disp1.innerHTML="无法播放 － 您没有选取播放清单上任何一首曲目。";}
 if(blnStatusBar){
	if(intExobudStat ==1){window.status=('无法播放 － 播放清单上没有设定任何曲目。');return true;}
	if(intExobudStat ==2){window.status=('无法播放 － 您没有选取播放清单上任何一首曲目。'); return true;}
 }
}


function openPlist() { // ExoBUD⑩ MP(II) List Popping Up
	window.open("exobudpl.html" , "mplist", "top=125px, left=320px, width=280 , height=500 ,scrollbars=auto , resizable=no , copyhistory=no");
}


// chkWmpState()绰 wmp俺眉狼 犁积 惑怕 溜, playState 蔼阑 馆券钦聪促.
// chkWmpOState() 绰 wmp 俺眉狼 固叼绢狼 俺规(open)惑怕 溜, openState 蔼阑 馆券钦聪促.

function chkWmpState(){
// 0(Undefined) 1(Stopped) 2 (Paused) 3(Playing) 4(ScanFowrd) 5(ScanReverse)
// 6(Buffering) 7(Waitng) 8(MediaEnded) 9(Transitioning) 10(Redy)
 return Exobud.playState;
}

function chkWmpOState(){
// 0(Undefined) 8(MediaChanging) 9(MediaLocating) 10(MediaConnecting) 11(MediaLoading) 
// 12(MediaOpening) 13(MediaOpen) 20(MediaWaiting) 21(OpeningUnknownURL)
 return Exobud.openState;
}

function chkOnline(){
// true(Network Connected) false(Network Lost)
return Exobud.isOnline;
}

function vizExobud(){
//Exobud.launchURL("http://intorock.3mm.net");
  window.open("http://intorock.3mm.net","vizExobud");
}
