// -------------------------------------------------------------------------------------------
// A number of functions that control settings of the Flash Player:
// TO DO:
//		- Alter code to accomodate multi-browser compatibility.
//		- Add more functions to alter player properties, if needed.
//		- Possibly add fscommand functionality via gloabl function.
//
// -------------------------------------------------------------------------------------------

// Writes the Object/Embed tags dynamically in order to support IE's handling of ActiveX/Embed obejcts:
function writeFlashObject(objectName, filePath, width, height, bgColor, flashVars) {
	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" name=\"" + objectName + "\" width=\"" + width + "\" height=\"" + height + "\" align=\"\" id=\"" + objectName + "\">");
	document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\" />");
	document.write("<param name=\"movie\" value=\"" + filePath + "\" />");
	document.write("<param name=\"quality\" value=\"high\" />");
	document.write("<param name=\"scale\" value=\"noscale\" />");
	document.write("<param name=\"salign\" value=\"lt\" />");
	document.write("<param name=\"bgcolor\" value=\"" + bgColor + "\" />");
	document.write("<param name=\"FlashVars\" value=\"" + flashVars + "\" />");
	document.write("<embed src=\"" + filePath + "\" FlashVars=\"" + flashVars + "\" swLiveConnect=true width=\"" + width + "\" height=\"" + height + "\" align=\"\" id=\"" + objectName + "\" name=\"" + objectName + "\" quality=\"high\" scale=\"noscale\" salign=\"lt\" bgcolor=\"" + bgColor + "\" allowscriptaccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>");
	document.write("</object>");
}

// Declare variables to store the x and y dimensions when xWidth and yHeight are specified:
var currentWidth;
var currentHeight;

// Sets the Flash player object size within the page:
function setPlayerSize(flashObject, divObject, xWidth, yHeight) {
	// Set currentWidth and currentHeight to passed values for use on resize:
	currentWidth = xWidth;
	currentHeight = yHeight;
	
	var iw, ih; // Set inner width and height of page:
	if (self.innerHeight){
		iw = self.innerWidth;
		ih = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		iw = document.documentElement.clientWidth;
		ih = document.documentElement.clientHeight;
	} else if (window.innerWidth == null) {
		iw = document.body.clientWidth;
		ih = document.body.clientHeight; 
	} else {
		iw = window.innerWidth;
		ih = window.innerHeight;
	}
	
	// Code to execute if the browser does NOT USE the embedded Flash Player:
	if(document.embeds > -1) {
		// Set Flash Player's width parameter:
		if(iw <= xWidth) {
			document.embeds[flashObject].width = xWidth;
			document.getElementById(divObject).style.width = xWidth + "px";
			
		} else {
			document.embeds[flashObject].width = "100%";
			document.getElementById(divObject).style.width = "100%";
		}
		
		// Set Flash Player's height parameter:
		if(ih <= yHeight) {
			document.embeds[flashObject].height = yHeight;
			document.getElementById(divObject).style.height = yHeight + "px";
		} else {
			document.embeds[flashObject].height = "100%";
			document.getElementById(divObject).style.height = "100%";
		}
	// Code to execute if the browser USES the embedded Flash Player:
	} else {
		// Set Flash Player's width parameter:
		if(iw <= xWidth) {
			document[flashObject].width = xWidth;
			document.getElementById(divObject).style.width = xWidth + "px";
		} else {
			document[flashObject].width = "100%";
			document.getElementById(divObject).style.width = "100%";
		}
		
		// Set Flash Player's height parameter:
		if(ih <= yHeight) {
			document[flashObject].height = yHeight;
			document.getElementById(divObject).style.height = yHeight + "px";
		} else {
			document[flashObject].height = "100%";
			document.getElementById(divObject).style.height = "100%";
		}
	}
}

function setPlayerSizeStatic(flashObject, divObject, xWidth, yHeight) {
	// Code to execute if the browser does NOT USE the embedded Flash Player:
	if(document.embeds > -1) {
		// Set Flash Player's width parameter:
		document.embeds[flashObject].width = xWidth;
		document.getElementById(divObject).style.width = xWidth + "px";
		
		// Set Flash Player's height parameter:
		document.embeds[flashObject].height = yHeight;
		document.getElementById(divObject).style.height = yHeight + "px";
	// Code to execute if the browser USES the embedded Flash Player:
	} else {
		// Set Flash Player's width parameter:
		document[flashObject].width = xWidth;
		document.getElementById(divObject).style.width = xWidth + "px";
		
		// Set Flash Player's height parameter:
		document[flashObject].height = yHeight;
		document.getElementById(divObject).style.height = yHeight + "px";
	}
}

function setPlayerSizeResize(flashObject, divObject) {
	setPlayerSize(flashObject, divObject, currentWidth, currentHeight);
}