/* Detect if the correct version of Flash is available on the client */
/* and center the Flash presentation vertically in a browser window */
/* (c) 2005 Antics Online, Inc. All Rights Reserved. */
/* Revised 9/13/05 */
/* Revised 5/8/06 -- Contains workaround for cropping problem in IE with Flash 7 */
/* Revised 12/15/06 -- Reference generic styles */
// 1/24/07 Added support for FlashVars
/* Revised 8/2/07 -- Option to display alternate content instead of redirect if no flash */
/* Revised 9/24/07 -- Removed NN4 support; Removed outer and innner divs when not centering */
/* Revised 11/21/08 -- Suppoert for Flash versions >= 10 */


// Set default values in case they're not passed in
var flashCenter = false;	// Set true to center vertically; false if running in a fixed position on the page
var flashBorder = false;	// Set true to add a border (applies only if centering); false to disable border
var flashFullscreen = false;	// Set true to resize window to fullscreen
var flashBgColor = "#FFFFFF"; // Sets the background color
var flashTextColor = "#000000"; // The text color for the window if flashCenter is true
var flashNoFlashPage = "";  // Send user here if no Flash; If blank string, then display noFlash content instead.
var flashTransparency = false;  // Set true if Flash is to be transparent (can be something other than top-most layer)
var flashVars = "";	 // 1/24/07 Added support for FlashVars
var flashScale = "";	 // 9/24/07 added support for scale;  Options are: noscale, exactfit, noborder, showall; default null or showall

// Init global vars
var flashInstalled = false;		// Boolean. true if flash Version is installed
var flashPageHeight = 0; // The height of the browser window

// Browser sniff stuff
var ns4 = document.layers;
var ie4 = document.all;
var nn6 = document.getElementById && !document.all;
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;		// true if we're on ie
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; // true if we're on windows

// Add a function as the body onload event handler
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
  			oldonload();
			func();
		}
	}
}

//  Called in body onload. This will center and make visible whatever we're displaying, either the Flash or the alternate no-Flash content.
function centerFlash() {
	var inner, outer, middle, loading;
	
	 if( nn6 ) { // Netscape 6, 7, Mozilla
			outer = document.getElementById("flashOuterDiv");
			inner = document.getElementById("flashInnerDiv");
			middle = document.getElementById("flashMiddleDiv");
			loading = document.getElementById("flashLoadingDiv");
	}
	else { // IE
		outer = document.all["flashOuterDiv"];
		inner = document.all["flashInnerDiv"];
		middle = document.all["flashMiddleDiv"];
		loading = document.all["flashLoadingDiv"];
	}
	
	loading.style.visibility = "hidden";
	
	if( flashCenter ) { // Don't center if playing in a fixed position	
		var y = 200; // Default position
		if( flashPageHeight ) { // If we were able to determine window dimensions
			y = (flashPageHeight/2) - (flashHeight/2); // Center the preso vertically
			if( y < 0 ) y = 0;
		}
		middle.style.visibility = "visible"; // 5/8/06 -- IE/Flash 7 cropping bug workaround: make visible here just before repositioning 
		outer.style.height = "100%"; // Set the background layer to fill the page
		middle.style.top = y + "px"; // Position the Flash layer in the center
		if( flashBorder ) inner.style.width = flashWidth; // Set the border layer to the width of the Flash animation
		if( isIE && !isWin ) window.resizeBy(0,-1); // Bug fix for IE Macintosh -- resize forces Flash to reposition
		outer.style.visibility = "visible";
	}
}

// Flash detection routine
function detectFlash() {	
	// Write vbscript detection if we're not on Mac. Check the browser...we're looking for ie/win
	if(isIE && isWin){ // don't write vbscript tags on anything but ie win
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('flashInstalled = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+flashVersion+'"))) \n');	
		document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
	}
	else {
		var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0);
		if( plugin ) {
			var installedVers = parseInt(plugin.description.substring(plugin.description.indexOf(".")-2)); // 11.21.08 Look for 2 digits in version to suppoert versions >= 10
			if( installedVers >= flashVersion ) flashInstalled = true;   // The required version of Flash is available 
		}
	}
}

// Write the content we're going to display. Set the styles based on the params set in the HTML file.
function displayFlash() {
	var innerStyle = ""; // Used to draw a border around the Flash
	var middleStyle = ""; // Used to center the Flash vertically on the screen
	var outerStyle = "";  // Used to fill the screen with a background color
	var colorStyle = ""; // Used to set the backgound color
	var trans = "'opaque";
	if( flashTransparency ) trans = "transparent";
			
	document.open();
	
	if( flashCenter ) { // Set the styles only if we need to center the Flash
		document.writeln('<center>');	
		outerStyle = middleStyle = "flashContent";
		if( flashBorder ) innerStyle = "flashBorder";
		colorStyle = 'style="background-color:' + flashBgColor +'; color:' + flashTextColor +';"';
		document.writeln('<div id="flashOuterDiv" class="' + outerStyle + '" ' + colorStyle + '><div id="flashMiddleDiv" class="' + middleStyle + '" ' + colorStyle + '><div id="flashInnerDiv" class="' + innerStyle + '">');
	}
	
	if( flashInstalled ) { // If the right version of Flash is installed
	
			document.writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + flashWidth + '" height="' + flashHeight + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + flashVersion + ',0,0,0">'  // 11.21.08 Add version number
			+ '<param name="MOVIE" value="' + flashSrc + '">'
			+ '<param name="LOOP" value="false"><param name="QUALITY" value="high"><param name="wmode" value="' + trans + '" />'
			+ '<param name="MENU" value="false">'
			+ '<param name="FlashVars" value="' + flashVars + '">' // 1/24/07 Added support for FlashVars
			+ '<param name="scale" value="' + flashScale + '">' // 9/24/07 Added support for Scale
			+ '<embed src="' + flashSrc + '" width="' + flashWidth + '" height="' + flashHeight + '" loop="false" quality="high" menu="false" wmode="' + trans + '" scale="' + flashScale + '"  pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" FlashVars="' + flashVars + '">'
			+ '</embed></object>');
	}
	else { // Else the right version of Flash is not installed
		if( flashNoFlashPage.length > 0 ) document.location = flashNoFlashPage; // If we're supposed to redirect to a different page
		else document.write(document.getElementById('flashNone').innerHTML);  // If we're supposed to display the no flash content instead
	}
	
	if( flashCenter ) { // Set the styles only if we need to center the Flash
		document.writeln('</div></div></div>');
		document.writeln('</center>');
	}
		
	document.close();
}

// Detect if Flash is present and then set up the Flash display environment
function initFlash() {
	var loading = null;
	if( ! ns4 ) {
		if( nn6 ) loading = document.getElementById("flashLoadingDiv");  // Netscape 6, 7, Mozilla
		else loading = document.all["flashLoadingDiv"]; // IE
	}
	if( loading != null ) loading.style.visibility = "visible";
	detectFlash(); // Call the Flash detection code
	addLoadEvent(centerFlash); // Add our centerFlash function as the body onload event handler
	if( flashFullscreen ) {
		self.moveTo(0,0);
		self.resizeTo(screen.width,screen.height);
	}
	flashPageHeight = getPageHeight();
	if( flashPageHeight == 0 || flashPageHeight == flashHeight ) {
		flashCenter = false;	// If running in a popup window, don't center
	}
}

// Return height of the broswer window or zero if unable
function getPageHeight() {
	var ns4 = document.layers; // Try again -- doesn't always work the first time
	if( !ns4 ) {
		var pageHeight = top.document.body.clientHeight; // If this doesn't work
		if( !pageHeight || isNaN(pageHeight) ) pageHeight = window.innerHeight; // Then try this
		if( isNaN(pageHeight) ) pageHeight = 0;
	}
	else {
		pageHeight = window.innerHeight;
	}
	return(pageHeight);
}