// JavaScript Document
function getOLeft(myObj){
	curObj = myObj;
	var objLT = curObj.offsetLeft;
	while(curObj!=curObj.offsetParent && curObj.offsetParent){
		curObj=curObj.offsetParent;
		if(curObj.tagName=="DIV" || curObj.tagName=="TABLE" || curObj.tagName=="TR" || curObj.tagName=="TD"){
			objLT += curObj.offsetLeft;
		}
	}
	return objLT;
}

function toPlay(){
	if(document.MediaPlayer.FileName==""){
		changeMedia(getObj("MediaPlayer").title,0);
	}else{
		if(mediaIndex>0){
			getObj("hideScreen").childNodes[0].src = pixArray[mediaIndex];
			getObj("hideScreen").style.display = "block";
			getObj("myScreen").style.display = "none";
		}else{
			getObj("hideScreen").style.display = "none";
			getObj("myScreen").style.display = "block";
		}
		if (document.MediaPlayer.playState !=2){
			document.MediaPlayer.Play();
		}
	}
}

function toStop(){
	getObj("hideScreen").childNodes[0].src = pixArray[mediaIndex];
	getObj("hideScreen").style.display = "block";
	getObj("myScreen").style.display = "none";
	document.MediaPlayer.Stop();
}

function toMute(){
	if(document.MediaPlayer.Mute.toString().toLowerCase()=='true'){
		document.MediaPlayer.Mute='False';
		getObj("muteControl").src = "img/player/player_mute.gif";
		getObj("muteControl").alt = "¹Ø±ÕÉùÒô";
	}else{
		document.MediaPlayer.Mute='True';
		getObj("muteControl").src = "img/player/player_silent.gif";
		getObj("muteControl").alt = "´ò¿ªÉùÒô";
	}
}

function mouseDown(){
	pFlag = true;
	if(window.event.srcElement.id!="pZone") 
		getObj("pBox").style.left = getObj("pBox").offsetLeft;
	else 
		getObj("pBox").style.left = (window.event.x)-9;
}

function mouseMove(){
			if(pFlag) getObj("pBox").style.left = window.event.clientX - getOLeft(getObj("pZone")) - 9 +"px"; 
			if (parseInt(getObj("pBox").style.left.replace("px","")) > pZoneWidth) getObj("pBox").style.left=pZoneWidth +"px";
			if (parseInt(getObj("pBox").style.left.replace("px","")) < 0) getObj("pBox").style.left=0;
}
	
function mouseUp(){
	if (pFlag){
		tempVol = (pZoneWidth/2-parseInt(getObj("pBox").style.left))*(-15)-623;
		document.MediaPlayer.Volume=Math.round(tempVol);
}
	pFlag = false;
}

function mouseEnd(){
	if(document.MediaPlayer.Duration>0){
		window.event.returnValue = false;
	}
}

//drag func

function startdrag(){
	if(document.MediaPlayer.Duration||(!isNaN(document.MediaPlayer.Duration))){
		window.document.onmousemove = mouseMove;
		window.document.ondragstart = mouseEnd;
		window.document.onmouseup = mouseUp;
	}
}

function changeMedia(u,r){
	if(typeof(r)!="undefined"){
		mediaIndex = r;
	}
	toStop();
	document.MediaPlayer.FileName=u;
	playerInterval = setInterval(checkState,500);
	//setTimeout(toPlay,1000);
}

function checkState(){
	if(document.MediaPlayer.playState==3){
		clearInterval(playerInterval);
		toPlay();
	}
}

function InitPlayer(id,type,urltype){
	document.MediaPlayer.FileName=getObj("MediaPlayer").title;
	toStop();
	window.document.onmousemove = mouseMove;
	window.document.ondragstart = mouseEnd;
	window.document.onmouseup = mouseUp;
	var url="";
	var ison="0";
	if(urltype=="1"){
			if(type==1){
				if(id==0){
					url="http://www.eootv.com/2008/img/SZTV_CT.asx";
				}else if(id==8){
					url="http://www.eootv.com/2008/img/SZTV-M_CT.asx";
				}else if(id==9){
					url="http://www.eootv.com/2008/img/SZTV-D_CT.asx";
				}else if(id==11){
					url="http://www.eootv.com/2008/img/SZTV-E_CT.asx";
				}else if(id==1){
					if(ison==1){
						url="#";
					}else{
						url="http://www.eootv.com/2008/img/SZTV-"+ id+"_CT.asx";
					}
				}else{
					url="http://www.eootv.com/2008/img/SZTV-"+id+"_CT.asx";
				}
			}else if(type==2){
				url="http://www.eootv.com/2008/img/SZR-"+ id+"_CT.asx";
			}
	}else if(urltype=="2"){
			if(type==1){
				if(id==0){
					url="http://www.eootv.com/2008/img/SZTV_CNC.asx";
				}else if(id==8){
					url="http://www.eootv.com/2008/img/SZTV-M_CNC.asx";
				}else if(id==9){
					url="http://www.eootv.com/2008/img/SZTV-D_CNC.asx";
				}else if(id==11){
					url="http://www.eootv.com/2008/img/SZTV-E_CNC.asx";
				}else if(id==1){
					if(ison==1){
						url="#";
					}else{
						url="http://www.eootv.com/2008/img/SZTV-"+ id+"_CNCasx";
					}
				}else{
					url="http://www.eootv.com/2008/img/SZTV-"+id+"_CNC.asx";
				}
			}else if(type==2){
				url="http://www.eootv.com/2008/img/SZR-"+ id+"_CNC.asx";
			}
	}else{
			if(type==1){
				if(id==0){
					url="http://www.eootv.com/2008/img/SZTV_CNC.asx";
				}else if(id==8){
					url="http://www.eootv.com/2008/img/SZTV-M_CNC.asx";
				}else if(id==9){
					url="http://www.eootv.com/2008/img/SZTV-D_CNC.asx";
				}else if(id==11){
					url="http://www.eootv.com/2008/img/SZTV-E_CNC.asx";
				}else if(id==1){
					if(ison==1){
						url="#";
					}else{
						url="http://www.eootv.com/2008/img/SZTV-"+ id+"_CNC.asx";
					}
				}else{
					url="http://www.eootv.com/2008/img/SZTV-"+ id+"_CNC.asx";
				}
			}else if(type==2){
				url="http://www.eootv.com/2008/img/SZR-"+ id+"_CNC.asx";
			}
	}
	if(type==1){
		changeMedia(url,0);
	}else if(type==2){
		changeMedia(url,id);
	}
}

var pFlag = false;
var pZoneWidth = 100 - 17;
var playerInterval;
var mediaIndex = 0;
var pixArray = ["img/player/pic_video.jpg","img/player/r1.jpg","img/player/r2.jpg","img/player/r3.jpg","img/player/r4.jpg"];
