--- swfobject_api.module.orig	2008-09-11 19:57:31.000000000 +0000
+++ swfobject_api.module	2008-12-04 10:25:13.000000000 +0000
@@ -45,25 +45,19 @@ function swfobject_api_menu($may_cache) 
 function swfobject_api_settings_form() {
   $form = array();
 
-  $form['swfobject_api_settings'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Settings'),
-    '#tree' => TRUE
-  );
-  $form['swfobject_api_settings']['swfoa_version'] = array(
+  $form['swfoa_version'] = array(  
     '#type' => 'textfield',
     '#title' => t('Default minimum version required'),
     '#description' => t('This value can be overridden via the theme call.'),
-    '#default_value' => variable_get('swfoa_express', '6'),
+    '#default_value' => variable_get('swfoa_version', '6'),
     '#required' => TRUE
   );
-  $form['swfobject_api_settings']['swfoa_express'] = array(
+  $form['swfoa_express'] = array(
     '#type' => 'checkbox',
     '#title' => t('Enable express install.'),
     '#description' => t('Express install allows player upgrades without having to leave the site. Only versions 6.0.65 and above are supported.'),
-    '#default_value' => variable_get('swfoa_express', ''),
+    '#default_value' => variable_get('swfoa_express', FALSE),
   );
-  $form['submit'] = array('#type' => 'submit', '#value' => t('Save settings'));
 
   return system_settings_form($form);
 }
@@ -101,12 +95,15 @@ function swfobject_api_build_variables($
  * @return 
  *   themed html
  */
-function theme_swfobject_api($url, $params = null, $flashvars = null, $id = null) {
+function theme_swfobject_api($url, $params = NULL, $flashvars = NULL, $id = NULL) {
   static $id_count;  
   
-  // get the path to thje swf object library
-  drupal_add_js(drupal_get_path('module', 'swfobject_api') .'/swfobject.js');
-  
+  // get the path to the swf object library
+  $path = drupal_get_path('module', 'swfobject_api');
+  drupal_add_js($path .'/swfobject.js');
+
+
+
   $base_params = array(
     'width' => '100%',
     'height' => '100%',
@@ -115,24 +112,23 @@ function theme_swfobject_api($url, $para
     'type' => 'movie',
     'bg_color' => '#FFFFFF'
   );
-  
-  $params = array_merge($base_params, $params);
-  
-  // Express install redirect URL: as per the SWFObject docs, this should
-  // actually be xiRedirectUrl; variable name changed for simplicity.
-  if (isset($param['express_redirect'])) {
-    $redirect = $param['express_redirect'];
-  }
- 
+
+  // merge the parameters
+  if ($params) {
+    $params = array_merge($base_params, $params);
+  }    
+
   // create a unique id, use what's passed in, what has been saved locally
-  if ($id) { $id_count = $id; }
+  if ($id) { 
+    $id_count = $id;
+  }
   else {
     $id_count = $id_count ? $id_count : 1;
   }
   
   // set the name of the swf file
   $name = form_clean_id(str_replace('.swf', '', basename($url))) .'_'. $id_count;
- 
+
   // set the div id to the params
   if ($params['div_id']) {
     $div_id = $params['div_id'];
@@ -148,39 +144,79 @@ function theme_swfobject_api($url, $para
     $class = ' class="'. $params['class'] .'"';
     unset($params['class']);
   }
-  
-  // build the div structure
-  $html[]  = '<div id="'. $div_id .'" '. $class .'>'. $params['no_flash'] .'</div>';
- 
-  // build the javascript output
-  $html[] = '<script type="text/javascript"><!-- ';
+
+  // build the javascript
+  $script = array();
+  $script[] = "$(document).ready(function () {";
  
-  
+  // add the parameters
+  if ($params) {
+    $script[] = 'var params = {';
+    $i = 1;
+    $count = count($params);
+    foreach ($params as $key => $value) {
+      // we don't output a comma on the last element in the array
+      $comma = $i++ < $count ? ',' : '';
+      $script[] = "  $key: '$value'" . $comma;
+    }
+    $script[] ='};';
+  }
+
+  // add the flashvars
+  if ($flashvars) {
+    $script[] = 'var flashvars = {';
+    $i = 1;
+    $count = count($flashvars);
+    foreach ($flashvars as $key => $value) {
+      $comma = $i++ < $count ? ',' : '';
+      $script[] = "  $key: '$value'" . $comma;
+    }
+    $script[] = "};";
+  }
+  else {
+    $script[] = "var flashvars = false;";
+  }
+
+  // add the attributes
+  if ($attributes) {
+    $script[] = 'var attributes = {';
+    $i = 1;
+    $count = count($attributes);
+    foreach ($attributes as $key => $value) {
+      $comma = $i++ < $count ? ',' : '';
+      $script[] = "  $key: '$value'" . $comma;
+    }
+    $script[] = "};";
+  }
+  else {
+    $script[] = "var attributes = {};";
+  } 
+
   // Express install redirect URL: as per the SWFObject docs, this should
   // actually be xiRedirectUrl; variable name changed for simplicity.
-  if (! $params['express_redirect']) {
-    $params['express_redirect'] = variable_get('swfoa_express', true) ? base_path() . drupal_get_path('module', 'swfobject_api') .'/expressinstall.swf' : 'false';
+  if (!$params['express_redirect']) {
+    $params['express_redirect'] = variable_get('swfoa_express', TRUE) ? drupal_get_path('module', 'swfobject_api') .'/expressinstall.swf' : 'false';
   }
 
   // Set the minimum version of flash expected
-  if (! $params['version']) {
+  if (!$params['version']) {
     $params['version'] = variable_get('swfoa_version', 9) ? variable_get('swfoa_express', "9.0.0") : 'false';
   }
-  
-  // get the parameters for this object
-  $script[] = swfobject_api_build_variables($flashvars, $params, $attributes);
-  
-  // build the swfobject the swfojbect
+ 
+  // register the swfojbect
   $script[] = "  swfobject.embedSWF('$url', '$div_id', '". $params['width'] ."', '". $params['height'] ."', '".  $params['version'] ."', '". $params['express_redirect'] ."', flashvars, params, attributes );";
-    
-  // build the complete output
-  $html[] = ' $(document).ready(function () {';
-  $html[] = implode("\n", $script);
-  $html[] = '}); ';
-  $html[] = "--></script>\n";
+
+  // close the document ready
+  $script[] = "});";
+
+  // output the js
+  drupal_add_js(implode("", $script), 'inline' );
 
   // increment the id count
-  $id_count ++;
-  
+  $id_count++;
+
+  // create the html output
+  $html[] = '<div id="' .$div_id .'" ' .$class .'>' .$params['no_flash'] ."</div>";
+
   return implode("\n", $html);
 }
\ No newline at end of file
