if(typeof autoPlayFlag=='undefined') var autoPlayFlag = true;	//播放器是否自动开始播放
if(typeof iniPic=='undefined') var iniPic = '';					//播放器不停止时的显示图片
if((typeof videoFile=='undefined')||(videoFile=="")) var videoFile = 'cptv_images/player/screenpic.gif';			//播放器的播放文件
if(typeof baseUrl=='undefined') var baseUrl='cptv_images/player/';					//图片的根路径
if(typeof playerFlag=='undefined') 
	var playerFlag="splb";
var pWidth = 400;												//播放器的宽，不能变动
var vWidth = 714;												//视频的宽，不能变动
var vHeight = 505;												//视频的高，不能变动
var defaultImage=baseUrl+"/screenpic.gif";
var defaultImg=new Image();
defaultImg.src=defaultImage;
var lastPlay=videoFile;
var isPlayO = autoPlayFlag?true:false;
var isStopO = autoPlayFlag?false:true;
var isPauseO = autoPlayFlag?false:true;

var playPic = new Image();
playPic.src = baseUrl+"/play.jpg";
var playOverPic=new Image();
playOverPic.src=baseUrl+"/play_over.jpg";
var stopPic = new Image();
stopPic.src = baseUrl+"/stop.jpg";
var stopOverPic=new Image();
stopOverPic.src=baseUrl+"/stop_over.jpg";
var pausePic = new Image();
pausePic.src = baseUrl+"/pause.jpg";
var pauseOverPic=new Image();
pauseOverPic.src=baseUrl+"/pause_over.jpg";
var muteOnPic = new Image();
muteOnPic.src = baseUrl+"/voice.jpg";
var muteOffPic = new Image();
muteOffPic.src = baseUrl+"/novoice.jpg";
function getRightInfo(id){
	var o = dojo.byId("rightInfo");
	var infoFile=((playerFlag=="splb")?"tree.jsp":"info.jsp?id="+id);
	o.innerHTML = "\u6b63\u5728\u52a0\u8f7d...";
	var request = dojo.io.bind({url:infoFile, mimetype:"text/html", error:function (type, errObj) {
		o.innerHTML = errObj.message;
	}, load:function (type, data, evt) {
		o.innerHTML = data;
		if(playerFlag=="splb"){
			//Login("ref");
		}
	}, useCache:false});
}
function GetObj(objName){
	if(document.getElementById){
		return eval('document.getElementById("' + objName + '")');
	}else{
		return eval('document.all.' + objName);
	}
}
var isIE = navigator.appVersion.toLowerCase().indexOf("msie") >= 0;

//遮盖标识，true表示正显示图片；false表示正显示视频
var flag = !autoPlayFlag;
var objHTML1 = ("	<OBJECT ID='MediaPlayer' width='"+vWidth+"' height='"+vHeight+"' CLASSID='CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95' STANDBY='Loading Windows Media Player components...' TYPE='application/x-oleobject' VIEWASTEXT>");
objHTML1 += ("	<PARAM NAME='FileName' VALUE='");

var objHTML2 = ("'>");
objHTML2 += ("	<PARAM NAME='AutoStart' VALUE='"+(autoPlayFlag?"True":"False")+"'>");
objHTML2 += ("	<PARAM NAME='ShowStatusBar' VALUE='True'>");
objHTML2 += ("	<PARAM NAME='ShowControls' VALUE='False'>");
objHTML2 += ("	<PARAM NAME='ShowTracker' VALUE='False'>");
objHTML2 += ("	<PARAM NAME='EnableTracker' VALUE='False'>");
objHTML2 += ("	<PARAM NAME='ShowPositionControls' VALUE='False'>");
objHTML2 += ("  <param name='loop' value='-1'>");
objHTML2 += ("	<PARAM NAME='EnablePositionControls' VALUE='False'>");
objHTML2 += ("	<param name='enableContextMenu' value='false'>");
objHTML2 += ("	</OBJECT>");
document.write("<table width=\"970\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
document.write("  <tr>");
document.write("    <td colspan=\"2\" height=\"17\"><img src=\""+baseUrl+"top_left.jpg\" width=\"731\" height=\"17\" /></td>");
document.write("    <td width=\"233\" rowspan=\"2\" align=\"left\" valign=\"top\"><table width=\"239\" height=\"506\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
document.write("      <tr>");
document.write("        <td><img src=\""+baseUrl+"logo1.jpg\" width=\"239\" height=\"90\" /></td>");
document.write("      </tr>");
document.write("      <tr>");
document.write("        <td><img src=\""+baseUrl+playerFlag+".jpg\" width=\"239\" height=\"37\" /></td>");
document.write("      </tr>");
document.write("      <tr>");
document.write("        <td><table width=\"239\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
document.write("          <tr>");
document.write("            <td width=\"13\"><img src=\""+baseUrl+"left_lb.jpg\" width=\"13\" height=\"396\" /></td>");
document.write("            <td width=\"204\" valign=\"top\" bgcolor=\"#FFFFFF\">");
document.write("				<div id=\"rightInfo\"  class=\"main_right_nrjj_content\"></div>");
document.write("				<div id=\"plinfo\"></div>");
document.write("			</td>");
document.write("            <td width=\"22\"><img src=\""+baseUrl+"right_lb.jpg\" width=\"22\" height=\"396\" /></td>");
document.write("          </tr>");
document.write("        </table></td>");
document.write("      </tr>");
document.write("    </table></td>");
document.write("  </tr>");
document.write("  <tr>");
document.write("    <td width=\"17\"><img src=\""+baseUrl+"left.jpg\" width=\"17\" height=\"506\" /></td>");
document.write("    <td width=\"714\">");
if(isIE)
document.write(objHTML1 + (autoPlayFlag ? videoFile : defaultImage) + objHTML2);
else
	document.write("<img src=\""+defaultImage+"\"/>");
document.write("    </td>");
document.write("  </tr>");
document.write("  <tr>");
document.write("    <td height=\"17\" colspan=\"3\"><table width=\"970\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#212121\">");
document.write("      <tr>");
document.write("        <td width=\"57\"><img src=\""+baseUrl+"left2.jpg\" width=\"57\" height=\"17\" /></td>");
document.write("        <td width=\"874\" height=\"17\" background=\""+baseUrl+"bg_scroll.jpg\" align=\"left\" id='pZone' onmousedown='mouseDown(0)' style='POSITION: relative;left:0px;'><div id='pBox' title='移动滑块控制影片进度'  style='OVERFLOW: hidden;POSITION: relative;cursor:e-resize;left:0px;top:4px;width:22px;height:8px;background-image:url("+baseUrl+"btn_scroll.jpg);'></div></td>");
document.write("        <td width=\"39\"><img src=\""+baseUrl+"right.jpg\" width=\"39\" height=\"17\" /></td>");
document.write("      </tr>");
document.write("    </table></td>");
document.write("  </tr>");
document.write("  <tr>");
document.write("    <td colspan=\"3\" scope=\"col\"><table width=\"970\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
document.write("      <tr>");
document.write("        <td width=\"58\"><img src=\""+baseUrl+"playleft.jpg\" width=\"58\" height=\"38\" /></td>");
document.write("        <td width=\"33\"><img src=\""+baseUrl+"stop.jpg\" id='stopControl' style=\"cursor: pointer;\" onclick=\"toStop();\"  width=\"33\" height=\"38\" /></td>");
document.write("        <td width=\"53\"><img src=\""+baseUrl+"play.jpg\" id='playControl' style=\"cursor: pointer;\" width=\"53\" height=\"38\" onclick=\"toPlay();\" /></td>");
document.write("        <td width=\"34\"><img src=\""+baseUrl+"pause.jpg\" id=\"pauseControl\" style=\"cursor: pointer;\" width=\"34\" height=\"38\" onclick=\"toPause();\"/></td>");
document.write("        <td width=\"35\"><img src=\""+baseUrl+"voice.jpg\" id=\"muteControl\" width=\"35\" height=\"38\" /></td>");
document.write("        <td width=\"77\" align=\"left\" background=\""+baseUrl+"voicebar.jpg\" id='vZone' onmousedown='mouseDown(1)' style='POSITION: relative;left:0px;'><div id='vBox'  style='OVERFLOW: hidden;POSITION: relative;cursor:e-resize;left:0px;top:10px;width:16px;height:15px;background-image:url("+baseUrl+"voicescroll.jpg);'></div></td>");
document.write("        <td width=\"411\" align=\"center\" background=\""+baseUrl+"bg_xinxi.jpg\"><table width=\"370\" height=\"20\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding-top:6px\">");
document.write("          <tr>");
document.write("            <td align=\"left\"><font color=\"#FFFFFF\"><marquee scrollAmount=2 width=300 id='marqueeId'></marquee></font></td>");
document.write("          </tr>");
document.write("        </table></td>");
document.write("        <td width=\"24\"><img src=\""+baseUrl+"allscreen.jpg\" width=\"24\" height=\"38\" onclick=\"FullScreen();\" style=\"cursor: pointer;\" /></td>");
document.write("        <td width=\"146\" align=\"center\" background=\""+baseUrl+"bg_searchinput.jpg\"><form action=\"svr/search\" method=\"post\" name=\"form1\" id=\"form1\"  >");
document.write("          <label>");
document.write("            <input type=\"text\" name=\"key\" class=\"search_input1\" />");
document.write("            </label>");
document.write("        </td>");
document.write("        <td width=\"99\"><img src=\""+baseUrl+"btn_search.jpg\" width=\"99\" height=\"38\" border=\"0\" onclick=\"document.forms[0].submit();\" style=\"cursor:pointer\"/></td>");
document.write("      </tr>");
document.write("    </table></form></td>");
document.write("  </tr>");
document.write("  <tr>");
document.write("    <td colspan=\"3\" scope=\"col\"><img src=\""+baseUrl+"bottom.jpg\" width=\"970\" height=\"12\" /></td>");
document.write("  </tr>");
document.write("</table>");
	
if(!isIE){
	showNoIE();
}

function showNoIE(){
	GetObj('myScreen').innerHTML='<img width='+vWidth+' height='+vHeight+' src='+baseUrl+'player/noie.gif alt="请使用IE浏览器观看视频"/>';
}
function GetMedia(){
	return GetObj("MediaPlayer");
}
function FullScreen(){
	if(GetObj("MediaPlayer").Duration>0){
		GetObj("MediaPlayer").DisplaySize = 3;
	}
}
function showDefaultImg(){
	GetObj("MediaPlayer").FileName=defaultImg.src;
}
function Mute()
{
	if(GetObj("MediaPlayer").Mute.toString().toLowerCase()=='true')
	{
		GetObj("MediaPlayer").Mute='False';
		document.images("muteControl").src = muteOnPic.src;
		document.images("muteControl").alt = "关闭声音";
	}else{
		GetObj("MediaPlayer").Mute='True';
		document.images("muteControl").src = muteOffPic.src;
		document.images("muteControl").alt = "打开声音";
	}
}

function toPlay()
{
	if(!isIE){
		alert("请使用IE浏览器欣赏视频!谢谢!");
		return false;
	}
	if((GetObj("MediaPlayer").PlayState==0)||(GetObj("MediaPlayer").PlayState==1)){
		if((lastPlay!="")&&(lastPlay!=defaultImg.src)){
			if(isPlayO){
				
			}else{
				if(isStopO)
					GetObj("MediaPlayer").FileName=lastPlay;
				if(isStopO||isPauseO)
				{
					GetObj("MediaPlayer").Play();
					GetObj("MediaPlayer").AutoStart=true;
					document.images("playControl").src =playOverPic.src;
					document.images("pauseControl").src=pausePic.src;
					document.images("stopControl").src=stopPic.src;
					isPlayO = true;
					isStopO = false;
					isPauseO = false;
					autoPlayFlag=true;
				}
			}
		}
	}
}

//back to ini video
function toStop()
{
	if(GetObj("MediaPlayer").PlayState==2){
		if((isPlayO||isPauseO))
		{
			window.clearInterval("FixPos()");
			GetObj("pBox").style.left=0;
			GetObj("MediaPlayer").AutoStart="False";
			GetObj("MediaPlayer").Stop();
			document.images("playControl").src = playPic.src;
			document.images("stopControl").src = stopOverPic.src;
			lastPlay=videoFile;
			//GetObj("MediaPlayer").FileName=defaultImg.src;
			isPlayO = false;
			isStopO = true;
			isPauseO = false;
			autoPlayFlag=false;
		}
	}
}

function toPause()
{
	if(GetObj("MediaPlayer").Duration>0){
		if(isPlayO&&GetObj("MediaPlayer").PlayState!=3)
		{
			GetObj("MediaPlayer").Pause();
			document.images("playControl").src = playPic.src;
			document.images("pauseControl").src=pauseOverPic.src;
			isPlayO = false;
			isPauseO = true;
		}
	}
}

function OnloadFun(){
	startdrag();
	setInterval("FixPos()",1000);
}

dojo.addOnLoad(OnloadFun);
var pBoxLength = GetObj('pBox').style.width.replace("px","");//进度条上钮宽
var vBoxLength = GetObj('vBox').style.width.replace("px","");//声音条上钮宽
var pZoneLength = GetObj('pZone').width-pBoxLength;//进度条宽
var vZoneLength = GetObj('vZone').width-vBoxLength;//声音条宽
function startdrag()
{
	if(GetObj("MediaPlayer").Duration||(!isNaN(GetObj("MediaPlayer").Duration))){
		window.document.onmousemove = mouseMove;
		window.document.ondragstart = mouseEnd;
		window.document.onmouseup = mouseUp;
	}else{
		showNoIE();
	}
}
//拖动对象标识：0进度条；1声音条
var isPorV = 0;
var pFlag = false;//true表示正在拖动进度条
var vFlag= false;//true表示正在拖动声音条

function mouseDown(objSign){
	isPorV = objSign;
	if(isPorV==0){
		if(GetObj("MediaPlayer").Duration>0 && GetObj("MediaPlayer").PlayState!=0){
			pFlag = true;
			if(window.event.srcElement.id!='pZone') GetObj('pBox').style.left = GetObj('pBox').offsetLeft;
			else GetObj('pBox').style.left = window.event.x;
		}
	}else if(isPorV==1){
		if(GetObj("MediaPlayer").PlayState!=0){
			vFlag = true;
			if(window.event.srcElement.id!='vZone') GetObj('vBox').style.left = GetObj('vBox').offsetLeft;
			else GetObj('vBox').style.left = window.event.x;
		}
	}
}

function mouseMove(){
	if(isPorV==0){
		if(GetObj("MediaPlayer").Duration>0 && GetObj("MediaPlayer").PlayState!=0){
			if(pFlag)
				GetObj('pBox').style.left = window.event.clientX - GetOLeft(GetObj('pZone')) +"px";
			if (parseInt(GetObj('pBox').style.left.replace("px","")) > pZoneLength) GetObj('pBox').style.left=pZoneLength +"px";
			if (parseInt(GetObj('pBox').style.left.replace("px","")) < 0) GetObj('pBox').style.left=0 +"px";
		}

	}else if(isPorV==1){
		if(GetObj("MediaPlayer").Duration>0 && GetObj("MediaPlayer").PlayState!=0){
			if(vFlag) GetObj('vBox').style.left = window.event.clientX - GetOLeft(GetObj('vZone')) +"px";
			if (parseInt(GetObj('vBox').style.left.replace("px","")) > vZoneLength) GetObj('vBox').style.left=vZoneLength +"px";
			if (parseInt(GetObj('vBox').style.left.replace("px","")) < 0) GetObj('vBox').style.left=0 +"px";
		}
	}
}

function mouseUp()
{
	if(isPorV==0){
		if(GetObj("MediaPlayer").Duration>0 && GetObj("MediaPlayer").PlayState!=0){
			if (pFlag){
				var duration = GetObj("MediaPlayer").Duration;
				GetObj("MediaPlayer").CurrentPosition=duration * (parseInt(GetObj('pBox').style.left)/pZoneLength);
			}
			pFlag = false;
		}
	}else if(isPorV==1){
		if(GetObj("MediaPlayer").Duration>0 && GetObj("MediaPlayer").PlayState!=0){
			if (vFlag){
				tempVol = (10 - (10*parseInt(GetObj('vBox').style.left)/vZoneLength))*(-340);
				if(tempVol<=-3400){
					if(GetObj("MediaPlayer").Mute.toString().toLowerCase()=='false' && document.images("muteControl").src != muteOffPic.src){
						GetObj("MediaPlayer").Mute='True';
						document.images("muteControl").src = muteOffPic.src;
						document.images("muteControl").alt = "打开声音";
					}
				}else if(tempVol<=0){
					if(GetObj("MediaPlayer").Mute.toString().toLowerCase()=='true')
					{
						GetObj("MediaPlayer").Mute='False';
						document.images("muteControl").src = muteOnPic.src;
						document.images("muteControl").alt = "关闭声音";
					}
				}else{
					return false;
				}
				GetObj("MediaPlayer").Volume=Math.round(tempVol);//duration * (parseInt(GetObj('vBox').style.left)/139);
			}
		}
		vFlag = false;
	}
}

function mouseEnd()
{
	if(GetObj("MediaPlayer").Duration>0){
		window.event.returnValue = false;
	}
}

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 FixPos(){
	if(GetObj("MediaPlayer").Duration>0){
		var duration = GetObj("MediaPlayer").Duration;
		var pos = GetObj("MediaPlayer").CurrentPosition;
		var pBoxPos = Math.round(pos/duration*pZoneLength);
		//alert("pos:"+pos);
		//alert("pBoxPos:"+pBoxPos);
		if (!isNaN(pBoxPos)) 
			GetObj("pBox").style.left = pBoxPos;
		if(GetObj("MediaPlayer").PlayState==0) toStop();
	}
	if (autoPlayFlag&&(GetObj("MediaPlayer").PlayState == 0)&&(GetObj("MediaPlayer").FileName!=defaultImg.src)) {
		toStop();
	}
}
function VolumeUp(vol){
	tempVol = (10 - vol)*(-340);
	GetObj("MediaPlayer").Volume= tempVol;
	GetObj('vBox').style.left = vol/10*vZoneLength-vBoxLength;
}
dojo.addOnLoad(OnloadFun);
VolumeUp(10);