//copied from newTech Dept.
function  speedtest()
{
time = new Date();

starttime = time.getTime();


time = new Date();

endtime = time.getTime();

if (endtime == starttime)

 {downloadtime = 0

 }

else

 {downloadtime = (endtime - starttime)/1000;

 }


if (downloadtime == 0)

 {downloadtime = .1;

  nextsize = 50;

 }

else if (downloadtime < .2)

 {nextsize = 500;

 }

else

 {

  nextsize = 50;

 }



kbytes_of_data = 50; // data file size

linespeed = kbytes_of_data/downloadtime;

kbps = (Math.round((linespeed*8)*10*1.02))/10;
}
var kbps_tmp;
kbps_tmp = getCookie("bn_stream_speed");
if (kbps_tmp == "")
{
		speedtest();
}
else
{
	var kbps=0;
	kbps=kbps_tmp;
}
if (kbps > 300)
{
		document.cookie = "bn_stream_speed=301; expires=Tuesday,07-February-2006 08:00:01 GMT; path=/; domain=swingsmedia.com.cn;";
		
}
else if(kbps > 90)
{
		document.cookie = "bn_stream_speed=91; expires=Tuesday,07-February-2006 08:00:01 GMT; path=/; domain=swingsmedia.com.cn;";
}
else
{
		document.cookie = "bn_stream_speed=1; expires=Tuesday,07-February-2006 08:00:01 GMT; path=/; domain=swingsmedia.com.cn;";
}



function getCookie(name) {

  var search;

  search = name + "="
  offset = document.cookie.indexOf(search) 
  if (offset != -1) {
    offset += search.length ;
    end = document.cookie.indexOf(";", offset) ;
    if (end == -1)
      end = document.cookie.length;
    return document.cookie.substring(offset, end);
  }
  else
    return "";
}




//scripted by guowei1 bellow, 2004
function OnloadFun(){startdrag();setInterval("FixPos()",1000);}
document.body.onload=OnloadFun;

var curBroad = broadFile;
var curNarrow = narrowFile;
var curFile;
	CheckBand();


var flag = true;
function GetObj(objName){
	if(document.getElementById){
		return eval('document.getElementById("' + objName + '")');
	}else{
		return eval('document.all.' + objName);
	}
}


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='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='EnablePositionControls' VALUE='False'>");
objHTML2 += ("	<param name='enableContextMenu' value='false'>");

objHTML2 += ("	</OBJECT>");

document.writeln("<style type='text/css'>");
document.writeln(".aWhiteMP A:link,.aWhiteMP A:visited {text-decoration:none;color:#ffffff;}");
document.writeln(".aWhiteMP A:active,.aWhiteMP A:hover {text-decoration:underline;color:#ff0000;}");
document.writeln(".aWhiteMP{color:#ffffff;}");

document.writeln("A.vv01:link,A.vv01:visited {text-decoration:none;color:#fff;}");
document.writeln("A.vv01:active,A.vv01:hover {text-decoration:none;color:#ff0;}");
document.writeln("</style>");

document.writeln("");

document.writeln("<table border=0 cellpadding=0 cellspacing=0>");
document.writeln("<form name='myForm'>");
document.writeln("<tr>");
document.writeln("<td height='"+vHeight+"' valign=top>");
document.writeln("	<div id='hideScreen' style='display:"+((iniPic==""||iniPic==null)?"none":"block")+";'>");
document.writeln("		<div class=aWhiteMP style='text-align:center;'><a href='javascript:toPlay()' class=vv01><img src='"+iniPic+"' width="+vWidth+" height="+vHeight+" border=1 alt='点击播放该视频'></div>");
document.writeln("	</div>");
document.writeln("	<div id='myScreen' style='border:1px solid #000;display:"+((iniPic==""||iniPic==null)?"block":"none")+";'>");
document.writeln(objHTML1 + curFile + objHTML2);
document.writeln("	</div>");
document.writeln("	<div id='tempDiv' style='display:none;'></div>");
document.writeln("</td>");
document.writeln("</tr>");
document.writeln("<tr>");
document.writeln("<td height=27 valign=top background=/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_06.gif>");
document.writeln("	<table idth=100% height=27 border=0 cellpadding=0 cellspacing=0>");
document.writeln("	<tr>");
document.writeln("	<td width=27 valign=top><img id=playControl src=/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_08.gif width=27 height=27 alt='播放/暂停' style='cursor:pointer;' onClick='toPlay()'></td>");
document.writeln("	<td width=27 valign=top><img id=stopControl src=/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_09.gif width=26 height=27 alt='停止' style='cursor:pointer;' onClick='toStop()'></td>");
document.writeln("	<td  valign=top><img src=/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_11.gif width=10 height=27></td>");
document.writeln("	<td>");
document.writeln("		<table width=100% height=27 cellspacing=0 border=0 cellpadding=0>");
document.writeln("		<tr>");
document.writeln("		<td>");
document.writeln("			<table width=100% cellspacing=0 border=0 cellpadding=0>");
document.writeln("			<tr>");
document.writeln("			<td id='pZone' background=/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_12.gif onmousedown='mouseDown(0)' style='POSITION: relative;left:0;' width=166><div id='pBox' style='OVERFLOW: hidden;POSITION: relative;cursor:e-resize;left:-5px;top:10px;width:18px;'><img src=/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_21.gif width=18 height=9  alt='移动滑块控制影片进度'></div></td>");
//document.writeln("			<td width=15 background=/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_06.gif>&nbsp;</td>");
document.writeln("			<td width=60 align=left ><img src=/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_19.gif width=20 height=27></td>");
document.writeln("			<!--volume-->");
document.writeln("			<td width=24 valign=top><img src=/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_18.gif alt='关闭声音' name=muteControl width=29 height=27 id=muteControl style='cursor:pointer;' onClick='Mute()'></td>");
document.writeln("			<td width=41 valign=top background=/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_22.gif id='vZone' onmousedown='mouseDown(1)' style='POSITION: relative;left:0;'><div id='vBox' style='OVERFLOW: hidden;POSITION: relative;cursor: pointer;left:0px;top:7px;width:9px;'><img src=/sitebao_wingsmedia/images/playerSkin/gw_bn_vol_21.gif width=9 height=16 alt='移动滑块控制音量'></div></td>");

document.writeln("			<td width=10>&nbsp;</td>")
document.writeln("			            <td><div style='width:0px;height:0px;position:relative;'>")
document.writeln("			              <div id='msgBox' style='color:#f00;left:22px;top:22px;width:138px;padding:5px;line-height:19px;border:1px solid #aaa;display:none;background-color:#fff;z-index:99;position:absolute;filter:alpha(opacity=90);'></div>")
document.writeln("			           </div>")
document.writeln("			                   <img src='/sitebao_wingsmedia/images/playerSkin/gw_bn_player_03.gif' width=26 height=27 alt='全屏播放,双击屏幕还原' onClick=FullScreen() style='cursor:pointer;'></td>")

document.writeln("			</tr>");
document.writeln("			</table>");
document.writeln("		</td>");
document.writeln("		</tr>");
document.writeln("		</table>");
document.writeln("	</td>");
document.writeln("	</tr>");
document.writeln("	</table>");	
document.writeln("</td>");
document.writeln("</tr>");
document.writeln("</form>");
document.writeln("</table>");


function ShowMsg(Msg){
	GetObj("msgBox").innerHTML = Msg;
	GetObj("msgBox").style.display = "block";
}


function HideMsg(){GetObj("msgBox").style.display = "none";}

function FullScreen(){
	if(document.MediaPlayer.Duration>0){
		document.MediaPlayer.DisplaySize = 3;
	}
}

function SetBand(){

  if(((document.myForm.band[0].checked)?curBroad:curNarrow)!=document.MediaPlayer.FileName){
	//var curBand = (document.myForm.band[0].checked)?"broad":"narrow";
	GetObj('myScreen').innerHTML=objHTML1+((document.myForm.band[0].checked)?curBroad:curNarrow)+objHTML2;
	//toStop();
	//toPlay();
	//document.MediaPlayer.FileName = (document.myForm.band[0].checked)?curBroad:curNarrow;
	ChgVideo((document.myForm.band[0].checked)?curBroad:curNarrow);
  }
}


var mutePic = new Image(29,29);
mutePic.src = "/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_17.gif";
function Mute()
{
	//alert(MediaPlayer.Mute);
	if(document.MediaPlayer.Mute.toString().toLowerCase()=='true')
	{
		document.MediaPlayer.Mute='False';
		document.images("muteControl").src = "/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_18.gif";
		document.images("muteControl").alt = "关闭声音";
	}else{
		document.MediaPlayer.Mute='True';
		document.images("muteControl").src = mutePic.src;
		document.images("muteControl").alt = "打开声音";
	}
}

			var isPlayO = true;
			var isStopO = false;
			var isPauseO = false;
			var playPic = new Image(48,77);
			playPic.src = "/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_07.gif";
			var stopPic = new Image(24,35);
			stopPic.src = "/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_10.gif";
			//var pausePic = new Image(28,77);
			//pausePic.src = "/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_18.gif";


function toPlay()
{
	document.MediaPlayer.AutoStart="True";
	if(document.MediaPlayer.Duration>0){
		if(isPlayO){
			toPause();
		}else{
			if(isStopO||isPauseO)
			{
				//alert(isStopO||isPauseO);
				document.MediaPlayer.Play();
				document.images("playControl").src = "/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_08.gif";
				document.images("stopControl").src = "/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_09.gif";
				//document.images("pauseControl").src = "http://image2.swingsmedia.com.cn/dongman/BN//sitebao_wingsmedia/images/playerSkin/vod009.gif";
				isPlayO = true;
				isStopO = false;
				isPauseO = false;
				//alert(isPlayO +"=="+ isStopO+"=="+ isPauseO);
			}
				if(flag){
					GetObj('hideScreen').style.display = 'none';
					GetObj('myScreen').style.display = 'block';
					flag = false;
				}
		
		}
	}
}

function toPlay2()
{
	document.MediaPlayer.AutoStart="True";
	if(document.MediaPlayer.Duration>0){
			if(isStopO||isPauseO)
			{
				//alert(isStopO||isPauseO);
				document.MediaPlayer.Play();
				document.images("playControl").src = "/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_08.gif";
				document.images("stopControl").src = "/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_09.gif";
				//document.images("pauseControl").src = "http://image2.swingsmedia.com.cn/dongman/BN//sitebao_wingsmedia/images/playerSkin/vod009.gif";
				isPlayO = true;
				isStopO = false;
				isPauseO = false;
				//alert(isPlayO +"=="+ isStopO+"=="+ isPauseO);
			}

	}
	if(flag){
		GetObj('hideScreen').style.display = 'none';
		GetObj('myScreen').style.display = 'block';
		flag = false;
	}
}

			/*
			//stop on current video
			function toStop()
			{
			//alert(MediaPlayer.Mute);
				if(isPlayO||isPauseO)
				{
					document.MediaPlayer.Stop();
					document.images("playControl").src = playPic.src;
					document.images("stopControl").src = stopPic.src;
					isPlayO = false;
					isStopO = true;
				}
				if((!flag)&&(document.MediaPlayer.FileName==broadFile||document.MediaPlayer.FileName==narrowFile)){
					GetObj('hideScreen').style.display = 'block';
					GetObj('myScreen').style.display = 'none';
					flag = true;
				}
			}
			*/

//back to ini video
function toStop()
{
	//alert(MediaPlayer.Mute);
			
	if(isPlayO||isPauseO)
	{
		document.MediaPlayer.AutoStart="False";
		document.MediaPlayer.Stop();
		document.images("playControl").src = playPic.src;
		document.images("stopControl").src = stopPic.src;
		isPlayO = false;
		isStopO = true;
		//clearInterval(idTmr);

		if(!flag){
		  if(iniPic!=""&&iniPic!=null){
			GetObj('hideScreen').style.display = 'block';
			GetObj('myScreen').style.display = 'none';
			
		  }
			curBroad = broadFile;
			curNarrow = narrowFile;
			CheckBand();
			document.MediaPlayer.FileName = curFile;
			flag = true;
		}
	}
}
			
			function toPause()
			{
			//alert(MediaPlayer.Mute);
				if(document.MediaPlayer.Duration>0){
					if(isPlayO&&document.MediaPlayer.PlayState!=3)
					{
						document.MediaPlayer.Pause();
						document.images("playControl").src = playPic.src;
						//document.images("pauseControl").src = pausePic.src;
						isPlayO = false;
						isPauseO = true;
					}
				}
			}
			//--->


	
	var fFlag= false;
	//mpControl func

	//drag func
	var pFlag = false;

	function startdrag()
	{
		//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=http://image2.swingsmedia.com.cn/dongman/BN/sitebao_wingsmedia/images/playerSkin/gw_bn_278.jpg alt="请使用IE浏览器观看视频">';
		}
	}
	var isPorV = 0;
	function mouseDown(objSign){
		//alert(window.event.srcElement.id);
		isPorV = objSign;
		if(isPorV==0){
			if(document.MediaPlayer.Duration>0){
				pFlag = true;
				//GetObj('pBox').style.left = (window.event.x-9);
				if(window.event.srcElement.id!='pZone') GetObj('pBox').style.left = GetObj('pBox').offsetLeft;
				else GetObj('pBox').style.left = (window.event.x-9);
			}
		}else if(isPorV==1){
			vFlag = true;
			if(window.event.srcElement.id!='vZone') GetObj('vBox').style.left = GetObj('vBox').offsetLeft;
			else GetObj('vBox').style.left = (window.event.x-4);
		}
	}

	function mouseMove(){
		if(isPorV==0){
			if(document.MediaPlayer.Duration>0){
				//alert(window.event.x-25);
				//if(pFlag) alert(parseInt(document.getElementById('pBox').style.left));
				//if(pFlag) document.getElementById('pBox').style.left = window.event.clientX-10;// - clickleft;
				//if(pFlag) document.getElementById('PlayState').innerText = (document.getElementById('pZone').offsetLeft+':'+document.getElementById('pBox').style.left+":"+window.event.clientX);
				if(pFlag) document.getElementById('pBox').style.left = window.event.clientX - document.getElementById('pZone').offsetLeft - 9; //window.event.x-9;
				if (parseInt(document.getElementById('pBox').style.left) > 166) document.getElementById('pBox').style.left=166;
				if (parseInt(document.getElementById('pBox').style.left) < -5) document.getElementById('pBox').style.left=-5;
			}

		}else if(isPorV==1){
			if(vFlag) document.getElementById('vBox').style.left = window.event.clientX - document.getElementById('vZone').offsetLeft - 4; //window.event.x-9;
				if (parseInt(document.getElementById('vBox').style.left) > 35) document.getElementById('vBox').style.left=35;
				if (parseInt(document.getElementById('vBox').style.left) < 0) document.getElementById('vBox').style.left=0;
		}
	}

	function mouseUp()
	{
		if(isPorV==0){
			if(document.MediaPlayer.Duration>0){
				if (pFlag){
					var duration = document.MediaPlayer.Duration;
					document.MediaPlayer.CurrentPosition=duration * (parseInt(document.getElementById('pBox').style.left)/166);
					//alert(window.event.x +"-"+document.getElementById('pZone').style.left+"="+parseInt(document.getElementById('pBox').style.left)+"("+duration * (parseInt(document.getElementById('pBox').style.left)/139)+")");
				}
				pFlag = false;
			}
		}else if(isPorV==1){
			if (vFlag){
				//var volume = document.MediaPlayer.Volume;
				tempVol = (10 - (parseInt(document.getElementById('vBox').style.left)/3.5))*(-100);
				//alert(tempVol);
				document.MediaPlayer.Volume=Math.round(tempVol);//duration * (parseInt(document.getElementById('vBox').style.left)/139);
				//alert(window.event.x +"-"+document.getElementById('pZone').style.left+"="+parseInt(document.getElementById('pBox').style.left)+"("+duration * (parseInt(document.getElementById('pBox').style.left)/139)+")");
			}
			vFlag = false;
		}
	}

	function mouseEnd()
	{
		if(document.MediaPlayer.Duration>0){
			window.event.returnValue = false;
		}
	}

	function FixPos(){
		if(document.MediaPlayer.Duration>0){
			var duration = document.MediaPlayer.Duration;
			var pos = document.MediaPlayer.CurrentPosition;
			if (pos == 0)
			{
				var pBoxPos = Math.round(pos/duration*166)-5;
			}
			else{
				var pBoxPos = Math.round(pos/duration*166);
			}
			if (!isNaN(pBoxPos)) document.getElementById('pBox').style.left = pBoxPos;
			//alert(Math.round(pos/duration*200));
			if(document.MediaPlayer.PlayState==0) toStop();
			//if(document.MediaPlayer.Duration==document.MediaPlayer.CurrentPosition) toStop();
		}
	}
	/*
	function ShowState(){
		myObj = document.getElementById('PlayState');
		switch (document.MediaPlayer.PlayState){
			case 0:
				myObj.innerText = '已停止';
				break;
			case 1:
				myObj.innerText = '已暂停';
				break;
			case 2:
				myObj.innerText = '播放中';
				break;
			case 3:
				myObj.innerText = '读取缓冲';
				fFlag= true;
				break;
			case 4:
				myObj.innerText = 'Stream is scanning forward';
				break;
			case 5:
				myObj.innerText = 'Stream is scanning in reverse';
				break;
			case 6:
				myObj.innerText = 'Skipping to next';
				break;
			case 7:
				myObj.innerText = 'Skipping to previous';
				break;
			case 8:
				myObj.innerText = '未打开任何影音文件';
				break;
			default:
				myObj.innerText = '';
		}
	
	//0 mpStopped Playback is stopped. 
	//1 mpPaused Playback is paused. 
	//2 mpPlaying Stream is playing. 
	//3 mpWaiting Waiting for stream to begin. 
	//4 mpScanForward . 
	//5 mpScanReverse Stream is scanning in reverse. 
	//6 mpSkipForward Skipping to next. 
	//7 mpSkipReverse Skipping to previous. 
	//8 mpClosed Stream is not open. 
	
	}
	setInterval("ShowState()",500);
	*/

	function VolumeUp(vol){
		/*050206-guowei1
		tempVol = (9 - vol)*(-100);
		if(tempVol < (-500)) tempVol-=200;
		//alert(tempVol);
		document.MediaPlayer.Volume= tempVol;
		for(var i=1;i<=vol;i++){
			document.images['vol'+i].src = 'http://image2.swingsmedia.com.cn/dongman/BN/sitebao_wingsmedia/images/playerSkin/vod023_'+i+'o.gif';
		}
		for(var i=vol+1;i<=9;i++){
			document.images['vol'+i].src = 'http://image2.swingsmedia.com.cn/dongman/BN/sitebao_wingsmedia/images/playerSkin/vod023_'+i+'.gif';
		}*/
		tempVol = (10 - vol)*(-100);
		document.MediaPlayer.Volume= tempVol;
		document.getElementById('vBox').style.left = vol/10*35;
	}


	function checkstat()
			{
				//alert('out'+document.MediaPlayer.PlayState)
				if (document.MediaPlayer.PlayState==0||document.MediaPlayer.PlayState==8){
					//alert(document.MediaPlayer.PlayState)
					toPlay2();
					clearInterval(idTmr);
					GetObj('hideScreen').innerHTML=tempHTML;
					broadFile = tempFile;
				}else{}
			}
	var tempHTML;
	var tempFile;
	function ChgVideo(filename){
			var tempCurB = curBroad;
			var tempCurN = curNarrow;

			toStop();
			document.MediaPlayer.AutoStart="True";
			curBroad = tempCurB;
			curNarrow = tempCurN;

			tempHTML = GetObj('hideScreen').innerHTML;
			tempFile = broadFile;
			GetObj('hideScreen').innerHTML='<div align=center><font color=white>视频加载中</font></div>';
			broadFile = filename;
			document.MediaPlayer.FileName=filename;
			//for the issue AutoPlay=True;
				document.images("playControl").src = "/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_08.gif";
				document.images("stopControl").src = "/sitebao_wingsmedia/images/playerSkin/gw_bn_mp_09.gif";
				isPlayO = true;
				isStopO = false;
				isPauseO = false;
			//end
			//idTmr = setInterval("checkstat()",300);//No need to SetInterval when AutoPlay==True;
	}

		function ChgBN(bFile,nFile){
		curBroad = bFile;
		curNarrow = nFile;
		curFile = curBroad;
		CheckBand();
		ChgVideo((document.myForm.band[0].checked)?curBroad:curNarrow);
	}

	function CheckBand(){
			if (kbps > 300)
			{
					if (curBroad == "" || curBroad==null)
					{
						curFile=curNarrow;
					}
					else
					{
						curFile=curBroad;
					}
			}
			else if(kbps > 90)
			{
					curFile=curNarrow;
			}
			else
			{
					curFile=curNarrow;
			}
			//alert(curFile+"\n"+curBroad+"<B:N>"+curNarrow)
	}
