document.write('<script type="text/javascript" src="/_c4/_scripts/swfobject.js"></scr' + 'ipt>'); 


function writeFlash(randomID,internalValues,requiredValues,attributeValues,paramValues,flashVarsValues) {
	// initialize variables
	var flashparams = "";
	var embedparams = "";
	var flashvarsparams = "";
	
	// construct output
	flashwrite = ('<script type="text/javascript"> var flashvars = {}; var params = {}; var attributes = {}; ');
	for (var k in attributeValues) {
		flashwrite  += ('attributes.'+k+' = "'+attributeValues[k]+'"; ');	
	}
	for (var k in paramValues) {
		flashwrite  += ('params.'+k+' = "'+paramValues[k]+'"; ');	
	}
	for (var k in flashVarsValues) {
		flashwrite  += ('flashvars.'+k+' = "'+flashVarsValues[k]+'"; ');	
	}
	flashwrite += ('swfobject.embedSWF("'+requiredValues["src"]+'","'+randomID+'","'+requiredValues["width"]+'","'+requiredValues["height"]+'","'+requiredValues["version"]+'",'+internalValues["express"]+', flashvars, params, attributes); ')
	flashwrite += ('</scr' + 'ipt>')

	// write output to HTML
	return(flashwrite);
}

function createFlash() {
	// initialize variables
	onError=null
	var randomID = "flash"+Math.floor(Math.random()*100000000);
	var internalValues = new Array(); // options for the createFlash method
	var requiredValues = new Array(); // required by flash
	var attributeValues = new Array(); // attributes
	var paramValues = new Array(); // optional settings for the flash movie
	var flashVarsValues = new Array(); // additional variables passed into the flash movie 
	
	if (document.location.toString().indexOf( 'https://' ) > -1) {
		protocol = "https://";
	}
	else{
		protocol = "http://";
	}
	
	// set defaults for internal parameters
	internalValues["alt"] = '<div style="background-color: #FFFFFF; padding: 2px; font-family: Verdana; font-size: 11px; font-weight: bold; color: #000000; text-transform: normal; font-style: normal; line-height: 12px; text-align: center;">We\'ve detected that your system is not configured to display this Flash content.<br /><a href="http://www.adobe.com/go/getflashplayer"><img border="0" src="'+protocol+'www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>'
	internalValues["express"] = false;
	
	// set defaults for required parameters
	requiredValues["codebase"] =  protocol + "download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=";
	requiredValues["pluginspage"] = protocol + "www.macromedia.com/go/getflashplayer";
	requiredValues["classid"] = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
	requiredValues["version"] = "6,0,40,0"; // not a required param, but separated from codebase if change is needed
	requiredValues["width"] = 42;
	requiredValues["height"] = 42;
	paramValues["quality"] = "high";
	
	// set up lists of required parameters and optional parameters; others passed in will go into the flashvars array
	var internalList = new Array("alt","express");
	var requiredList = new Array("classid","codebase","width","height","src","pluginspage","version");
	var attributeList = new Array("id","name","class","align");
	var paramList = new Array("swliveconnect","play","loop","menu","quality","scale","salign","wmode","bgcolor","base","devicefont","allowscriptaccess","seamlesstabbing","allowfullscreen","allownetworking");

	// loop through each argument passed into function
	for(var i =0; i < arguments.length; i++ ) {
		var nameList = arguments[i].split("="); // split each argument into name/value pairs
		argName = (nameList.shift()); // assigns the name to the text before the first equal sign
		argValue = (nameList.join("=")); // assigns the value to the text after the first equal sign (accounts for multiple equal signs)
		
		// check to see if the argument name matches one of the internal parameters
		for(n=0;n<internalList.length;n++) {
			if (argName == internalList[n]) {
				internalValues[argName] = argValue; // assign a required parameter into an associative array
				argName = ""; // clear variable;
				break;
			}
		}
		
		// check to see if the argument name matches one of the required parameters
		for(j=0;j<requiredList.length;j++) {
			if (argName == requiredList[j]) {
				requiredValues[argName] = argValue; // assign a required parameter into an associative array
				argName = ""; // clear variable;
				break;
			}
		}
		
		// check to see if the argument name matches one of the attributes
		for(a=0;a<attributeList.length;a++) {
			if (argName == attributeList[a]) {
				attributeValues[argName] = argValue; // assign a required parameter into an associative array
				argName = ""; // clear variable;
				break;
			}
		}
		
		// check to see if the argument name matches one of the optional parameters
		for(k=0;k<paramList.length;k++) {	
			if (argName == paramList[k]) {
				paramValues[argName] = argValue; // assign an optional parameter into an associative array
				argName = ""; // clear variable;
				break;
			}
		}
		
		// if neither condition above applies, pass argument into the flashvars array
		if (argName != "") {
			flashVarsValues[argName] = argValue;
		}
	}
	
	// check to see if express install is desired
	if (internalValues["express"] == "true") {
		internalValues["express"] = '"/_c4/tools/flash_player/expressInstall.swf"';
	} else {
		internalValues["express"] = false;
	}
	
	// size alternate content div appropriately
	var divWidth = "";
	var divHeight = "";
	
	if (String(requiredValues["width"].indexOf("%")) >= 0) {
		divWidth = ' width: '+requiredValues["width"]+'; ';
	} else {
		divWidth = ' width: '+requiredValues["width"]+'px; ';
	}

	if (String(requiredValues["height"].indexOf("%")) >= 0) {
		divHeight = ' height: '+requiredValues["height"]+'; ';
	} else {
		divHeight = ' height: '+requiredValues["height"]+'px; ';
	}
	
	// construct holding div
	document.write('<div id="'+randomID+'" style="'+divWidth+divHeight+'">'+internalValues["alt"]+'</div>');

	// construct output
	document.write(writeFlash(randomID,internalValues,requiredValues,attributeValues,paramValues,flashVarsValues));
}