// Flash Loader
// Used to prevent highlight in Internet Explorer

function writeFlash(swffile, swfw, swfh, container, loadMethod) {

  var htmlMake;
  var thisBrowser = navigator.userAgent;
  var flashDelay  = (thisBrowser.indexOf("Safari") != -1) ? 200 : 0;

  // Safari needs a delay when using innerHTML modifications or
  // the flash wont show up until an event such as onmouseover
  // occurs on the page. This is silly.

  switch(loadMethod) {
  default:
  // The default method is by changing innerHTML on a DIV container
    htmlMake = '<object width="' + swfw + '" height="' + swfh + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">' + "\n"
  	         + '<param name="movie" value="' + swffile + '" />' + "\n"
  	         + '<param name="wmode" value="transparent" />' + "\n"
  	         + '<embed src="' + swffile + '" width="' + swfw + '" height="' + swfh + '" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' + "\n"
             + '</object>' + "\n";

    // Load the innerHTML with or without timeout depending on flashDelay
    setTimeout( function() { document.getElementById(container).innerHTML = htmlMake; }, flashDelay);
  break;
  case "docwrite":
  document.write('<object width="' + swfw + '" height="' + swfh + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">' + "\n"
	         + '<param name="movie" value="' + swffile + '" />' + "\n"
	         + '<param name="wmode" value="transparent" />' + "\n"
	         + '<embed src="' + swffile + '" width="' + swfw + '" height="' + swfh + '" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' + "\n"
           + '</object>' + "\n");
  break;
  } // ! switch (loadMethod)

} // ! writeFlash





var embedBase     = 'http://www.judgejoebrown.com/';
var embedCount    = 0;

/** Function: flashInsert()
 *
**/
function flashInsert(swfContainer, swfFile, swfW, swfH, swfData) {

  embedCount++;
  var embedID         = 'flash-embed-' + embedCount;

  // Check if the container exists
  var embedContainer  = document.getElementById(swfContainer);

  if( embedContainer ) {

    if( userBrowser != 'IE' ) {

      embedContainer.innerHTML  = ''; // clear the old stuff

      // Generate a new object for the flash movie
      var newObject           = document.createElement('object');
          newObject.id        = embedID;

          // Set the object attributes
          newObject.setAttribute('base',      embedBase);
          // newObject.setAttribute('classid',   'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000');
          // newObject.setAttribute('codebase',  'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0');
          newObject.setAttribute('width',     swfW);
          newObject.setAttribute('height',    swfH);

      // Add the parameters underneath the object
      var paramList           = new Array();
          paramList['movie']  = swfFile;
          paramList['wmode']  = 'transparent';

          for(var paramName in paramList) {
          var newParameter    = document.createElement('param');
              newParameter.setAttribute(paramName, paramList[paramName]);
              newObject.appendChild(newParameter);
          } // ! cycle parameters

      if( swfData != undefined ) {
        paramList['flashvars'] = swfData;
      }

      // Add the embed tag underneath the object
      var newEmbed            = document.createElement('embed');

          // Set the embed attributes
          newEmbed.setAttribute('base',         embedBase);
          newEmbed.setAttribute('type',         'application/x-shockwave-flash');
          newEmbed.setAttribute('src',          swfFile);
          newEmbed.setAttribute('width',        swfW);
          newEmbed.setAttribute('height',       swfH);
          newEmbed.setAttribute('wmode',        'transparent');
          newEmbed.setAttribute('flashvars',    swfData);
          newEmbed.setAttribute('pluginspage',  'http://www.macromedia.com/go/getflashplayer');

          newObject.appendChild(newEmbed);

      // Insert the new object into the page
      embedContainer.appendChild(newObject);

      return true;

    } else {
    // If the user is using Internet Explorer, use a different embed method

      var flashHTML     = '<object'
                        + ' width="' + swfW + '"'
                        + ' height="' + swfH + '"'
                        + ' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">' + "\n"
                          // Set some parameters
  	                    + '<param name="movie" value="' + swfFile + '" />' + "\n"
                        + '<param name="wmode" value="transparent" />' + "\n"
                        + '<param name="flashvars" value="' + swfData + '" />' + "\n"
                          // Attempt alternate embed to fix a bug?
            //            + '<embed src="' + swfFile + '" width="' + swfW + '" height="' + swfH + '" wmode="transparent" flashvars="' + swfData + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' + "\n"
                        + '</object>' + "\n";

      embedContainer.innerHTML  = flashHTML;

      return true;

    } // ! browser?

  } // ! valid container?

  return false;

} // ! flashInsert()

