function getObj(objName)
{
        try
		{
			if (document.getElementById)
			{
					return eval('document.getElementById("'+objName+'")');
			}
			else
			{
					return eval('document.all.'+objName);
			}
		}
		catch(e)
		{}
}

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;
}

//Undefined = 0,准备就绪 Stopped = 1,停止; Paused = 2,暂停; Playing = 3,播放中; Buffering = 4,缓冲中; Waiting = 5,等待中; MediaEnded = 6,播放结束Ready = 7, 准备读;Reconnecting = 8,重连中; BTDowning = 9 BT种子下载中; Createing = 10,正在连接中; Stoping=11 正在停止;
function QvodPlay()
{
	if(QvodPlayer.PlayState != 3)
	{    
		QvodPlayer.Play();
		getObj("playControl").src="image/07.gif";
		if(FirstPlay)
		{
			getObj("mediaInfo").innerText="连接中";
			FirstPlay = false;
		}
		else
		{
			getObj("mediaInfo").innerText="播放中";
		}
		
	}
	else
	{    
		QvodPause();
	}
}

function QvodPause()
{
	if(QvodPlayer.Currentpos > 0)
	{
		QvodPlayer.Pause();
		getObj("playControl").src="image/08.gif";
		getObj("mediaInfo").innerText="已暂停";
	}	
}

function QvodStop()
{
	if(QvodPlayer.CurrentPos > 0)
	{
		QvodPlayer.Stop();
		getObj("playControl").src="image/07.gif";
		getObj("mediaInfo").innerText="已停止";	
	}
	
}

function FullScreen()
{
	try
	{	
		if(QvodPlayer.CurrentPos > 0)
		{
			var v = true;
			QvodPlayer.Full = v;
		}
	}
	catch(e)
	{}	
}
var mute = false;
function Mute()
{
	if(mute)
	{
		mute = false;
		QvodPlayer.Mute = mute;
		getObj("muteControl").src = "image/mute.gif";
		getObj("muteControl").alt = "关闭声音";			
		
	}
	else
	{
		mute = true;
		QvodPlayer.Mute = mute;
        getObj("muteControl").src = "image/mute_2.gif";
        getObj("muteControl").alt = "打开声音";	
	}	
}

//==========调整声音======================================
var isPorV = 0;
var fFlag= false;
//drag func
var pFlag = false;
var vFlag = false;
var pZoneWidth = getObj("tdqvod").style.width.replace("px","")-260;//这个值指这个播放进度条的长度
var vZoneWidth=57;
var bufferingProgress = 0;
var downloadProgress = 0;
var bitRate;
var currentPositionString = "";
var mediaTitle;
var itemTitle;
var FirstPlay = true;
function mouseDown(objSign)
{
        isPorV = objSign;
        if(isPorV==0){
               if(QvodPlayer.CurrentPos > 0)
                {
                        pFlag = true;
                        if(window.event.srcElement.id!="pZone") 
                                getObj("pBox").style.left = getObj("pBox").offsetLeft -1;
                        else 
                                getObj("pBox").style.left = (window.event.x-12);
                }
        }
        else if(isPorV==1)
        {
      
                vFlag = true;
                if(window.event.srcElement.id!="vZone") 
                {
                        getObj("vBox").style.left = getObj("vBox").offsetLeft+"px";
                }
                else 
                {
                        getObj("vBox").style.left = (window.event.x-3);		
                }
        }
}

function mouseMove(){
 
        if(isPorV==0)
        {
                if(QvodPlayer.CurrentPos > 0)
                {
                        if(pFlag) getObj("pBox").style.left = window.event.clientX - getOLeft(getObj("pZone")) - 12 +"px";
                        if (parseInt(getObj("pBox").style.left.replace("px","")) > pZoneWidth) getObj("pBox").style.left=pZoneWidth +"px";
                        if (parseInt(getObj("pBox").style.left.replace("px","")) < -5) getObj("pBox").style.left=-5 +"px";
                }

        }
        else if(isPorV==1)
        {          

                if(vFlag)
                {
                 getObj("vBox").style.left = window.event.clientX - getOLeft(getObj("vZone")) - 4 +"px";
                 }
                if (parseInt(getObj("vBox").style.left.replace("px","")) > vZoneWidth) getObj("vBox").style.left=vZoneWidth +"px";
                if (parseInt(getObj("vBox").style.left.replace("px","")) < 0) getObj("vBox").style.left=0 +"px";
                
                if(isPorV==1)
                {    
                        if (vFlag)
                        {
                                tempVol = (parseInt(getObj("vBox").style.left)/vZoneWidth)*100;
								var tempV = Math.round(tempVol);
								if(tempV < 0) tempV = 0;
								if(tempV > 100) tempV = 100;
								var tempVstr = tempV.toString(10);
								var flVol = tempV;//-100 * (80 - tempV);
								QvodPlayer.Volume= flVol;
                        }
                }
                
        }
}

function mouseUp()
{
        if(isPorV==0){
				var currentPos = QvodPlayer.CurrentPos;
                if(currentPos > 0)
				{
                        if (pFlag)
						{
                                var duration = QvodPlayer.Duration;
								var tempVol =duration * (parseInt(getObj("pBox").style.left)/pZoneWidth) ;
								tempVol = Math.floor(tempVol);
								if(tempVol <0 )tempVol =0;
								QvodPlayer.CurrentPos = tempVol;
                        }
                        pFlag = false;
                }
        }
		else if(isPorV==1)
		{
                if (vFlag){
                                tempVol = (parseInt(getObj("vBox").style.left)/vZoneWidth)*100;
								var tempV = Math.round(tempVol);
								if(tempV < 0) tempV = 0;
								if(tempV > 100) tempV = 100;
								var tempVstr = tempV.toString(10);
								getObj("mediaInfo").innerText="当前音量：" + Math.round(tempVstr) + "%";
								var flVol = tempV;//-100 * (80 - tempV);
								QvodPlayer.Volume= flVol;
                }
                vFlag = false;
        }
}
//========================================================
function mouseEnd()
{
        window.event.returnValue = false;
}

function OnloadFun()
{
        startdrag();
        setInterval("FixPos()",1000);
}
var hc=false;
var firstload=false;
function FixPos()
{
        if(!firstload)
        {
             QvodPlayer.Volume= 50;
             firstload=true;  
        }        
         
 
        
		var duration = QvodPlayer.Duration;
        if( duration > 0)
		{
		        if(QvodPlayer.get_CurTaskProcess()==800 && hc==false && typeof(nexturl)!="undefined") 
                {                
                   QvodPlayer.StartNextDown(nexturl);
                   hc=true;
                } 		        
                var pos = QvodPlayer.CurrentPos;
                if (pos == 0)
                {
                        var pBoxPos = Math.round(pos/duration*pZoneWidth)+5;
                }
                else
                {
                        var pBoxPos = Math.round(pos/duration*pZoneWidth)+5;
                }
                if (!isNaN(pBoxPos)) 
                {
                        getObj("pBox").style.left = pBoxPos;
                }
                if(QvodPlayer.PlayState == 1) 
                {
                        getObj("playControl").src="image/07.gif";
						getObj("pBox").style.left = 5;
						mediaInfo.innerText="已停止";
                }
				downloadProgress = 0;
				downloadProgress = Math.round(QvodPlayer.Downrate);
				bitRate = 0;
				currentPositionString = "";
				if(duration > 3600)
					{
						//---共计时间
						var vHours = Math.floor(duration / 3600); 
						var vstrHours = vHours > 9 ? vHours.toString(10) : ("0" + vHours.toString(10));
						var vMin   = Math.floor((duration % 3600) / 60);
						var vstrMin = vMin > 9? vMin.toString(10) : ("0" + vMin.toString(10));
						var vSen   = Math.floor(duration % 60);
						var vstrSen = vSen > 9 ? vSen.toString(10) : ("0" + vSen.toString(10));
						//---当前时间
						var vHours1 = Math.floor(pos / 3600);
						var vstrHours1 = vHours1 > 9 ? vHours1.toString(10) : ("0" + vHours1.toString(10));
						var vMin1 = Math.floor((pos % 3600) / 60);
						var vstrMin1 = vMin1 > 9 ? vMin1.toString(10) : ("0" + vMin1.toString(10));
						var vSen1 = Math.floor(pos % 60);
						var vstrSen1 = vSen1 > 9 ? vSen1.toString(10) : ("0" + vSen1.toString(10));
						currentPositionString = vstrHours1 + ":" + vstrMin1 + ":" + vstrSen1;
						currentPositionString = currentPositionString + " / " ;
						currentPositionString = currentPositionString + vstrHours + ":" + vstrMin + ":" + vstrSen;
					}
				else
				{
						//---共计时间
						var vMin   = Math.floor((duration % 3600) / 60);
						var vstrMin = vMin > 9 ? vMin.toString(10) : ("0" + vMin.toString(10));
						var vSen   = Math.floor(duration % 60);
						var vstrSen = vSen > 9 ? vSen.toString(10) : ("0" + vSen.toString(10));
						//---当前时间
						var vMin1 = Math.floor((pos % 3600) / 60);
						var vstrMin1 = vMin1 > 9 ? vMin1.toString(10) : ("0" + vMin1.toString(10));
						var vSen1 = Math.floor(pos % 60);
						var vstrSen1 = vSen1 > 9 ? vSen1.toString(10) : ("0" + vSen1.toString(10));
						currentPositionString = vstrMin1 + ":" + vstrSen1;
						currentPositionString = currentPositionString + " / " ;
						currentPositionString = currentPositionString + vstrMin + ":" + vstrSen;					
				}
				getObj("mediaTime").innerText = currentPositionString.toString();
//Undefined = 0,准备就绪 Stopped = 1,停止; Paused = 2,暂停; Playing = 3,播放中; Buffering = 4,缓冲中; Waiting = 5,等待中; MediaEnded = 6,播放结束Ready = 7, 准备读;Reconnecting = 8,重连中; BTDowning = 9 BT种子下载中; Createing = 10,正在连接中; Stoping=11 正在停止;
				switch(QvodPlayer.PlayState)
				{
						case 10:
						{				
				                getObj("playControl").src="image/08.gif";
								mediaInfo.innerText="缓冲:(" + downloadProgress.toString(10) +" KB/S)";
						}
						break;
						case 1:
						{
							mediaInfo.innerText="已停止";
							getObj("playControl").src="image/07.gif";					
						}
						break;
						case 3:
						{	
								if(document.getElementById("divad"))
						        {
						            document.getElementById("divad").style.display='none';
						        }
				                getObj("playControl").src="image/08.gif";
								if(downloadProgress < 1)
									mediaInfo.innerText="播放中("+QvodPlayer.get_Rate()+" Kbps)";
								else
								{
								    if(pos<=6)
								    {
								        mediaInfo.innerText="播放中("+QvodPlayer.get_Rate()+" Kbps)";
								    }
								    else
								    {									
									    mediaInfo.innerText="播放中(" + downloadProgress.toString(10) +" KB/S)";
									}
							    }
									
							
						}
						break;
						case 2:
						{
						    if(document.getElementById("divad"))
						    {
						        document.getElementById("divad").style.display='';
						    }
							mediaInfo.innerText="已暂停";
							getObj("playControl").src="image/07.gif";												
						}						
						break;
						default:
						break;
				}
        }
		else
		{
//Undefined = 0,准备就绪 Stopped = 1,停止; Paused = 2,暂停; Playing = 3,播放中; Buffering = 4,缓冲中; Waiting = 5,等待中; MediaEnded = 6,播放结束Ready = 7, 准备读;Reconnecting = 8,重连中; BTDowning = 9 BT种子下载中; Createing = 10,正在连接中; Stoping=11 正在停止;	
			downloadProgress = 0;
			downloadProgress = Math.round(QvodPlayer.Downrate);
			switch(QvodPlayer.PlayState)
			{
				case 0:
				{
					mediaInfo.innerText = "准备就绪";
					getObj("playControl").src="image/07.gif";		
				}
				break;
				case 10:
				{
					mediaInfo.innerText = "正在缓冲 (" + downloadProgress.toString(10) +" KB/S)";
					getObj("mediaTime").innerText = "00:00 / 00:00";
				}
				break;
				case 4:
						{					
				                getObj("playControl").src="image/08.gif";
								mediaInfo.innerText="缓冲:(" + downloadProgress.toString(10) +" KB/S)";
						}
						break;
			    case 1:
						{
							mediaInfo.innerText="已停止";
							getObj("playControl").src="image/07.gif";					
						}
						break;
				case 3:
						{
							    if(document.getElementById("divad"))
						        {
						        document.getElementById("divad").style.display='none';
						        }
				                getObj("playControl").src="image/08.gif";
								if(downloadProgress < 1)
									mediaInfo.innerText="播放中";
								else
									mediaInfo.innerText="播放中(" + downloadProgress.toString(10) +" KB/S)";
						}
						break;
				case 2:
						{
						    if(document.getElementById("divad"))
						    {
						        document.getElementById("divad").style.display='';
						    }
							mediaInfo.innerText="已暂停";
							getObj("playControl").src="image/07.gif";												
						}						
						break;
						default:
						break;
			}
		}
}



function startdrag()
{
        if(QvodPlayer.Currentpos||(!isNaN(QvodPlayer.Currentpos))){
                window.document.onmousemove = mouseMove;
                window.document.ondragstart = mouseEnd;
                window.document.onmouseup = mouseUp;
        }
}
//====点击播放==============================================
function PointPlay(playername)
{
	QvodPlayer.stop();
	mediaInfo.innerText = "正在缓冲";
	getObj("mediaTime").innerText = "00:00 / 00:00";	
	QvodPlayer.URL = playername;
	QvodPlayer.Play();
	getObj("playControl").src="image/08.gif";
}
//==========================================================
OnloadFun();