// Copyright 2006 Google Inc.
// All rights reserved.

/**
 * A javascript function to load a Flash control, avoiding IE ActiveX updates.
 * @param divId {string} a div whose contents will be replaced with the control
 * @param flashUrl {string} URL to the flash object
 * @param width {number} width of the control
 * @param height {number} height of the control
 * @param opt_clickTagUrl {string} the unencoded destination (clickTAG) URL.
 * @param opt_flashVars {string} the flashvars to pass to the movie.
 * @param opt_allowScriptAccess {string} allowScriptAccess value
 */
function FOD_createControl(divId, flashUrl, width, height, opt_clickTagUrl, opt_flashVars,
    opt_allowScriptAccess) {
  var d = document.getElementById(divId);
  if (opt_clickTagUrl) {
    flashUrl = cdUtils.updateUrlWithParam(flashUrl, "clickTAG",
        cdUtils.makeUrlAbsolute(opt_clickTagUrl));
  }
  /*
   * If FlashVars are specified, we must pass it into the embed twice with different formats.
   * Store both embed strings in seperate variables
   */
  var flashVarsObject = '';
  var flashVarsEmbed = '';
  if (opt_flashVars) {
      flashVarsObject = '<param name="FlashVars" value="' + opt_flashVars + '"/>';
      flashVarsEmbed = ' FlashVars="' + opt_flashVars + '"';
  }
  var objectId = '';
  var scriptAccessObject = '';
  var scriptAccessEmbed = '';
  if (opt_allowScriptAccess) {
    objectId = (' id="fo' + Math.random() + '"').replace('.', '');
    scriptAccessObject = '<param name="AllowScriptAccess" value="' + opt_allowScriptAccess + '"/>';
    scriptAccessEmbed = ' AllowScriptAccess="' + opt_allowScriptAccess + '"';
  }
  d.innerHTML =
  '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
      + ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"'
      + ' width=' + width
      + ' height=' + height + objectId + '>'
      + scriptAccessObject
      + '<param name="movie" value="' + flashUrl + '"/>'
      + '<param name="quality" value="high"/>'
      + flashVarsObject
      + '<embed src=' + flashUrl
      + ' width=' + width
      + ' height=' + height
      + scriptAccessEmbed
      + flashVarsEmbed
      + ' type="application/x-shockwave-flash"'
      + ' pluginspage="http://www.macromedia.com/go/getflashplayer">'
      + '</embed>'
      + '</object>';
}
