//chinaacc media control script writed by cailiqiang 2005

var sFlag = false;
var isPlay = true;
var isStop = false;
var isPause = false;
var isAutoPage = true;
var g_sCurPos = -1;
var g_sPostion = 0;
var isSeek = "";

function GetObj(objName){
	if(document.getElementById){
		return eval('document.getElementById("' + objName + '")');
	}else{
		return eval('document.all.' + objName);
	}
}

function StartMouse()
{
	//alert(document.MediaPlayer.Duration||(!isNaN(document.MediaPlayer.Duration)));
	if(document.MediaPlayer.Duration||(!isNaN(document.MediaPlayer.Duration))){
		window.document.onmousemove = mouseMove;
		window.document.ondragstart = mouseEnd;
		window.document.onmouseup = mouseUp;
		/*window.document.onmousedown = mouseDown;*/
	}else{
		//  GetObj('myScreen').innerHTML='<img width=320 height=264 src=images/gw_bn_278.jpg alt="请使用IE浏览器观看视频">';
	}
}
	
function mouseDown(){
	if(document.MediaPlayer.Duration>0){
		sFlag = true;
		if(window.event.srcElement.id!='ForSlider') GetObj('Slider').style.left = GetObj('Slider').offsetLeft;
		else GetObj('Slider').style.left = (window.event.x-7);
	}		
}

function mouseMove(){	
	if(document.MediaPlayer.Duration>0){				
		if(sFlag) document.getElementById('Slider').style.left = window.event.clientX - document.getElementById('ForSlider').offsetLeft - 7; //window.event.x-9;
		if (parseInt(document.getElementById('Slider').style.left) > 90) document.getElementById('Slider').style.left=90;
		if (parseInt(document.getElementById('Slider').style.left) < 0) document.getElementById('Slider').style.left=0;
	}	
}

function mouseUp()
{	
	if(document.MediaPlayer.Duration>0){
		if (sFlag){
			var duration = document.MediaPlayer.Duration;
			document.MediaPlayer.CurrentPosition=duration * (parseInt(document.getElementById('Slider').style.left)/90);
		}
		sFlag = false;
	}
}

function mouseEnd()
{
	if(document.MediaPlayer.Duration>0){
		window.event.returnValue = false;
	}
}

function FixMediaPos(){
	if(document.MediaPlayer.Duration>0){
		if (isSeek != "") 
		{
			seekTime(isSeek);
			isSeek = "";
		}
		var duration = document.MediaPlayer.Duration;
		var pos = document.MediaPlayer.CurrentPosition;
		var SliderPos = Math.round(pos/duration*90);
		if (!isNaN(SliderPos)) document.getElementById('Slider').style.left = SliderPos;
		if(document.MediaPlayer.PlayState==0) 
		{toStop();}
			
	}
}

function toStop()
{
	document.MediaPlayer.Stop();
	document.images("playControl").src = "../images/m_play2.gif";
	document.images("stopControl").src =" ../images/m_stop2.gif"
	isStop = true;
	isPlay = false;
}

function toPlay()
{
	if(document.MediaPlayer.Duration>0){
		if(isPlay){
			toPause();
		}else{
			if(isStop||isPause)
			{
				//alert(isStopO||isPauseO);
				document.MediaPlayer.Play();
				document.images("playControl").src = "../images/m_play1.gif";
				document.images("stopControl").src = "../images/m_stop1.gif";
				//document.images("pauseControl").src = "images/vod009.gif";
				isPlay = true;
				isStop = false;
				isPause = false;
			}		
		}
	}
	
}

function toPause()
{
	if(document.MediaPlayer.Duration>0){
		if(isPlay&&document.MediaPlayer.PlayState!=3)
		{
			document.MediaPlayer.Pause();
			document.images("playControl").src = "../images/m_play2.gif";
			//document.images("pauseControl").src = pausePic.src;
			isPlay = false;
			isPause = true;
		}
	}
}

function toMute()
{
	document.MediaPlayer.Mute = ! document.MediaPlayer.Mute;
	if (true == document.MediaPlayer.Mute) 
		{document.images("muteControl").src = "../images/m_mute2.gif";}
	else
		{document.images("muteControl").src = "../images/m_mute1.gif";}
}



function fnConvertToSeconds(sTime) 
{
	var asTemp = sTime.split(":");
	var lTemp = 0;
	lTemp = parseInt((asTemp[0] * 3600), 10) + parseInt((asTemp[1] * 60), 10) + parseInt(asTemp[2], 10);
	return(lTemp);
}


function seekTime(sTimeTarget)
{
	if(document.MediaPlayer.Duration>0){	
		try
		{
			var sSeekTarget = fnConvertToSeconds(sTimeTarget);	
			// the following is executed if sTimeTarget is not in the gaAction array
			document.MediaPlayer.CurrentPosition = sSeekTarget;
			//if (giStatePlaying != document.MediaPlayer.PlayState)
			//{
				document.MediaPlayer.Play();				
			//}
		}
		catch(e) 
		{}	
	}
}

function PageChange(ExeType,MediaState)
{
	if(ExeType==0)
	{Teacher.Stop();}
	else if(ExeType==1)
	{
		if (MediaState == 2 )
		{
		Teacher.Play();			
		}	
		else
		{Teacher.Stop();}
	}
	else if(ExeType==2)
	{
		alert((MediaPlayer.ErrorCode & 0xFFFF) + "\n" + MediaPlayer.ErrorDescription + "\n" + MediaPlayer.FileName);
	}
}