var videoAdURL = "";
var videoAdClickURL = "";
var orgVideoURL = new Array();
document.domain = "tvb.com";

function setVideo(){
	for (i=0; i<arguments.length; i++){
		with(document){
			writeln('<SCR'+'IPT FOR="'+arguments[i]+'"');
			writeln('        EVENT="EndOfStream()" ');
			writeln('        LANGUAGE="JScript">');
			writeln('	if ('+arguments[i]+'.FileName == videoAdURL){');
			writeln('		if (videoAdClickURL != ""){');
			writeln('			'+arguments[i]+'.ClickToPlay = true;');
			writeln('			'+arguments[i]+'.SendMouseClickEvents = false;');
			writeln('		}');
			writeln('		if (document.images["advertisement"]){');
			writeln('			document.images["advertisement"].src = "http://marketing.tvb.com/sitecommon/images/video/spacer.gif";');
			writeln('		}');
			writeln('		'+arguments[i]+'.FileName = orgVideoURL["'+arguments[i]+'"];');
			writeln('		setTimeout("'+arguments[i]+'.Play()",500);');
			writeln('	}');
			writeln('</SCR'+'IPT>');
			writeln('<SCR'+'IPT FOR="'+arguments[i]+'"');
			writeln('        EVENT="Click()" ');
			writeln('        LANGUAGE="JScript">');
			writeln('   if (videoAdClickURL != ""){');
			writeln('   	adWin = window.open(videoAdClickURL,"adWin","");');
			writeln('   	adWin.focus();');
			writeln('   }');
			writeln('</SCR'+'IPT>');
		}
	}
}

function setMediaPlayer(){
	for (i=0; i<arguments.length; i++){
		with(document){
			writeln('<SCR'+'IPT FOR="'+arguments[i]+'"');
			writeln('        EVENT="EndOfStream()" ');
			writeln('        LANGUAGE="JScript">');
			writeln('	if ('+arguments[i]+'.FileName == videoAdURL){');
			writeln('		if (videoAdClickURL != ""){');
			writeln('			'+arguments[i]+'.ClickToPlay = true;');
			writeln('			'+arguments[i]+'.SendMouseClickEvents = false;');
			writeln('		}');
			writeln('		if (document.images["advertisement"]){');
			writeln('			document.images["advertisement"].src = "http://marketing.tvb.com/sitecommon/images/video/spacer.gif";');
			writeln('		}');
			writeln('		'+arguments[i]+'.FileName = orgVideoURL["'+arguments[i]+'"];');
			writeln('		setTimeout("'+arguments[i]+'.Play()",500);');
			writeln('	}');
			writeln('</SCR'+'IPT>');
			writeln('<SCR'+'IPT FOR="'+arguments[i]+'"');
			writeln('        EVENT="Click()" ');
			writeln('        LANGUAGE="JScript">');
			writeln('   if (videoAdClickURL != ""){');
			writeln('   	adWin = window.open(videoAdClickURL,"adWin","");');
			writeln('   	adWin.focus();');
			writeln('   }');
			writeln('</SCR'+'IPT>');
		}
	}
}

function setAllMediaPlayer(){
	for (i=0; i<document.all.tags("object").length; i++){
		if ((document.all.tags("object")[i].classid == "CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95") || (document.all.tags("object")[i].classid == "CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"))
			with(document){
				writeln('<SCR'+'IPT FOR="'+document.all.tags("object")[i].id+'"');
				writeln('        EVENT="EndOfStream()" ');
				writeln('        LANGUAGE="JScript">');
				writeln('   if ('+arguments[i]+'.FileName == videoAdURL){');
				writeln('		if (videoAdClickURL != ""){');
				writeln('			'+document.all.tags("object")[i].id+'.ClickToPlay = true;');
				writeln('			'+document.all.tags("object")[i].id+'.SendMouseClickEvents = false;');
				writeln('		}');
				writeln('		if (document.images["advertisement"]){');
				writeln('			document.images["advertisement"].src = "http://marketing.tvb.com/sitecommon/images/video/spacer.gif";');
				writeln('		}');
				writeln('		'+document.all.tags("object")[i].id+'.FileName = orgVideoURL["'+arguments[i]+'"];');
				writeln('		setTimeout("'+document.all.tags("object")[i].id+'.Play()",500);');
				writeln('	}');
				writeln('</SCR'+'IPT>');
				writeln('<SCR'+'IPT FOR="'+document.all.tags("object")[i].id+'"');
				writeln('        EVENT="Click()" ');
				writeln('        LANGUAGE="JScript">');
				writeln('   if (videoAdClickURL != ""){');
				writeln('   	adWin = window.open(videoAdClickURL,"adWin","");');
				writeln('   	adWin.focus();');
				writeln('   }');
				writeln('</SCR'+'IPT>');
			}
	}
}

function showAdvertisement(){
	document.write('<img name=advertisement src="http://marketing.tvb.com/sitecommon/images/video/spacer.gif" border=0>');
}

function videoType(playpath){
	if (playpath.indexOf("56k.asx") > -1 || playpath.indexOf("_n.asx") > -1)
		return "56k";
	if (playpath.indexOf("300k.asx") > -1 || playpath.indexOf("_b.asx") > -1)
		return "300k";
	return "";
}

function PlayVideo(playid, playpath){
	if ((navigator.userAgent.indexOf("IE") > -1) && (navigator.platform == "Win32")){
		//videoAdWin = window.open("http://marketing.tvb.com/sitecommon/sales_video.html?"+videoType(playpath)+"&","videoAdWin","width=1,height=1,location=0,menubar=0,status=0,toolbar=0,directories=0,scrollbars=0,resizable=0,top=10000,left=10000");
		setTimeout("PlayVideo2('"+playid+"', '"+playpath+"')", 500);
	}else{
		PlayVideo2(playid,playpath);
	}
}

function PlayVideo2(playid, playpath){
	if (navigator.platform == "Win32"){
		if (navigator.userAgent.indexOf("IE") > -1){
			orgVideoURL[playid] = playpath;
			eval(playid + ".autoStart = true;");
			if (videoAdURL != ""){
				if (videoAdClickURL != ""){
					eval(playid + ".SendMouseClickEvents = true;");
					eval(playid + ".ClickToPlay = false;");
					eval(playid + ".CursorType = 1;");
				}
				eval(playid + ".Filename = '" + videoAdURL + "';");
				if (document.images["advertisement"])
					document.images["advertisement"].src = "http://marketing.tvb.com/sitecommon/images/video/advertisement.gif";
			}else{
				eval(playid + ".Filename = '" + orgVideoURL[playid] + "';");
			}
		}else{
			//eval("document." + playid + ".SetAutoStart(true);");
			//eval("document." + playid + ".SetFileName('" + playpath + "');");
		}
	}else{
		if (navigator.userAgent.indexOf("IE") > -1){
			this.location = playpath;
		}else{
			temp = window.open(playpath,"temp","width=1,height=1,top=10000,left=10000");
			temp.blur();
			setTimeout("temp.close();",100);
		}
	}
}

function PlayAsx(playpath){
	if (navigator.userAgent.indexOf("IE") > -1){
		if (navigator.platform == "Win32"){
			if (playpath.charAt(0) == "/")
				playpath = this.location.href.substring(0,this.location.href.indexOf("tvb.com")+7) + playpath
			if (playpath.indexOf("http://") != 0)
				playpath = this.location.href.substring(0,this.location.href.lastIndexOf("/")+1) + playpath
			//videoAdWin = window.open("http://marketing.tvb.com/sitecommon/sales_video.html?"+videoType(playpath)+"&"+playpath,"videoAdWin","width=330,height=290,location=0,menubar=0,status=0,toolbar=0,directories=0,scrollbars=0,resizable=0");
			//videoAdWin.focus();
		}else{
			this.location = playpath;
		}
	}else{
		temp = window.open(playpath,"temp","width=1,height=1,top=10000,left=10000");
		temp.blur();
		setTimeout("temp.close();",100);
	}
}
