/*EMBED FLASH INTO HTML
These functions embed a flash swf into a page.
They address the ActiveX update that Microsoft is implementing for IE.
User interaction will be automatically enabled, so that users will not be prompted to activate the swf.
embedFlash() takes 4 parameters and will embed a swf into the html page.
detectAndEmbedFlash() takes 5 parameters. It does the same thing as embedFlash. In addition, it performs flash detection and will display an alternative image if the user does not have flash installed.
*/
function embedFlash(swf_location,swf_bgcolor,swf_width,swf_height){
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" WIDTH="'+ swf_width +'" HEIGHT="'+ swf_height +'" >');
	document.write('<PARAM NAME=movie VALUE="' + swf_location + '">');
	document.write('<PARAM NAME="menu" VALUE="false">');
	document.write('<PARAM NAME="quality" VALUE="best">');
	document.write('<PARAM NAME="bgcolor" VALUE="'+ swf_bgcolor + '">');
	document.write('<PARAM NAME="wmode" VALUE="transparent">');
	document.write('<EMBED src="' + swf_location + '" menu="false" quality="best" bgcolor="'+ swf_bgcolor + '"   wmode="transparent"  WIDTH="'+ swf_width +'" HEIGHT="'+ swf_height +'" NAME="swf_movie" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
	
	document.write('</EMBED>');
	document.write('</OBJECT>');
}

function embedFlashVars(swf_location,swf_bgcolor,swf_width,swf_height,vars){
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" WIDTH="'+ swf_width +'" HEIGHT="'+ swf_height +'" >');
	document.write('<PARAM NAME=movie VALUE="' + swf_location + '">');
	document.write('<PARAM NAME="menu" VALUE="false">');
	document.write('<PARAM NAME="quality" VALUE="best">');
	document.write('<PARAM NAME="bgcolor" VALUE="'+ swf_bgcolor + '">');
	document.write('<PARAM NAME="FlashVars" VALUE="'+ vars + '">');
	document.write('<PARAM NAME="wmode" VALUE="transparent">');
	document.write('<EMBED src="' + swf_location + '" menu="false" quality="best" bgcolor="'+ swf_bgcolor + '"   wmode="transparent"  WIDTH="'+ swf_width +'" HEIGHT="'+ swf_height +'" NAME="swf_movie" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
	
	document.write('</EMBED>');
	document.write('</OBJECT>');
}


function detectAndEmbedFlash(swf_location,swf_bgcolor,swf_width,swf_height,alt_image){
	// Detect Flash plugin
	//   The global variable flashPresent will be set to 1 if the
	//   Flash plugin is present in the client browser, and 0 otherwise
	//   If flash not present, display the alternative image (alt_image)
	
	// If the client is using Windows, create an activeXDetect() function in VBScript to find the plugin
	var msie_windows = 0;
	if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
		msie_windows = 1;
		document.writeln('<script language="VBscript">');
		document.writeln('Dim vbDetect');
		document.writeln('vbDetect = 0');
		document.writeln('If ScriptEngineMajorVersion >= 2 then');
		document.writeln('  vbDetect = 1');
		document.writeln('End If');
		document.writeln('Function activeXDetect(activeXname)');
		document.writeln('  on error resume next');
		document.writeln('  If ScriptEngineMajorVersion >= 2 then');
		document.writeln('     activeXDetect = False');
		document.writeln('     activeXDetect = IsObject(CreateObject(activeXname))');
		document.writeln('     If (err) then');
		document.writeln('        activeXDetect = False');
		document.writeln('     End If');
		document.writeln('   Else');
		document.writeln('     activeXDetect = False');
		document.writeln('   End If');
		document.writeln('End Function');
		document.writeln('</'+'script>');
	}
	
	// detectFlash()
	//   Detects the Flash plugin
	//   Returns 1 if the Flash plugin is present in the client browser
	//           0, if the Flash plugin is not present
	function detectFlash() {
		var i,
			undetectable = 0,
			detected = 0,
			pluginObject = new Object();
	
		// Set defaults for Flash plugin
		ext = 'swf';
		mimeType = 'application/x-shockwave-flash';
		activeXname = 'ShockwaveFlash.ShockwaveFlash';
	
		// If the client is using Windows, detect using VBscript
		if (msie_windows && vbDetect) {
			undetectable = 0;
		} else {
			undetectable = 1;
		}
	
		// If the navigator.plugins hash exists, search this hash
		if (navigator.plugins) {
			numPlugins = navigator.plugins.length;
			if (numPlugins > 0) {
				// Search for the Flash mime type (application/x-shockwave-flash)
				//   in the navigator.mimeTypes hash
				if (navigator.mimeTypes && navigator.mimeTypes[mimeType]
										&& navigator.mimeTypes[mimeType].enabledPlugin
										&& (navigator.mimeTypes[mimeType].suffixes.indexOf(ext) != -1)) {
					// We've found the correct mime type
					// Search the navigator.plugins hash
					if ((navigator.appName == 'Netscape') && (navigator.appVersion.indexOf('4.0') != -1)) {
						// Netscape cannot search navigator.plugins by numeric index
						for (i in navigator.plugins) {
							if ((navigator.plugins[i].description.indexOf('Flash') != -1) || (i.indexOf('Flash') != -1)) { // some versions of quicktime have no description. feh!
								detected = 1;
								break;
							}
						}
					} else {
						// Search non-Netscape browsers for the plugin
						for (i = 0; i < numPlugins; i++) {
							pluginObject = navigator.plugins[i];
							if ((pluginObject.description.indexOf('Flash') != -1) || (pluginObject.name.indexOf('Flash') != -1)) {
								detected = 1;
								break;
							}
						}
					}
	
					// Double-check the mimeTypes hash (for Mac compatibility)
					if (navigator.mimeTypes[mimeType] == null) {
						detected = 0;
					}
				}
				return detected;	// Return
			} else if ((msie_windows == 1) && !undetectable) {
				// In IE for Windows, run the VBScript detection function
				return activeXDetect(activeXname);
			} else {
				// Otherwise, the plugin is not present
				return 0;
			}
		} else {
			// Otherwise, the plugin is not present
			return 0;
		}
	}
	
	// Run the detectFlash() function, and set the flashPresent
	// variable to 1 if the Flash plugin exists, 0 otherwise
	if (detectFlash() == 'true' || detectFlash() == 1) {
		flashPresent = 1;
	} else {
		flashPresent = 0;
	}
	// If the Flash plugin is present, display the Flash piece
	if (flashPresent) {
		//embedFlash(swf_location,bg_color,width,height)
		embedFlash(swf_location,swf_bgcolor,swf_width,swf_height);
	// Otherwise, display the static image
	} else {
		document.write('<img src="'+ alt_image +'" border="0" width="'+ swf_width +'" height="'+ swf_height +'" >');
	
	}
}
