// This script will add the Player preference box on video pages.  Based on the selection, it will load the appropriate player and play the video. HJB
var gstrPlayer = "";
var gstrSpeed = "";
var gstrWidth = "";
var gstrHeight = "";
var gstrLang = "";
var gstrVid = "";
var gstrErr = "";
// following are for displaying the text in the createWindow box
var gstrParagraph = "Выберите плеер и скорость соединения:‎";
var gstrHeadingSpeed = "Скорость соединения";
var gstrHeadingPlayer = "Медиаплеер";
var gstrSpeedHigh = "Высокое качество (High)";
var gstrSpeedMedium = "Среднее качество (Medium)‎";
var gstrSpeedLow = "Низкое качество (Low)‎";
var gstrSelect = "OK";
var gstrErr = "Для просмотра этого файла на вашем компьютере должна быть установлена программа Adobe Flash Player.";

	window.onload=selectPlayer;

function selectPlayer() {
	//collects the video name and language symbols from the filename
	var urlPath = window.location.pathname.split("/");
	var file = urlPath[urlPath.length-1];
	gstrVidTemp = file.replace(/\.htm$/i, "");
	// lastIndexOf & slice functions -->first character is at index 0
	gstrLang = gstrVidTemp.slice(gstrVidTemp.lastIndexOf("-")+1);
	gstrVid = gstrVidTemp.slice(0,gstrVidTemp.lastIndexOf("-")+1);
	document.getElementById("player").innerHTML = "<div id=\"select\"><p>" + gstrParagraph + "</p><form><h4>" + gstrHeadingPlayer + "</h4><input type=\"radio\" name=\"player\" id=\"flash\" value=\"Flash Player\" checked>Flash Player<br><input type=\"radio\" name=\"player\" id=\"qt\" value=\"QuickTime\">QuickTime<br><input type=\"radio\" name=\"player\" id=\"wmp\" value=\"Windows Media Player\">Windows Media Player<br><hr><h4>" + gstrHeadingSpeed + "</h4><input type=\"radio\" name=\"speed\" id=\"low\" value=\"Low\" checked>" + gstrSpeedLow + "<br><input type=\"radio\" name=\"speed\" id=\"med\" value=\"Medium\">" + gstrSpeedMedium + "<br><input type=\"radio\" name=\"speed\" id=\"high\" value=\"High\">" + gstrSpeedHigh + "<br><input type=\"button\" id=\"select\" value=\"" + gstrSelect + "\" title=\"" + gstrSelect + "\" onClick=\"javascript:makePlayer();\"></form></div>";
}

//adds the appropriate player
function  makePlayer() {
	//player type
	if (document.getElementById("flash").checked == true){
	gstrPlayer = ".swf";
	}
	if (document.getElementById("wmp").checked == true){
	gstrPlayer = ".wvx";
	}
	if (document.getElementById("qt").checked == true){
	gstrPlayer = ".mov";
	}
	
	//player size
	if (document.getElementById("low").checked == true){
		//gstrSpeed = "320180";
		gstrSpeed = "180";
		if(document.getElementById("flash").checked == true){
			gstrWidth = "342";
			gstrHeight = "231";
		}else if(document.getElementById("qt").checked == true){
			gstrWidth = "320";
			gstrHeight = "196";
		}else{
			gstrWidth = "320";
			gstrHeight = "256";
		}
	}
	if (document.getElementById("med").checked == true){
		//gstrSpeed = "430240";
		gstrSpeed = "240";
		if(document.getElementById("flash").checked == true){
			gstrWidth = "452";
			gstrHeight = "291";
		}else if(document.getElementById("qt").checked == true){
			gstrWidth = "430";
			gstrHeight = "256";
		}else{
			gstrWidth = "430";
			gstrHeight = "316";
		}	
	}
	if (document.getElementById("high").checked == true){
		gstrSpeed = "360";
		if(document.getElementById("flash").checked == true){
			gstrWidth = "662";
			gstrHeight = "411";
		}else if(document.getElementById("qt").checked == true){
			gstrWidth = "640";
			gstrHeight = "376";
		}else{
			gstrWidth = "640";
			gstrHeight = "436";
		}	
	}

	if(gstrPlayer == ".swf") {
		document.getElementById('player').innerHTML = "<a href=\"javascript:history.go(0)\"><img src=\"/images/refresh.gif\" width=\"30\" height=\"24\" border=\"0\"></a><br><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"" + gstrWidth + "\" height=\"" + gstrHeight + "\" id=\"FLVPlayer\"><param name=\"movie\" value=\"" + gstrVid + gstrSpeed + gstrLang + gstrPlayer + "\"><param name=\"salign\" value=\"lt\"><param name=\"quality\" value=\"high\"><param name=\"scale\" value=\"noscale\"><param name=\"allowscriptaccess\" value=\"sameDomain\"><param name=\"FlashVars\" value=\"&MM_ComponentVersion=1&skinName=Halo_Skin_2&streamName=" + gstrVid + gstrSpeed + gstrLang + "&autoPlay=true&autoRewind=false\"><!--[if !IE]>--><object type=\"application/x-shockwave-flash\" data=\"" + gstrVid + gstrSpeed + gstrLang + gstrPlayer + "\" width=\"" + gstrWidth + "\" height=\"" + gstrHeight + "\" id=\"FLVPlayer\"><param name=\"salign\" value=\"lt\"><param name=\"quality\" value=\"high\"><param name=\"scale\" value=\"noscale\"><param name=\"allowscriptaccess\" value=\"sameDomain\"><param name=\"FlashVars\" value=\"&MM_ComponentVersion=1&skinName=Halo_Skin_2&streamName=" + gstrVid + gstrSpeed + gstrLang + "&autoPlay=true&autoRewind=false\"><!--<![endif]--><p>" + gstrErr +"</p><!--[if !IE]>--></object><!--<![endif]--></object>";
	}
	if(gstrPlayer == ".wvx") {
		document.getElementById('player').innerHTML = "<a href=\"javascript:history.go(0)\"><img src=\"/images/refresh.gif\" width=\"30\" height=\"24\" border=\"0\"></a><br><object classid=\"clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6\" width=\"" + gstrWidth + "\" height=\"" + gstrHeight + "\" id=\"wmp10\" type=\"application/x-oleobject\"><param name=\"url\" value=\"" + gstrVid + gstrSpeed + gstrLang + gstrPlayer + "\"><param name=\"showcontrols\" value=\"true\"><param name=\"autostart\" value=\"true\"><param name=\"ShowDisplay\" value=\"false\"><param name=\"uiMode\" value=\"full\"><param name=\"loop\" value=\"false\"><embed type=\"application/x-mplayer2\" src=\"" + gstrVid + gstrSpeed + gstrLang + gstrPlayer + "\" width=\"" + gstrWidth + "\" height=\"" + gstrHeight + "\" showcontrols=\"1\" showdisplay=\"0\" autostart=\"1\" loop=\"false\"></embed></object>";
	}
	if(gstrPlayer == ".mov") {
		document.getElementById('player').innerHTML = "<a href=\"javascript:history.go(0)\"><img src=\"/images/refresh.gif\" width=\"30\" height=\"24\" border=\"0\"></a><br><object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" width=\"" + gstrWidth + "\" height=\"" + gstrHeight + "\" type=\"video/quicktime\" codebase=\"http:\/\/www.apple.com\/qtactivex\/qtplugin.cab\"><param name=\"src\" value=\"" + gstrVid + gstrSpeed + gstrLang + gstrPlayer + "\"><param name=\"qtsrc\" value=\"" + gstrVid + gstrSpeed + gstrLang + gstrPlayer + "\"><param name=\"autoplay\" value=\"true\"><param name=\"controller\" value=\"true\"><param name=\"loop\" value=\"false\"><param name=\"showlogo\" value=\"false\"><embed src=\"" + gstrVid + gstrSpeed + gstrLang + gstrPlayer + "\" qtsrc=\"" + gstrVid + gstrSpeed + gstrLang + gstrPlayer + "\" width=\"" + gstrWidth + "\" height=\"" + gstrHeight + "\" autoplay=\"true\" controller=\"true\" loop=\"false\" type=\"video/quicktime\" showlogo=\"false\" pluginspage=\"http:\/\/www.apple.com/quicktime/download/\"></embed></object>";
	}

}
