Index: swfobject2/swfobject2.js
===================================================================
RCS file: swfobject2/swfobject2.js
diff -N swfobject2/swfobject2.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ swfobject2/swfobject2.js	20 Mar 2009 15:38:33 -0000
@@ -0,0 +1,22 @@
+// $Id$
+
+/**
+ * @FILE
+ * This does the actual flash replacement when the page is loaded
+ */
+
+
+/**
+ * This function looks for swfobject class items and loads them
+ * as swfobjects. This is different than the D6 version because we don't have
+ * the same JS functions
+ */
+$(document).ready( function () {
+  // get each swf div that needs to be processed
+  $('.swfobject2:not(.swfobject2Init-processed)').each(function () {
+    var config = Drupal.settings.swfobject2['items'][$(this).attr('id')];
+    swfobject.embedSWF(config.url, $(this).attr('id'), config.width, config.height, config.version, config.express_redirect, config.flashvars, config.params, config.attributes);
+    // set this item to processed
+    $(this).addClass('swfobject2Init-processed');
+  });
+});
\ No newline at end of file
Index: swfobject2/swfobject2.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/swftools/swfobject2/swfobject2.module,v
retrieving revision 1.1.4.5
diff -u -p -r1.1.4.5 swfobject2.module
--- swfobject2/swfobject2.module	8 Sep 2008 16:27:38 -0000	1.1.4.5
+++ swfobject2/swfobject2.module	20 Mar 2009 15:38:34 -0000
@@ -23,6 +23,29 @@ function swfobject2_swftools_methods() {
   return $methods;
 }
 
+
+/**
+ * Ensure that the necessary JS files and settings are loaded.
+ *
+ * This function automatically checks to make sure that the JS files are only
+ * loaded once.
+ * @param array $settings
+ */
+function swfobject2_ensure_swfobject($settings = array()) {
+  static $done = FALSE;
+  if (! $done) {
+    // add the swftools code
+    drupal_add_js(swftools_get_player_path() .'/swfobject2/swfobject.js');
+    // Load the JS which creates loads the params into the page
+    drupal_add_js(drupal_get_path('module', 'swfobject2') .'/swfobject2.js', 'module', 'footer');
+    $done = TRUE;
+  }
+  // add the settings for this object to the page. We do not cache this so that
+  // anon users will always get the JS
+  drupal_add_js($settings, 'setting', 'footer', FALSE, TRUE, FALSE);
+}
+
+
 /**
  * Implementation of swftools_embed hook
  * Returns the markup for the page, plus set necessary javascript.
@@ -31,35 +54,45 @@ function swfobject2_swftools_methods() {
  * is to push the javascript into the header of the page in which case you don't
  * add any paramters as all. This is useful for filtered nodes where the body is
  * not regenerated every time.
+ * @param $action
+ * @param $methods
+ * @param $vars
+ *   object, with flashvars, params, attributes
+ * @param $html_alt
+ *   string, displays when flash is not present
  */
 function swfobject2_swftools_embed($action = 'add_js', $methods = FALSE, $vars = FALSE, $html_alt = '') {
+  // set some base parameters that will be overridden by incoming data
+  // @TODO get all the standard vars in here
+  $base_params = array(
+    'width' => '100%',
+    'height' => '100%',
+    'version' => variable_get('swftools_params_version', 7),
+    'type' => 'movie',
+    'bgcolor' => variable_get('swftools_params_bgcolor', '#FFFFFF'),
+    'express_redirect' => variable_get('swfobject2_settings_express', false) ? drupal_get_path('module', 'swfobject2') .'/expressinstall.swf' : 'false',
+  );
 
-  // Set flag to indicate if the javascript has been added to the header
-  static $swfobject2_has_run;
-
-  // Output javascript to the header to load the SWF Object code
-  if (!$swfobject2_has_run) {
-    // Add swfobject.js
-    drupal_add_js(swftools_get_player_path() .'/swfobject2/swfobject.js');
-    $swfobject2_has_run = TRUE;
-    if ($action == 'add_js') {
-      // Exit early having put the javascript in the header.
-      return;
-    }
-  }
-
-  // Initialise a counter to give each div a unique id
-  static $unique_id = 0;
+  // Merge in default parameters with passed parameters
+  $vars->params += $base_params;
 
-  // If a specific id has been passed used this, otherwise generate one by combining time and $unique_id
+  // if an ID was passed via parameters, us it
   if ($vars->params['id']) {
-    $id = $vars->params['id'];
+    $attributes['id'] = $vars->params['id'];
     unset($vars->params['id']);
-  } else {
+  }
+  // if no id was passed in via the attributes or parameters, generate one
+  elseif (! $vars->attributes['id']) {
+    // Initialize a counter to give each div a unique id
+    static $unique_id = 0;
+    // Generate ID with $unique_id
     $unique_id++;
-    $id = 'swfobject2-id-' . time() . $unique_id;
+    $vars->attributes['id'] = 'swfobject2-id-' . $unique_id;
   }
 
+  // set the standard class for the display
+  $vars->attributes['class'] .= ' swftools swfobject2';
+
   // Anything in $vars->params will be output - we don't want src_path
   unset($vars->params['src_path']);
 
@@ -69,28 +102,49 @@ function swfobject2_swftools_embed($acti
   // Generate js string ready for output to the page header
   // swfObject takes parameters swfURL, id, width, height, version, expressinstall, flashvars, params, attributes
   // At the moment expressInstall isn't enabled
-  $swf_js = t('swfobject.embedSWF("!url", "!id", "!width", "!height", "!version", "", !flashvars, !params, !attributes);', array(
-    '!url' => $vars->params['src'],
-    '!id' => $id,
-    '!width' => $vars->params['width'],
-    '!height' => $vars->params['height'],
-    '!version' => $vars->params['version'],
-    '!flashvars' => drupal_to_js($vars->flashvars),
-    '!params' => drupal_to_js($vars->params),
-    '!attributes' => drupal_to_js(array('id' => 'swf'.$id)),
-  ));
+  $settings['swfobject2']['items'][$vars->attributes['id']] = array(
+    'url' => $vars->params['src'],
+    'id' => $vars->attributes['id'],
+    'width' => $vars->params['width'],
+    'height' => $vars->params['height'],
+    'version' => $vars->params['version'],
+    'flashvars' => $vars->flashvars,
+    'params' => $vars->params,
+    'attributes' => $vars->attributes,
+  );
 
   // Generate the html markup ready to receive the substitution
-  $html  = '<div id="'. $id .'" class="swftools swfobject2">' . "\n";
-  $html .= $html_alt . "\n";
-  $html .= '</div>' . "\n";
-
-  // Although SWF Object 2 recommends adding js to the page header that will prevent cached filters being used
-  // So we add js to the page body in order that it gets cached too
-  $html .= '<script type="text/javascript">' . "\n";
-  $html .= $swf_js . "\n";
-  $html .= '</script>'  . "\n";
+  $html = array();
+  $html[] = '<div '. drupal_attributes($vars->attributes) .'>';
+  $html[] =  ($html_alt ? $html_alt : t('Sorry, you need to install flash to see this content.'));
+  $html[] = '</div>' . "\n";
+
+   // Add js to the page footer. We don't need to worry about caching this
+  swfobject2_ensure_swfobject($settings);
 
   // Return html markup
-  return $html;
+  return implode("\n", $html);
 }
+
+
+/**
+ * Provides a compatibility layer for the depreciated swfobject_api module
+ * @param $url
+ * @param $params
+ * @param $flashvars
+ * @param $id
+ * @param $attributes
+ * @return unknown_type
+ */
+function theme_swfobject_api($url, $params = array(), $flashvars = array(), $id = null, $attributes = array()) {
+  $return_vars = new stdClass();
+  // merge the id into $params
+  $attributes['id'] = $params['id'] ? $params['id'] : $attributes['id'];
+  // merge the url of the swf into $params
+  $params['src'] = $url;
+  // add the params to the vars
+  $return_vars->params = $params;
+  // add the flashars to the the vars
+  $return_vars->flashvars = $flashvars;
+  return swfobject2_swftools_embed(false, SWFTOOLS_EMBED_METHOD, $return_vars, $params['no_flash'], $attributes);
+}
\ No newline at end of file
