/*
 * Flash Embed Framework
 *
 * Ammon Haggerty (ammon@odopod.com, http://www.odopod.com/)
 * 04-20-2006
 *
 * Embeds Flash movie.
 *
 * If Flash == required version (defined in globals.js) - embeds swf
 * If Flash < required version && >= ver 6,0,65 - supports auto install, embeds updateSwf
 * If updateSwf is not defined - displays textcontent div with html upgrade message
 * If Flash version < ver 6,0,65 or no Flash found - displays textcontent div with html upgrade message
 *
 * Usage:
 *
 *	<script type="text/javascript">
 *		var fpo = new Object;
 *		fpo.url = 		"pathToSwf.swf";
 *		fpo.id = 		"swfIdName";
 *		fpo.updateSwf = "pathToAltLoading.swf";
 *		fpo.width = 	"977";
 *		fpo.height = 	"100%";
 *		fpo.align =		"top";
 *		fpo.scale =		"noscale";
 *		fpo.bgColor = 	"#E7E7DD";
 *		fpo.quality =	"best"
 *		fpo.play = 		"true";
 *		fpo.loop = 		"false";
 *		fpo.allowScr = 	"sameDomain";
 *		fpo.classID = 	"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
 *		fpo.codeBase = 	"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab";
 *		embedSwf(fpo);
 *	</script>
 *
 */

function embedSwf(fpo) {

	// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
	var hasProductInstall = DetectFlashVer(6, 0, 65);

	// Version check based upon the values entered above in globals.js
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

	// Location visited after installation is complete if installation is required
	var MMredirectURL = window.location;

	// Stored value of document title used by the installation process to close the window that started the installation process
	var MMdoctitle = document.title;

	// define write boolean
	var writeEmbed = true;

	// determine if an update fla has been defined
	var updateSwfDefined = true;
	if ( fpo.updateSwf == undefined || fpo.updateSwf == '' ) {
		updateSwfDefined = false;
	}

	// if Flash is too old or not detected, display textcontent div
	if ( !hasProductInstall && !hasReqestedVersion && ignoreVal != 'true' ) {
		displayTextContent()
		writeEmbed = false;
	}

	// if has install req, but no flash alternative defined, display text conent
	if ( hasProductInstall && !hasReqestedVersion && ignoreVal != 'true' && !updateSwfDefined ) {
		displayTextContent()
		writeEmbed = false;
	}

	// pull arguments from the URL and send them to the swf...
	var urlArgs = "";
	var is_input = document.URL.indexOf('?');
	if (is_input != -1) {
		urlArgs = document.URL.substring(is_input+1, document.URL.length);
	}

	// Check to see if a player with Flash Product Install is available and the version does not meet the requirements for playback
	if ( hasProductInstall && !hasReqestedVersion && ignoreVal != 'true' ) {
		var newURL = fpo.updateSwf+'?MMredirectURL='+MMredirectURL+'&MMplayerType=ActiveX&MMdoctitle='+MMdoctitle;
	} else if (hasReqestedVersion || ignoreVal == 'true') {
		var newURL = fpo.url;
	}

	if ( writeEmbed ) {
		// created inside a frame for browser scrolling
		var oeTags = '<table width="'+fpo.width+'" height="'+fpo.height+'" border="0" cellspacing="0" cellpadding="0" id="flashContent"><tr><td>'
		+ '<object classid="'+fpo.classID+'" width="'+fpo.width+'" height="'+fpo.height+'" codebase="'+fpo.codeBase+'" id="'+fpo.id+'">'
		+ '<param name="movie" value="'+newURL+'" /><param name="quality" value="'+fpo.quality+'"/><param name="bgcolor" value="'+fpo.bgColor+'" />'
		+ '<param name="allowScriptAccess" value="'+fpo.allowScr+'" />'
		+ '<param name="FlashVars" value="'+urlArgs+'" />'
		+ '<embed src="'+newURL+'" FlashVars="'+urlArgs+'" quality="'+fpo.quality+'" bgcolor="'+fpo.bgColor+'"'
		+ 'width="'+fpo.width+'" height="'+fpo.height+'" name="'+fpo.id+'" aligh="'+fpo.align+'"'
		+ 'play="'+fpo.play+'" loop="'+fpo.loop+'" quality="'+fpo.quality+'" allowScriptAccess="'+fpo.allowScr+'"'
		+ 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">'
		+ '<\/embed>'
		+ '<\/object>'
		+ '</td></tr></table>';

		// write embed
		document.write(oeTags);
	}
}

function getElement(id) {
	var el = document.getElementById(id);
	return el;
}

function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

// Hides Flash div and exposes html div
function displayTextContent() {
	var flashEl = getElement("flashcontent");
	var textEl = getElement("textcontent");
	flashEl.style.display = "none";
	textEl.style.display = "block";
}
