// initialize global variables
var detectableWithVB = false;
var pluginFound = false;

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) || (!pluginFound && !redirectIfFound)) ) {
	// go away
	window.location = redirectURL;
	return pluginFound;
    } else {
	// stay here and return result of plugin detection
	return pluginFound;
    }	
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}




// DETECTION FLASH PLAYER

var flash2Installed = false;	// boolean. true if flash 2 is installed
var flash3Installed = false;	// boolean. true if flash 3 is installed
var flash4Installed = false;	// boolean. true if flash 4 is installed
var flash5Installed = false;	// boolean. true if flash 5 is installed
var flash6Installed = false;	// boolean. true if flash 6 is installed
var flash7Installed = false;	// boolean. true if flash 7 is installed
var flash8Installed = false;	// boolean. true if flash 8 is installed
var flash9Installed = false;	// boolean. true if flash 9 is installed
var maxVersion		= 9;		// highest version we can actually detect
var actualVersion	= 0;		// version the user really has
var hasRightVersion = false;	// boolean. true if it's safe to embed the flash movie in the page

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;				// true if we're on ie
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;	// true if we're on windows


/*function detectFlash() {

	if(isIE && isWin) {
		// Write vbscript detection on ie win. IE on Windows doesn't support regular JavaScript plugins array detection.
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
		document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
		document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
		document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
		document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
		document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
		document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
		document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
		document.write('<\/SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
	}

	if(navigator.plugins && (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) ) {
		var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
		var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

		var flashVersion = parseInt(flashDescription.substring(16));
		flash2Installed = flashVersion == 2;
		flash3Installed = flashVersion == 3;
		flash4Installed = flashVersion == 4;
		flash5Installed = flashVersion == 5;
		flash6Installed = flashVersion == 6;
		flash7Installed = flashVersion == 7;
		flash8Installed = flashVersion == 8;
		flash9Installed = flashVersion >= 9;
	}
  
	// Loop through all versions we're checking, and set actualVersion to highest detected version.
	for(var i = 2; i <= maxVersion; i++)
		if(eval("flash" + i + "Installed") == true)
			actualVersion = i;
  
	// If we're on msntv (formerly webtv), the version supported is 4 (as of January 1, 2004).
	// Note that we don't bother sniffing varieties of msntv. You could if you were sadistic...
	if(navigator.userAgent.indexOf("WebTV") != -1)
		actualVersion = 4;
  
	return actualVersion;

//	if(actualVersion < requiredVersion)
//		window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
}
*/

function printFlashError(actualVersion, neededVersion) {
	if(!neededVersion)
		neededVersion = 7;

	//document.writeln("<br><br><br>");
	if(actualVersion >= 2)
		document.writeln("<h2>You are still using<br>an older version of Flash player</h2><br><br>");
	else
		document.writeln("<h2>You do not have the flash player installed</h2><br><br>");
	document.writeln("<h3>You must have Flash Player "+ neededVersion +"<br>installed on your computer</h3>");
	document.writeln("<br><a style='color:#C40000' href=\"http://www.macromedia.com/go/getflashplayer\" target=_blank title=\"Click to install the latest version of Flash player\" onmouseover=\"window.status='Click to install the latest version of Flash player'; return true\" onmouseout=\"window.status=''; return true\"><img src=\"/img/get_flashplayer.gif\" border=0 width=88 height=31 alt=\"Get Flash player\"><br>");
	document.writeln("<b>Click here to install the latest version of Flash player</b></a>");
//	document.writeln("<br><p style='font-size:9px'>Macromedia and Flash are trademarks of Macromedia, Inc.</p>");
	//window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
}


function printFlashObject(ID, objectAttributes, FlashSRC, MoreParams) {
	html = "";
	html += "\n"+ ('<object '+ (ID ? "name1='"+ID+"'" : "") +' '+ (ID ? "id='"+ID+"'" : "") +' '+ objectAttributes +' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0">');
	html += "\n"+ ('<param name=movie value="'+ FlashSRC +'" />');
	if(MoreParams)
		html += "\n"+ (MoreParams);
	html += "\n"+ ("<param name=quality value=high />");
	//html += "\n"+ ("<param name=wmode value=transparent />");
	html += "\n"+ ("<param name=allowFullScreen value=true />");	
	if(MoreParams) {
		MoreParamsEmbed = MoreParams.replace("<param name=\"", "");
		MoreParamsEmbed = MoreParamsEmbed.replace("\" value=", "=");
		MoreParamsEmbed = MoreParamsEmbed.replace(">", "");
	}
	else
		MoreParamsEmbed = "";

	html += "\n"+ ('<embed '+ (ID ? "name='"+ID+"'" : "") +' '+ (ID ? "id1='"+ID+"'" : "") +' '+ objectAttributes +' '+ MoreParamsEmbed +' src="'+ FlashSRC +'" quality=high allowFullScreen=true '); //wmode=transparent 
	html += "\n"+ ("pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\">");
	html += "\n"+ ("</embed>");
	html += "\n"+ ("</object>");
//alert(html);
	document.writeln(html);
}


function printFLVPlayer(source, width, height, quality) {

	flash_version = detectFlash();

	if(flash_version < 8) {
		document.writeln("<center style=\"border:1px solid #CCC; padding:10px\">");
		printFlashError(flash_version, 8);
		document.writeln("</center>");
		return false;
	}
	

	if(flash_version >= 9)
		flvplayer_src = "WSPlayer.swf";
	else {
		if(!height)
			height = "93%";
		else {
			if(isNaN(height-20)) {
				height = height.substring(0, height.length-1);
				height = height - 4;
				height += "%";
			}
			else
				height = height - 20;
		}

		flvplayer_src = "WSPlayerV8.swf";
	}

	if(!width)
		width = "100%";
	if(!height)
		height = "100%";

	if (quality == "high") {
		printFlashObject("FLVPlayer", "width=\""+ width +"\" height=\""+ height +"\"", "/flash/"+ flvplayer_src +"?autostart=true&help=false&streaming=1&source="+ source);
	} else {
		printFlashObject("FLVPlayer", "width=\""+ width +"\" height=\""+ height +"\"", "/flash/"+ flvplayer_src +"?autostart=true&help=false&source="+ source);
	}
		
	if(flash_version < 9)
		document.writeln("<div class=little>To view the video in fullscreen, please install <a target=_blank href=\"\">Flash Player 9</a></div>");




}

function crypt(str, d) {
	res = "";
	for(var i=0;i<str.length;i++)
		res+=String.fromCharCode(str.charCodeAt(i)+d);
	return res;
}

