//Video Ad Script,IE only 
//Ver 2.0
//bulid 2006-12-25

var videoAfpPicShowTimes = 15000;	//此处定义非WindowsMedia视频广告的默认插播时间。单位（毫秒）
var videoAfpInsertSign = 0;	//请勿更改此项
var videoAfpBarHeight = 64;
var videoAfpVideoHeight = 304;
var videoAfpStopChecker;
var videoAfpChecker;
var videoAfpPlayState = 0;
var videoAfpPicShowTime;
var videoBefore;
var videoAfter;


function videoAfpInsertAd(s)
{
	var regS = new RegExp("<script","gi");
	s = s.replace(regS,"<script DEFER");
	videoAfpLayer.innerHTML = s;
}

function insertFlash(elm, url, w, h, id) {//flash广告所需要的函数
 if (!document.getElementById(elm)) return;
 var str = '';
 str += '<embed width="'+ w +'" height="'+ h +'" src="'+ url +'" quality="autohigh" wmode="opaque" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" id='+id+'></embed>';
 document.getElementById(elm).innerHTML = str;
}

function videoAfpControlsPause()
{
	mainPlayer.controls.pause();
}

function videoAfpControlsPlay()
{
	if (videoAfpPlayState != 2 && videoAfpPlayState != 4)return;
	mainPlayer.controls.play();
}

function videoAfpTransDisplay(s)
{
	if (1 == s)
	{
		videoAfpLayer.style.display = "block";
		mainPlayer.height = videoAfpBarHeight;
		videoAfpOverlay.style.display = "block";
		
		return;
	}	
	videoAfpLayer.innerHTML = "";
	videoAfpScriptLayer.innerHTML = "";

	videoAfpLayer.style.display = "none";
	mainPlayer.height = videoAfpVideoHeight;
	videoAfpOverlay.style.display = "none";
}

function videoAfpPlay()
{
	if (videoAfpInsertSign == 0)return;

	if (document.getElementById("mainPlayer"))mainPlayer.settings.mute = true;

	if (videoBefore)
	{
		videoAfpScript(videoBefore,1);
	}
	else
	{
		videoAfpStart();
	}
}

function videoAfpCheck()
{
	if (AdPlayer.playState == 0 && AdPlayer.openState == 6)
	{
		if (videoAfpPlayState == 3)
		{
			videoAfpTransDisplay();
			videoAfpPlayState = 4;
		}
		else
		{
			videoAfpStart();
		}

		clearInterval(videoAfpChecker);
	}
}

function videoAfpStopCheck()
{
	if (document.getElementById("mainPlayer"))
	{
		if (mainPlayer.playState == 3 && videoAfpPlayState == 0 && mainPlayer.network.frameRate > 200)
		{
			videoAfpPlayState = 1;
			videoAfpControlsPause();
		}
		if (mainPlayer.playState == 1 && videoAfpPlayState == 2)
		{
			videoAfpPlayState = 3;
			clearInterval(videoAfpStopChecker);

			if (videoAfter)
			{
				videoAfpScript(videoAfter,2);
			}
			else
			{
				videoAfpPlayState = 4;
			}
		}
	}
}

function videoAfpTimer()
{
	if (videoAfpPlayState == 3)
	{
		videoAfpTransDisplay();
		videoAfpPlayState = 4;
	}
	else
	{
		videoAfpStart();
	}
}


function videoAfpStart()
{
	videoAfpTransDisplay();
	videoAfpPlayState = 2;
	videoAfpControlsPlay();
	mainPlayer.settings.mute = false;
}

function videoAfpScript(uri,mode)
{
	videoAfpPicShowTime = videoAfpPicShowTimes;

	var _script = document.createElement("script");
	_script.src = uri;
	_script.onreadystatechange = function(){videoAfpScriptCheck(this,mode);};
	videoAfpScriptLayer.appendChild(_script);
}

function videoAfpScriptCheck(obj,mode)
{
	if(obj.readyState == 'loaded' || obj.readyState == 'complete')
	{
		if(videoAfpLayer.innerHTML != "")
		{
			if(2 == mode)
			{
				videoAfpTransDisplay(1);
			}
				
			if(document.getElementById("AdPlayer"))
			{
				videoAfpChecker = setInterval(videoAfpCheck,500);
			}
			else
			{
				setTimeout(videoAfpTimer,videoAfpPicShowTime);
			}

		}
		else
		{
			if(1 == mode)
			{	
				videoAfpStart();
			}
			if(2 == mode)
			{	
				videoAfpPlayState = 4;
			}
		}
	}
}


function videoAfpInsertVideo(src,width,height)
{
	videoAfpVideoHeight = height + videoAfpBarHeight;

	if (videoAfpInsertSign)
	{
		document.write("<div id='videoAfpPosLayer' style='position:relative;width:"+width+"px;height:"+videoAfpVideoHeight+"px;z-index:1'><div id='videoAfpMainLayer' style='position:absolute;width:"+width+"px;height:"+videoAfpVideoHeight+"px;z-index:2;left:0px;top:0px'><table width="+width+" height="+(height+videoAfpBarHeight)+" border=0 cellpadding=0 cellspacing=0 bgcolor='#000000'><tr><td valign='bottom'><OBJECT id=mainPlayer height="+videoAfpBarHeight+" width="+width+" classid=clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6><PARAM NAME='URL' VALUE='"+src+"'><PARAM NAME='rate' VALUE='1'><PARAM NAME='balance' VALUE='0'><PARAM NAME='currentPosition' VALUE='0'><PARAM NAME='defaultFrame' VALUE=''><PARAM NAME='playCount' VALUE='1'><PARAM NAME='autoStart' VALUE='1'><PARAM NAME='currentMarker' VALUE='0'><PARAM NAME='invokeURLs' VALUE='-1'><PARAM NAME='baseURL' VALUE=''><PARAM NAME='volume' VALUE='50'><PARAM NAME='mute' VALUE='0'><PARAM NAME='uiMode' VALUE='full'><PARAM NAME='stretchToFit' VALUE='-1'><PARAM NAME='windowlessVideo' VALUE='0'><PARAM NAME='enabled' VALUE='-1'><PARAM NAME='enableContextMenu' VALUE='-1'><PARAM NAME='fullScreen' VALUE='0'><PARAM NAME='SAMIStyle' VALUE=''><PARAM NAME='SAMILang' VALUE=''><PARAM NAME='SAMIFilename' VALUE=''><PARAM NAME='captioningID' VALUE=''><PARAM NAME='enableErrorDialogs' VALUE='0'><PARAM NAME='_cx' VALUE='6482'><PARAM NAME='_cy' VALUE='6350'></OBJECT></td></tr></table></div><div id='videoAfpLayer' align='left' style='position:absolute;width:"+width+"px;height:"+height+"px;z-index:3;left:0px;top:0px;'></div><div id='videoAfpOverlay'  style='position:absolute;width:"+width+"px;height:"+videoAfpBarHeight+"px;z-index:4;left:0px;top:"+height+"px;'><table width="+width+" height="+videoAfpBarHeight+" border=0 cellpadding=0 cellspacing=0><tr><td colspan=2 height=5></td></tr><tr><td width="+(width-100)+" height=14></td><td width=100 style='font-size:9pt;color:#CCCCCC' bgcolor='#000000'>正在插播广告…</td></tr><tr><td colspan=2 height=45></td></tr></table></div><div id='videoAfpScriptLayer' align='left' style='position:absolute;width:10px;height:10px;z-index:1;left:0px;top:0px;display:none'></div></div>");
	}
	else
	{
		document.write("<EMBED type='application/x-mplayer2' src="+src+" width="+width+" height="+videoAfpVideoHeight+" balance='true' showpositioncontrols='true' showtracker='true' showaudiocontrols='true' showcontrols='true' showstatusbar='true' showdisplay='true' volume='50' autosize='true' autostart='true' animationatstart='true' transparentatstart='true' stretchtofit='true'></EMBED>");
	}
}

if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
	videoAfpStopChecker = setInterval(videoAfpStopCheck,200);
	videoAfpInsertSign = 1;
}
