/*
Filename:  gen_mm_object.js
Desc:      Generate object and param tags for multimedia content based on browser type
Copyright: Relevant Arts Enterprise, Inc. <http://www.relevantarts.com/>
Author:    John A. Lock <jlock@relevantarts.com>
Created:   2008-Oct-07 v1.0
Modified:  

Minimum calling requirements:

  <div id="xxxxxx">
  <script language="javascript" type="text/javascript">
  <!-- Generate the multimedia object code
  var yyyyyy = new Object;                                        <!-- Create the code object
  yyyyyy.classid = "clsid:111111111-2222-3333-4444-55555555555";  <!-- Class ID for MS ActiveX control -->
  yyyyyy.width   = "300";                                         <!-- Pixel width for element -->
  yyyyyy.height  = "45";                                          <!-- Pixel height for element -->
  yyyyyy.bgcolor = "#ffffff";                                     <!-- Background color, if desirable -->
  yyyyyy.src     = "audio/somesound.wav";                         <!-- URL or file name of media -->
  yyyyyy.type    = "audio/x-wav";                                 <!-- MIME type for media -->
  generate_object(yyyyyy, "xxxxxx");                              <!-- Install the generated code -->
  // -->
  </script>
  <noscript>
  <p style="color:#ff0000"><strong>Javascript must be enabled to view/play this page element</strong></p>
  </noscript>
  </div>
*/

function generate_object(ObjectID, ContainerID) {

  // Generate an object tag based on browser type, MSIE gets "classid", others get "type"
  var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
  var ObjectTag = "";
  if (isIE) {
    ObjectTag = "\n<object classid=\"" + ObjectID['classid'];
  }
  else {
    ObjectTag = "\n<object type=\"" + ObjectID['type'];
  }

  // Add width, height, and media source
  ObjectTag += '" width="' + ObjectID['width'] +
               '" height="' + ObjectID['height'] +
               '" data="' + ObjectID['src'] + "\">\n";

  // Generate all the param statements specified and a few others to cover different semantics and plugins
	var ParamCode = "";
	for (Property in ObjectID) {
    // Skip these, we got them in the object tag
    if (Property == "classid" ||
        Property == "width" ||
        Property == "height" ||
        Property == "type") {
        continue;
    }

    // Basic parameter code
		ParamCode += '<param name="' + Property + '" value="' + ObjectID[Property] + "\" />\n";

    // Generate extra params for "movie" and "url" using "src" value
    if (Property == "src") {
      ParamCode += '<param name="url" value="' + ObjectID[Property] + "\" />\n";
      ParamCode += '<param name="movie" value="' + ObjectID[Property] + "\" />\n";
    }

    // Generate an extra param for "autostart" using "autoplay" value
    if (Property == "autoplay") {
      ParamCode += '<param name="autostart" value="' + ObjectID[Property] + "\" />\n";
    }

    // Generate an extra param for "playcount=999" if "loop" is set to true
    if (Property == "loop" && ObjectID[Property] == "true") {
      ParamCode += '<param name="playcount" value="999"' + " />\n";
    }
  }

  // Replace the div's HTML code with what we generated.
	document.getElementById(ContainerID).innerHTML = ObjectTag + ParamCode + "\n</object>\n";
}

