// --------------------------------------------------------------------------------
// 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.
// --------------------------------------------------------------------------------


// Responsible for setting variables within Flash movie to allow for user of browser controls,
// namely the use of the forward and back buttons in the browser.
/* - LOCATED ON PAGE CONTAINING FLASH --
function setPage(targetObject, issueID, sectionID, articleID) {
	// Check if Flash object exists:
	if (window.document[targetObject]) {
		// Set issueID variable in _root timeline of Flash movie:
		window.document[targetObject].SetVariable("issueID", issueID);
		
		// Set sectionID variable in _root timeline of Flash movie:
		window.document[targetObject].SetVariable("sectionID", sectionID);
		
		// Set articleID variable in _root timeline of Flash movie:
		window.document[targetObject].SetVariable("articleID", articleID);
	}
}
*/

// Writes the Object/Embed tags dynamically in order to support IE's handling of ActiveX/Embed obejcts:
function writeFlashObject(objectName, filePath, width, height, bgColor, align, salign, wmode, 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=\"" + 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=\"" + salign + "\" />");
	document.write("<param name=\"bgcolor\" value=\"" + bgColor + "\" />");
	document.write("<param name=\"wmode\" value=\"" + wmode + "\" />");
	document.write("<param name=\"FlashVars\" value=\"" + flashVars + "\" />");
	document.write("<embed src=\"" + filePath + "\" FlashVars=\"" + flashVars + "\" width=\"" + width + "\" height=\"" + height + "\" align=\"" + align + "\" id=\"" + objectName + "\" name=\"" + objectName + "\" quality=\"high\" scale=\"noscale\" salign=\"" + salign + "\" wmode=\"" + wmode + "\" 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;

// Set the size of the Flash movie based on the width/height of the browser window and the values
// passed into the script:
function setPlayerSizeTest(targetObject, xWidth, yHeight) {
	// Determine the browser windows width and height:
	var iw, ih; // Set inner width and height
	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;
	}
	
	// Resize the Flash Player:
	if(document.all && !document.getElementById) {
		if(iw <= xWidth) {
			document.all[targetObject].style.pixelWidth = xWidth;
		} else {
			document.all[targetObject].style.pixelWidth = "100%";
		}
		if(ih <= yHeight) {
			document.all[targetObject].style.pixelHeight = yHeight;
		} else {
			document.all[targetObject].style.pixelHeight = "100%";
		}
	}else{
		if(iw <= xWidth) {
			document.getElementById(targetObject).style.width = xWidth;
		} else {
			document.getElementById(targetObject).style.width = xWidth;
		}
		if(ih <= yHeight) {
			document.getElementById(targetObject).style.height = yHeight;
		} else {
			document.getElementById(targetObject).style.height = "100%";
		}
	}
}

function setPlayerSizeStatic( targetObject, xWidth, yHeight, divObject, divWidth, divHeight ) {
	// alert( targetObject + ' set to width: ' + xWidth + ' height: ' + yHeight );
	
	document.getElementById(divObject).style.width = divWidth;
	document.getElementById(divObject).style.height = divHeight;
	
	// 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[targetObject].width = xWidth;
		
		// Set Flash Player's height parameter:
		document.embeds[targetObject].height = yHeight;
	
	// Code to execute if the browser USES the embedded Flash Player:
	} else {
		// Set Flash Player's width parameter:
		document[targetObject].width = xWidth;
		
		// Set Flash Player's height parameter:
		document[targetObject].height = yHeight;
	}
}

function setPlayerSize(targetObject, xWidth, yHeight) {
	// Set currentWidth and currentHeight to passed values for use on resize:
	currentWidth = xWidth;
	currentHeight = yHeight;
	
	// Declare variables used to store inner width and height:
	var iw, ih; // Set inner width and height
	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[targetObject].width = xWidth;
		} else {
			document.embeds[targetObject].width = "100%";
		}
		// Set Flash Player's height parameter:
		if(ih <= yHeight) {
			document.embeds[targetObject].height = yHeight;
		} else {
			document.embeds[targetObject].height = "100%";
		}
	// Code to execute if the browser USES the embedded Flash Player:
	} else {
		// Set Flash Player's width parameter:
		if(iw <= xWidth) {
			document[targetObject].width = xWidth;
		} else {
			document[targetObject].width = "100%";
		}
		// Set Flash Player's height parameter:
		if(ih <= yHeight) {
			document[targetObject].height = yHeight;
		} else {
			document[targetObject].height = "100%";
		}
	}
}

// Sets the Flash player object size within the page:
function setPlayerSizeDiv(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 setPlayerSizeResize(targetObject) {
	setPlayerSize(targetObject,currentWidth,currentHeight);
}