diff -urp nodereference_explorer/js/explorer.actions.js c:\Dev\workspace\nodereference_explorer/js/explorer.actions.js
--- nodereference_explorer/js/explorer.actions.js	2009-07-23 16:52:12.000000000 +0200
+++ c:\Dev\workspace\nodereference_explorer/js/explorer.actions.js	2009-11-08 13:45:52.634800000 +0100
@@ -7,7 +7,7 @@
  * already there from a former request, e. g. loading of node form.
  */
 
-Drupal.nodereference_explorer.actions = {};
+Drupal.nodereference_explorer.actions = Drupal.nodereference_explorer.actions || {};
 
 /**
  * Attaches actions to the core widget, e. g. buttons
@@ -21,7 +21,7 @@ Drupal.behaviors.NodereferenceExplorerAc
   //removes the value
   $('.nodereference-explorer-action-remove-value:not(.nodereference-explorer-processed)', context)
     .click(Drupal.nodereference_explorer.actions.remove).addClass('nodereference-explorer-processed'); 
-}
+};
 
 /**
  * Action for opening the dialog
@@ -96,7 +96,7 @@ Drupal.nodereference_explorer.actions.re
  */
 Drupal.nodereference_explorer.actions.setValue = function(widget, type, value) {
   eval('nodereference_explorer_plugin_cck_' +type+ '_setValue(widget, value);');
-}
+};
 
 /**
  * Clears the select item value. Like setValue() this is type specific
@@ -107,7 +107,7 @@ Drupal.nodereference_explorer.actions.se
  */
 Drupal.nodereference_explorer.actions.removeValue = function(widget, type) {
   eval('nodereference_explorer_plugin_cck_' +type+ '_removeValue(widget);');
-}
+};
 
 /**
  * Add a progress throbber, simulating progress
@@ -118,7 +118,7 @@ Drupal.nodereference_explorer.actions.st
   $(element).after('<span class="views-throbbing">&nbsp</span>');
   if ($('input', element)) //if the action element is an input disable it, preventing multiple clicking
 	$(element).attr('disabled', 'disabled');
-}
+};
 
 /**
  * Stop progress when action done
@@ -129,4 +129,4 @@ Drupal.nodereference_explorer.actions.en
   $(element).next().remove();
   if ($('input', element))  //enable button again
     $(element).removeAttr("disabled");
-}
+};
diff -urp nodereference_explorer/js/explorer.dialog.js c:\Dev\workspace\nodereference_explorer/js/explorer.dialog.js
--- nodereference_explorer/js/explorer.dialog.js	2009-08-18 09:54:14.000000000 +0200
+++ c:\Dev\workspace\nodereference_explorer/js/explorer.dialog.js	2009-11-08 13:24:16.260800000 +0100
@@ -7,7 +7,7 @@
  * id collisions with the underlying form.
  */
 
-Drupal.nodereference_explorer.dialog = {};
+Drupal.nodereference_explorer.dialog = Drupal.nodereference_explorer.dialog || {};
 
 /**
  * Open the dialog with the specified options
@@ -45,7 +45,7 @@ Drupal.nodereference_explorer.dialog.ope
   );
   
   $(dialog).dialog(options);
-}
+};
 
 /**
  * Adds the action buttons to the dialog's button pane
@@ -81,7 +81,7 @@ Drupal.nodereference_explorer.dialog.add
   };
 	
   return buttons;
-}
+};
 
 /**
  * Sets the dialog content to its correct size when using a button pane
@@ -107,7 +107,7 @@ Drupal.nodereference_explorer.dialog.res
     $buttonpane_height = buttonpane.height()/2;
   }
   $(dialog).height($container_height - titlebar.outerHeight() - $buttonpane_height);
-}
+};
 
 /**
  * Masking of node form widgets
diff -urp nodereference_explorer/js/explorer.js c:\Dev\workspace\nodereference_explorer/js/explorer.js
--- nodereference_explorer/js/explorer.js	2009-07-23 16:52:12.000000000 +0200
+++ c:\Dev\workspace\nodereference_explorer/js/explorer.js	2009-11-08 13:46:27.808800000 +0100
@@ -22,7 +22,19 @@ Drupal.nodereference_explorer.addedCSS =
 Drupal.behaviors.NodereferenceExplorer = function(context) {
    //add css class to surrounding wrapper, needed for theming
   $('.nodereference-explorer .form-autocomplete', context).parent().addClass('nodereference-explorer-wrapper');
-}
+};
+
+/**
+ * Return filename without path
+ * 
+ * @param file
+ *          Filepath
+ * @return basename Filename without path
+ */
+Drupal.nodereference_explorer.getBasename = function(file) {
+  var parts = file.split('/');
+  return parts[parts.length - 1];
+};
 
 /**
  * Get the nodereference_explorer settings. The component (subwidget) id
@@ -57,7 +69,9 @@ Drupal.nodereference_explorer.addCSS = f
     for (var file in css[type]) {
       var link = css[type][file];
       // Does the page already contain this stylesheet?
-      if (!$('link[href='+ $(link).attr('href') + ']').length) {
+       // Does the page already contain this stylesheet?
+      var basename = Drupal.nodereference_explorer.getBasename(file);
+      if (!Drupal.settings.cssInit[basename] && !$('link[href='+ $(link).attr('href') + ']').length) {
         $('head').append(link);
          Drupal.nodereference_explorer.addedCSS.push(link); // Keep a list, so we can remove them later.
       }
@@ -80,7 +94,11 @@ Drupal.nodereference_explorer.addJS = fu
           inlines.push($(js[type][file]).text());
         }
         else {
-          scripts.push($(js[type][file]).attr('src'));
+          var source = $(js[type][file]).attr('src');
+          scripts.push(source);
+          if (Drupal.settings.jsInit[file]) {
+            Drupal.nodereference_explorer.addedJS[source] = true;
+          }
         }
       }
     }
diff -urp nodereference_explorer/js/explorer.modalframe.js c:\Dev\workspace\nodereference_explorer/js/explorer.modalframe.js
--- nodereference_explorer/js/explorer.modalframe.js	2009-07-23 16:52:12.000000000 +0200
+++ c:\Dev\workspace\nodereference_explorer/js/explorer.modalframe.js	2009-11-08 13:24:39.565800000 +0100
@@ -7,7 +7,7 @@
  * to use the Modal Frames API module to open the popup views.
  */
 
-Drupal.nodereference_explorer.modalframe = {};
+Drupal.nodereference_explorer.modalframe = Drupal.nodereference_explorer.modalframe || {};
 
 /**
  * Open a modalframe dialog
@@ -37,4 +37,4 @@ Drupal.nodereference_explorer.modalframe
       Drupal.nodereference_explorer.actions.setValue(widget, type, args.selection);
     }
   };
-}
+};
diff -urp nodereference_explorer/js/explorer.preview.js c:\Dev\workspace\nodereference_explorer/js/explorer.preview.js
--- nodereference_explorer/js/explorer.preview.js	2009-08-18 09:54:14.000000000 +0200
+++ c:\Dev\workspace\nodereference_explorer/js/explorer.preview.js	2009-11-08 13:47:03.622800000 +0100
@@ -7,7 +7,7 @@
  * CCK fields.
  */
 
-Drupal.nodereference_explorer.preview = {};
+Drupal.nodereference_explorer.preview = Drupal.nodereference_explorer.preview || {};
 
 /**
  * Preview behavior. Each preview wrapper loads the preview if the core widget changes
@@ -37,7 +37,7 @@ Drupal.behaviors.NodereferenceExplorerPr
       $(widget).blur();
     })
     .addClass('nodereference-explorer-processed');
-}
+};
 
 /**
  * Load the preview via JSON
@@ -61,7 +61,7 @@ Drupal.nodereference_explorer.preview.ge
       $(preview).text('');
     }
   });
-}
+};
 
 /**
  * Fix for id collisions between node form and view filter form.
@@ -71,4 +71,4 @@ Drupal.nodereference_explorer.preview.ge
 Drupal.nodereference_explorer.preview.showTitle = function () {
   $('#edit-title-wrapper').show();
   $('#edit-title').show();	
-}
+};

diff -urp nodereference_explorer/js/explorer.settings.js c:\Dev\workspace\nodereference_explorer/js/explorer.settings.js
--- nodereference_explorer/js/explorer.settings.js	2009-07-23 16:52:12.000000000 +0200
+++ c:\Dev\workspace\nodereference_explorer/js/explorer.settings.js	2009-11-08 13:21:47.114600000 +0100
@@ -30,4 +30,4 @@ Drupal.behaviors.NodereferenceExplorerSe
   if ($('#edit-advanced-view:not(.nodereference-explorer-processed)', context))
     $('#edit-advanced-view', context).change().addClass('nodereference-explorer-processed'); 
  
-}
+};

diff -urp nodereference_explorer/js/explorer.tabs.js c:\Dev\workspace\nodereference_explorer/js/explorer.tabs.js
--- nodereference_explorer/js/explorer.tabs.js	2009-07-17 17:38:28.000000000 +0200
+++ c:\Dev\workspace\nodereference_explorer/js/explorer.tabs.js	2009-11-08 13:21:53.499600000 +0100
@@ -43,4 +43,4 @@ Drupal.behaviors.NodereferenceExplorerTa
     var display = $(ui.panel).attr('id');
     $('#filter-'+display).show();
   });
-}
+};

diff -urp nodereference_explorer/nodereference_explorer.module c:\Dev\workspace\nodereference_explorer/nodereference_explorer.module
--- nodereference_explorer/nodereference_explorer.module	2009-07-28 17:14:18.000000000 +0200
+++ c:\Dev\workspace\nodereference_explorer/nodereference_explorer.module	2009-11-08 13:07:18.626600000 +0100
@@ -307,4 +307,70 @@ function nodereference_explorer_add_js($
       }
     }
   }
+}
+
+/**
+ * Implementation of hook_theme_registry_alter().
+ *
+ * Make Nodereference page preprocess function run *after* everything else's,
+ * so that a theme can't call drupal_get_js() and mess everything up.
+ *
+ * @source jquery_update_theme_registry_alter()
+ * @see nodereference_explorer_preprocess_page()
+ */
+function nodereference_explorer_theme_registry_alter(&$theme_registry) {
+  if (isset($theme_registry['page'])) {
+    // If jquery_update's preprocess function is there already, remove it.
+    if ($key = array_search('nodereference_explorer_preprocess_page', $theme_registry['page']['preprocess functions'])) {
+      unset($theme_registry['page']['preprocess functions'][$key]);
+    }
+    // Now tack it on at the end so it runs after everything else.
+    $theme_registry['page']['preprocess functions'][] = 'nodereference_explorer_preprocess_page';
+  }
+}
+
+/**
+ * Implementation of moduleName_preprocess_hook().
+ *
+ * A theme preprocess function to allow content type plugins to use page
+ * template variables which are not yet available when the content type is
+ * rendered.
+ *
+ * We need to store which JS and CSS files were included in the page, because
+ * when JS and CSS optimalization is enabled, all these files are aggregrated into the
+ * single file and this information is lost. Duplicate loading is causing errors or
+ * unwanted behavior, ie. conflicts caused by duplicate javascript event handlers or
+ * reset of the color scheme.
+ *
+ * In this hook we capture all JS and CSS files which are going to be included in the page
+ * and we add them to the Drupal.settings.jsInit and Drupal.settings.cssInit arrays
+ */
+function nodereference_explorer_preprocess_page(&$vars) {
+  $sections = array('core', 'module', 'theme');
+  // load all javascript
+  $javascript = drupal_add_js();
+  $styles = drupal_add_css();
+  $js = $css = array();
+  // we dont have 'theme' styles at this phase, so we add main theme file "style.css" manually
+  // this will prevent override of color.module customized theme
+  $css[] = 'style.css';
+
+  // iterate through all sections and add all js and css files to our Drupal.settings storage
+  foreach ($sections as $section) {
+    $js += isset($javascript[$section]) ? array_keys($javascript[$section]) : array();
+    $css += isset($styles['all'][$section]) ? array_keys($styles['all'][$section]) : array();
+  }
+
+  // process javascript files
+  $js = array_filter($js);
+  $js = array_fill_keys($js , TRUE);
+  $javascript['setting'][] = array('jsInit' => $js);
+
+  // process css files
+  $css = array_map('basename', array_filter($css));
+  $css = array_fill_keys($css , TRUE);
+  $javascript['setting'][] = array('cssInit' => $css);
+
+  // save processed settings back to header variable
+  $vars['scripts'] = drupal_get_js('header', $javascript);
 }
