// browser/plugin config flags
var ie = false;
var ns = false;
var win = false;
var mac = false;
var browserVer = 0;

// right browser/plugin flag
var flashedAndReady = false;

// check whether or not browser is able to detect for plugin
function canDetectFlash() {
	// Determine the browser (IE or Netscape) using navigator.appName
	ie = (navigator.appName.toLowerCase().indexOf("microsoft") != -1);
	ns = (navigator.appName.toLowerCase().indexOf("netscape") != -1);

	// Determine the platform using navigator.userAgent
	win = (navigator.userAgent.toLowerCase().indexOf("win") != -1);
	mac = (navigator.userAgent.toLowerCase().indexOf("mac") != -1);

	// Determine the browser version
	browserVer = parseFloat(ie ? navigator.appVersion.substring(navigator.appVersion.toLowerCase().indexOf("msie") + 4) : navigator.appVersion);

	// Return the appropriate value based on the browser, version and platform
	if (ie && win) return (browserVer >= 4.0) // Works in Windows IE 4.0 and better
	if (ie && mac) return (browserVer >= 5.0) // Works in Mac IE 5.0 and better
	if (ns) return (browserVer >= 3.0) // Works in Netscape 3.0 and up

	// If none of the above conditions matched, the browser is unknown and likely doesn't support detection
	return false;
}

// get flash plugin version
function getFlashVersion() {
	// Set local variables to avoid crashing bug
	var thearray = navigator.plugins;
	var arraylength = thearray.length;

	for (i=0; i < arraylength; i++) {
		// retrieve the plugin
		theplugin = thearray[i];

		// get the plugin name
		thename = theplugin.name;

		// get the plugin description
		thedesc = theplugin.description;

		// If the plugin is the flash player
		if (thedesc.indexOf("Flash") != -1) {
			// parse out the version
			versionString = thedesc.substring(thedesc.indexOf("Flash") + 5);

			// pet the major version
			majorVersion = parseInt(versionString);

			// and return it
			return majorVersion;
		}
	}
	// If we've went through the whole list of plugins without finding Shockwave, we return zero.
	return 0;
}

function getFlash(lang) {
	var elang

	if (lang == "") {
		elang = "en"
	} else {
		elang = lang
	}

	var flashAnimation = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"" + 
	            " codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\"" + 
	            " width=\"740\" height=\"254\" VIEWASTEXT>" + 
	            "<param name=\"movie\" value=\"/flash/" + elang + "_KSM_home.swf\">" + 
	            "<param name=\"quality\" value=\"high\">" + 
	            "<embed src=\"/flash/" + elang + "_KSM_home.swf\" quality=\"high\"" +
	            " pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"" +
	            " type=\"application/x-shockwave-flash\" width=\"740\" height=\"254\">" + 
              "</embed>" + 
              "</object>";
	
	document.write(flashAnimation);
}

function getPhoto(lang) {
	var elang
	var imgAlt

	if (lang == "") {
		elang = "en"
	} else {
		elang = lang
	}

	var homePhoto = "<img src=\"/flash/" + elang + "_ksm_flash_alternative.jpg\" width=\"740\" height=\"254\" alt=\"\">";

	document.write(homePhoto);
}

// if detectable browser and ie on windows (got to call VBScript to get plugin version)
if (canDetectFlash() && ie && win) {
	// if flash plugin version is 4 or greater
	if ( VBGetFlashVersion() >= 4) {
		// set ready for flash
		flashedAndReady = true;
	} else {
		// set not ready for flash
		flashedAndReady = false;
	}
// else if other detectable browser which are ie and ns on mac or ns on win (got to call JavaScript to get plugin version)
} else if ( ( (canDetectFlash() && mac) || (canDetectFlash() && ns) ) ) {
	// if flash plugin version is 4 or greater
	if ( getFlashVersion() >= 4) {
		// set ready for flash
		flashedAndReady = true;
	} else {
		// set not ready for flash
		flashedAndReady = false;
	}
} else {
	// set not ready for flash
	flashedAndReady = false;
}
