var detectedVersion = -1;
var detectedMinorVersion = -1;

function getFlashVersion (baseVersion) {

	if (detectedVersion != -1) return detectedVersion;
	if (baseVersion == null) baseVersion = 10;

	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var pluginRef = navigator.plugins['Shockwave Flash'];
		if (pluginRef != null) {
			var verIndex = pluginRef.description.indexOf (".");
			var minorIndex = pluginRef.description.indexOf ("r");
			//alert (pluginRef.description.length);
			//alert (minorIndex);
			detectedVersion = parseInt (pluginRef.description.substr (verIndex - 1, 1));
			detectedMinorVersion = parseInt (pluginRef.description.substr (minorIndex - 1, pluginRef.description.length - 1));
		}
	}
	else if (navigator.userAgent.indexOf("MSIE") != -1 && parseInt(navigator.appVersion) >= 4 && navigator.platform == "Win32") {
		document.write('<scr' + 'ipt language="VBScript"\> \nPrivate i, x\nOn Error Resume Next\n controlPresent = False\nFor i = ' + baseVersion + ' To 1 Step -1\n');
		document.write('Set x = CreateObject("ShockwaveFlash.ShockwaveFlash." & i)\n controlPresent = IsObject(x)\nIf controlPresent Then\ndetectedVersion = CStr(i)\nExit For\nEnd If\nNext\n');		
		document.write('</scr' + 'ipt\> \n');
	}
	return detectedVersion;
}

/*
  * Params :
  * movieName - the name of the flash movie to embed (flash.swf)
  * failOverImage - The image that is displayed in place of the flash movie if the player is not detected
  * failOverURL - the URL for the fail over graphic
  * failOverTitle - the title/alt for the fail over graphic
  * width - the width of the flash movie in pixels
  * height - the height of the flash movie in pixels
  * baseVersion - the version of the plugin to test for. If the detected plugin version is less than the
  *              baseVersion specified, the fail over graphic will be displayed in place of the flash movie
  * bgcolor - the background color for the flash movie eg. #FFFFFF
  */

function flashEmbed (movieName, failOverImage, failOverURL, failOverTitle, failOverUsemap, width, height, baseVersion, bgcolor) {
	var version = getFlashVersion (baseVersion);
	if ((version != -1) && (version >= baseVersion)) {
		writeFlashTag (movieName, width, height, baseVersion, bgcolor);
	}
	else {
		if (failOverUsemap != "") {
			document.write ('<img src = "' + failOverImage + '" width="' + width + '" height="' + height + '" border="0" usemap="#' + failOverUsemap + '">');
		}
		else
		{
		    if (failOverURL != "") {
			    document.write ('<a href = "' + failOverURL + '"><img src = "' + failOverImage + '" width="' + width + '" height="' + height + '" border="0" title="' + failOverTitle + '"></a>');		
			}
			else
			{
			    document.write ('<img src = "' + failOverImage + '" width="' + width + '" height="' + height + '" border="0" title="' + failOverTitle + '">');		
			}
		}
	}
}

function writeFlashTag (movieName, width, height, baseVersion, bgcolor) {
	document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + baseVersion + ',0,0,0" width="' + width + '"height="' + height + '">\n<param name="movie" value="' + movieName + '">\n<param name="quality" value="high">\n<param name="bgcolor" value="' + bgcolor + '">\n');
	document.write ('<embed src="' + movieName + '" TYPE="application/x-shockwave-flash" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="' + width + '" height="' + height + '" bgcolor="' + bgcolor + '"></embed>\n</object>');		
	}

getFlashVersion ();

