/**
 * Embed a Flash file into a page, detecting the correct version as necessary
 * and skipping the IE ActiveX click-to-activate enforcement.
 * Be sure to have a <noscript> section right underneath the JS embed statement
 * so that viewers know they need to enable JavaScript to view the movie.
 */
function FlashEmbedder(reqMajorVer, reqMinorVer, reqRevision) {
	this.reqMajorVer = reqMajorVer;
	this.reqMinorVer = reqMinorVer;
	this.reqRevision = reqRevision;
	
	this.flashOK     = DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision);
	
	/**
	 * For pages that are delivered as application/xhtml+xml, document.write()
	 * no longer works.  Content must be embedded via Node#innerHTML.  Provide
	 * the target node here.
	 */
  this.targetID    = null;

	var pluginsPage  = "http://www.adobe.com/go/getflashplayer";
	
	this.defaults    = [ "quality", "high",
                  		 "allowScriptAccess", "sameDomain",											 
                   		 "type",        "application/x-shockwave-flash",
		                   "codebase",    'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
		                   "pluginspage", pluginsPage ];
	
	this.alternateContent = "You'll need to upgrade your version of the Flash plugin to view this movie.  If you have an Internet connection, "
	                      + "<a href='" + pluginsPage + "'>click here to download the latest Flash plugin</a>.";
}

/**
 * Embeds a Flash movie onto a Web jage using JavaScript.
 * This method passed alongs its parameters in a similar
 * way as the Adobe Flash Detection Kit, but it also
 * allows for some sane defaults to be applied to the call,
 * so that things such as "codebase" and "type" need not be
 * included into every page.  These parameters are, of course,
 * overridable by your calls.
 */
FlashEmbedder.prototype.embedMovie = function() {
	var user_args = arguments;
	var args      = [];
	
	var alternateContent = this.alternateContent;
	
	for (var i = 0; i < this.defaults.length; i++) {
		args.push(this.defaults[i]);
	}

  for (var i = 0; i < user_args.length; i = i + 2) {
    var currArg   = user_args[i];
		var currValue = user_args[i + 1];
		switch (currArg) {
			case "src":
			  pos = currValue.indexOf(".swf");
      	if (pos > -1) {
					currValue = currValue.substr(0, pos);
				}
			  break;
			case "alternateContent":
			  alternateContent = currValue;
		    currValue = null;		
				break;
		}

    if (currValue) {
      args.push(currArg);
	  	args.push(currValue);
		}
	}

  if (this.flashOK) {
		ret = AC_GetArgs(args, ".swf", "movie", 
										 "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", 
										 "application/x-shockwave-flash");  
    if (this.targetID) {
			document.getElementById(this.targetID).innerHTML = AC_Generateobj_string(ret.objAttrs, ret.params, ret.embedAttrs);
		} else {
      AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
		}
	} else {  // flash is too old or we can't detect the plugin
	  if (this.targetID) {
			document.getElementById(this.targetID).innerHTML = alternateContent;
		} else {
  		document.write(alternateContent);  // insert non-flash content
		}
	}		
	
	return this.flashOK;
}


/**
 * A version of the FDK function that returns a string instead of
 * directly writing to the document.
 */
function AC_Generateobj_string(objAttrs, params, embedAttrs) 
{ 
    var str = '';
    if (isIE && isWin && !isOpera)
    {
  		str += '<object ';
  		for (var i in objAttrs)
  			str += i + '="' + objAttrs[i] + '" ';
  		for (var i in params)
  			str += '><param name="' + i + '" value="' + params[i] + '" /> ';
  		str += '></object>';
    } else {
  		str += '<embed ';
  		for (var i in embedAttrs)
  			str += i + '="' + embedAttrs[i] + '" ';
  		str += '> </embed>';
    }

    return str;
}



var flash_embedder = new FlashEmbedder(requiredMajorVersion, requiredMinorVersion, requiredRevision);