diff --git a/jwplayermodule_swfobject.js b/jwplayermodule_swfobject.js
index 3c9a83e..b406add 100644
--- a/jwplayermodule_swfobject.js
+++ b/jwplayermodule_swfobject.js
@@ -1,12 +1,43 @@
 
 
 /**
+ * Before swfobject class items are loaded as swfobjects, we need
+ * be sure the external swfobject library is loaded
+ */
+Drupal.behaviors.jwplayermodule = function (context) {
+  if($('html:not(.jwplayermodule-processed)', context).length > 0){
+    $('html:not(.jwplayermodule-processed)', context).addClass('jwplayermodule-processed').each(function () {
+      var s = document.createElement("script");
+      s.setAttribute("type","text/javascript");
+      if (s.readyState){  //IE
+        s.onreadystatechange = function(){
+          if (s.readyState == "loaded" || s.readyState == "complete"){
+            s.onreadystatechange = null;
+            jwplayermodule_swfobjectInit(context);
+          }
+        };
+      } 
+      else {  //Others
+        s.onload = function(){
+          jwplayermodule_swfobjectInit(context);
+        };
+      }
+      s.setAttribute("src",Drupal.settings.jwplayermodule.external_js);
+      document.getElementsByTagName("head")[0].appendChild(s);
+    });
+  }
+  else{
+    jwplayermodule_swfobjectInit(context)
+  }
+};
+
+/**
  * This function looks for swfobject class items and loads them
  * as swfobjects. 
  */
-Drupal.behaviors.swfobjectInit = function (context) {
+function jwplayermodule_swfobjectInit(context){
   $('.swfobject:not(.swfobjectInit-processed)', context).addClass('swfobjectInit-processed').each(function () {
     var config = Drupal.settings.swfobject['files'][$(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);
   });
-};
+}
diff --git a/jwplayermodule_theme.inc b/jwplayermodule_theme.inc
index e6178d4..367acf2 100644
--- a/jwplayermodule_theme.inc
+++ b/jwplayermodule_theme.inc
@@ -48,7 +48,8 @@ function theme_jwplayermodule_render_player($config, $flash_vars) {
     } else {
       $external_js = "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js";
       //Drupal 6.x cannot add external javascript normally.  This hack circumvents that.
-      drupal_add_js('document.write(unescape("%3Cscript src=\''. $external_js . '\' type=\'text/javascript\'%3E%3C/script%3E"));', 'inline');
+      //It will load the script as required from behaviors
+      drupal_add_js(array('jwplayermodule' => array('external_js' => $external_js)), "setting");
       drupal_add_js(drupal_get_path("module", "jwplayermodule") . "/jwplayermodule_swfobject.js", "module", "footer");
     }
     $done = TRUE;
@@ -165,4 +166,4 @@ function theme_jwplayermodule_admin($form) {
   }
   $output .= drupal_render($form);
   return $output;
-}
\ No newline at end of file
+}
