/*	
	Copyright Jeremy Mallin LLC. All rights reserved.
	Exlusive, non-transferrable use provided to website owner as is, without warranty.
	Author is not responsible for changes made by website owner or third party.
	
	Tested To Work With:
	Microsoft Internet Explorer	6 and Newer
	Mozilla Firefox 			3 and Newer
	Google Chrome				1 and Newer
	Apple Safari 				3 and Newer
	Opera 						9 and Newer
	Netscape Navigator 			9 and Newer

	Function to embed Flash with standards compliant code.
	This preactivates the Flash movie for use in Internet Explorer and other browsers.
	
	Arguments take the form of 'name=value' where the name|value pairs are defined by the Adobe Flash plugin as defined at
	http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_12701
	
	EXAMPLE VALUES:

	data	= 'mymovie.swf'
	height	= '100'
	loop	= 'false'
	parent	= 'elementID';
	play	= 'true'
	quality	= 'best'
	width	= '100%'
	
	EXAMPLE CALL:	
	embedFlash('data=mymovie.swf','height=100','loop=false','parent=elementID','play=true','quality=best','width=100%');
	
*/
// Function to embed Flash object
function embedFlash(){
	
	// Define required Flash plugin version
	MajorVersion							= 9;
	MinorVersion							= 0;
	MajorRevision							= 47;
	
	// Read In Parameters
	if (arguments.length>0){
		args 								= new Array();
		param 								= new Array();
		for (fa=0; fa<arguments.length; fa++){
			args[args.length] 				= arguments[fa].split('=');
			param[args[args.length-1][0]]	= args[args.length-1][1];
			if (args[args.length-1][0]=='flashvars'){
				param.flashvars 			= param.flashvars.replace(/\:/g,'=');
				param.flashvars 			= param.flashvars.replace(/\;/g,'&');
			}
		}
	} else {
		return false;
	}
	
	// Set Flash content for when required Flash plugin is not installed.
	if (!DetectFlashVer(MajorVersion, MinorVersion, MajorRevision)){
		MMPlayerType						= (navigator.userAgent.indexOf("MSIE") > 0) ? "ActiveX" : "PlugIn";
		param.data							= "Media/SWF/playerProductInstall.swf";
		param.allowscriptaccess				= "always";
		param.flashvars						= "MMredirectURL=" + window.location;
		param.flashvars						+= "&MMplayerType=" + MMPlayerType;
		param.flashvars						+= "&MMdoctitle=" + document.title.slice(0, 47) + " - Flash Player Installation";
	}
	
	// Get Parent Element Which Will Contain Flash
	if (document.getElementById){
		parentObj							= document.getElementById(param.parent);
	} else {
		return false;
	}
	
	// Create Flash OBJECT Element
	flashObj								= document.createElement("object");
	
	// Embed Flash OBJECT Element Within Parent Element
	parentObj.appendChild(flashObj);

	// Create PARAM Element
	paramObj								= document.createElement("param");
	
	// Set Attributes of PARAM Element To Specify Flash Content
	paramObj.setAttribute("name","movie");
	paramObj.setAttribute("value",param.data);
	
	// Embed PARAM Element Within Flash OBJECT Element
	flashObj.appendChild(paramObj);

	// Set Other Miscellaneous Flash OBJECT Element Attributes
	for (fa in param){
		if (fa!='parent'){
			
			// Set OBJECT Attribute For Browsers That Use OBJECT Attributes
			flashObj.setAttribute(fa,param[fa]);
			
			// Set PARAM Element For Browsers That Require PARAM Elements
			paramObj						= document.createElement("param");
			paramObj.setAttribute("name",fa);
			paramObj.setAttribute("value",param[fa]);
			flashObj.appendChild(paramObj);
		}
	}

	// Define Flash OBJECT Element MIME Type
	flashObj.setAttribute("type","application/x-shockwave-flash");

}
