Index: modules/overlay/overlay-parent.css
===================================================================
RCS file: /cvs/drupal/drupal/modules/overlay/overlay-parent.css,v
retrieving revision 1.3
diff -u -r1.3 overlay-parent.css
--- modules/overlay/overlay-parent.css	15 Dec 2009 05:28:59 -0000	1.3
+++ modules/overlay/overlay-parent.css	17 Dec 2009 14:55:15 -0000
@@ -68,9 +68,6 @@
   padding: 0;
   overflow: visible;
   background: #fff url(images/loading.gif) no-repeat 50% 50%;
-  -webkit-box-shadow: 8px 8px 8px rgba(0,0,0,.5);
-  -moz-box-shadow: 8px 8px 8px rgba(0,0,0,.5);
-  box-shadow: 8px 8px 8px rgba(0,0,0,.5);
 }
 .overlay-loaded #overlay-container {
   background: none;
@@ -96,6 +93,20 @@
   margin: 0 0 0 -3px;
   padding: 0;
 }
+/**
+ * CSS Hack for IE 7 and below.
+ * http://www.webdevout.net/css-hacks#in_css-selectors
+ */
+*:first-child+html .overlay .ui-dialog-titlebar ul li {
+  display: inline;
+}
+* html .overlay .ui-dialog-titlebar ul li {
+  display: inline;
+}
+/**
+ * End of CSS Hack for IE 7 and below.
+ */
+
 .overlay .ui-dialog-titlebar ul li a,
 .overlay .ui-dialog-titlebar ul li a:active,
 .overlay .ui-dialog-titlebar ul li a:visited,
Index: modules/overlay/overlay-parent.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/overlay/overlay-parent.js,v
retrieving revision 1.7
diff -u -r1.7 overlay-parent.js
--- modules/overlay/overlay-parent.js	15 Dec 2009 05:28:59 -0000	1.7
+++ modules/overlay/overlay-parent.js	17 Dec 2009 14:55:15 -0000
@@ -29,8 +29,8 @@
     $('#toolbar a.toggle', context).once('overlay').click(function () {
       setTimeout(function () {
         // Resize the overlay, if it's open.
-        if (Drupal.overlay.iframe.documentSize) {
-          Drupal.overlay.resize(Drupal.overlay.iframe.documentSize);
+        if (Drupal.overlay.iframeDocumentSize) {
+          Drupal.overlay.resize(Drupal.overlay.iframeDocumentSize);
         }
       }, 150);
     });
@@ -65,8 +65,22 @@
  */
 Drupal.overlay = Drupal.overlay || {
   options: {},
-  iframe: { $container: null, $element: null },
-  isOpen: false
+  isOpen: false,
+  
+  autoResizing: false,
+  
+  beforeCloseEnabled: false,
+  beforeCloseIsBusy: false,
+  
+  $dialog: null,
+  $container: null,
+  $iframe: null,
+  
+  iframeDocumentSize: null,
+  
+  $iFrameWindow: null,
+  $iFrameDocument: null,
+  $iFrameBody: null
 };
 
 /**
@@ -108,7 +122,7 @@
     onOverlayCanClose: options.onOverlayCanClose,
     onOverlayClose: options.onOverlayClose,
     customDialogOptions: options.customDialogOptions || {}
-  }
+  };
 
   self.options = $.extend(defaultOptions, options);
 
@@ -116,7 +130,7 @@
   self.create();
 
   // Open the dialog offscreen where we can set its size, etc.
-  var temp = self.iframe.$container.dialog('option', { position: ['-999em', '-999em'] }).dialog('open');;
+  self.$container.dialog('option', { position: ['-999em', '-999em'] }).dialog('open');
 
   return true;
 };
@@ -130,10 +144,8 @@
 Drupal.overlay.create = function () {
   var self = this;
 
-  self.iframe.$element = $(Drupal.theme('overlayElement'));
-  self.iframe.$container = $(Drupal.theme('overlayContainer')).append(self.iframe.$element);
-
-  $('body').append(self.iframe.$container);
+  self.$iframe = $(Drupal.theme('overlayElement'));
+  self.$container = $(Drupal.theme('overlayContainer')).append(self.$iframe);
 
   // Open callback for jQuery UI Dialog.
   var dialogOpen = function () {
@@ -143,10 +155,11 @@
     // Also, this is not necessary here because we need to deal with an
     // iframe element that contains a separate window.
     // We'll try to provide our own behavior from bindChild() method.
-    $('.overlay').unbind('keypress.ui-dialog');
+    self.$dialog.unbind('keypress.ui-dialog');
 
     // Adjust close button features.
-    $('.overlay .ui-dialog-titlebar-close:not(.overlay-processed)').addClass('overlay-processed')
+    self.$dialog.find('.ui-dialog-titlebar-close:not(.overlay-processed)')
+      .addClass('overlay-processed')
       .attr('href', '#')
       .attr('title', Drupal.t('Close'))
       .unbind('click')
@@ -157,33 +170,33 @@
       });
 
     // Replace the title span element with an h1 element for accessibility.
-    $('.overlay .ui-dialog-title').replaceWith(Drupal.theme('overlayTitleHeader', $('.overlay .ui-dialog-title').html()));
+    self.$dialog.find('.ui-dialog-title')
+      .replaceWith(Drupal.theme('overlayTitleHeader', $('.ui-dialog-title', self.$dialog).html()));
 
     // Compute initial dialog size.
     var dialogSize = self.sanitizeSize({width: self.options.width, height: self.options.height});
 
     // Compute frame size and dialog position based on dialog size.
     var frameSize = $.extend({}, dialogSize);
-    frameSize.height -= $('.overlay .ui-dialog-titlebar').outerHeight(true);
-    var dialogPosition = self.computePosition($('.overlay'), dialogSize);
+    frameSize.height -= self.$dialog.find('.ui-dialog-titlebar').outerHeight(true);
+    var dialogPosition = self.computePosition(self.$dialog, dialogSize);
 
     // Adjust size of the iframe element and container.
-    $('.overlay').width(dialogSize.width).height(dialogSize.height);
-    self.iframe.$container.width(frameSize.width).height(frameSize.height);
-    self.iframe.$element.width(frameSize.width).height(frameSize.height);
+    self.$container.width(frameSize.width).height(frameSize.height);
+    self.$iframe.width(frameSize.width).height(frameSize.height);
 
     // Update the dialog size so that UI internals are aware of the change.
-    self.iframe.$container.dialog('option', { width: dialogSize.width, height: dialogSize.height });
-
-    // Hide the dialog, position it on the viewport and then fade it in with
-    // the frame hidden until the child document is loaded.
-    self.iframe.$element.hide();
-    $('.overlay').hide().css({top: dialogPosition.top, left: dialogPosition.left});
-    $('.overlay').fadeIn('fast', function () {
-      // Load the document on hidden iframe (see bindChild method).
-      self.load(self.options.url);
+    self.$container.dialog('option', {
+      width: dialogSize.width,
+      height: dialogSize.height,
+      position: [dialogPosition.left, dialogPosition.top]
     });
 
+    // Hide the iframe hidden until the child document is loaded.
+    self.$iframe.hide();
+    // Load the document on hidden iframe (see bindChild method).
+    self.load(self.options.url);
+
     if ($.isFunction(self.options.onOverlayOpen)) {
       self.options.onOverlayOpen(self);
     }
@@ -206,15 +219,18 @@
   // Close callback for jQuery UI Dialog.
   var dialogClose = function () {
     $(document).unbind('keydown.overlay-event');
-    $('.overlay .ui-dialog-titlebar-close').unbind('keydown.overlay-event');
+    self.$dialog.find('.ui-dialog-titlebar-close').unbind('keydown.overlay-event');
     try {
-      self.iframe.$element.remove();
-      self.iframe.$container.dialog('destroy').remove();
+      self.$iframe.remove();
+      self.$container.dialog('destroy').remove();
     } catch(e) {};
-    delete self.iframe.documentSize;
-    delete self.iframe.Drupal;
-    delete self.iframe.$element;
-    delete self.iframe.$container;
+    delete self.iframeDocumentSize;
+    delete self.$iframe;
+    delete self.$container;
+    delete self.$dialog;
+    delete self.$iFrameWindow;
+    delete self.$iFrameDocument;
+    delete self.$iFrameBody;
     if (self.beforeCloseEnabled) {
       delete self.beforeCloseEnabled;
     }
@@ -242,7 +258,9 @@
   $.extend(dialogOptions, self.options.customDialogOptions);
 
   // Create the jQuery UI Dialog.
-  self.iframe.$container.dialog(dialogOptions);
+  self.$container.dialog(dialogOptions);
+  // Cache dialog selector.
+  self.$dialog = $('.' + dialogOptions.dialogClass);
 };
 
 /**
@@ -253,23 +271,24 @@
  */
 Drupal.overlay.load = function (url) {
   var self = this;
-  var iframe = self.iframe.$element.get(0);
+  var iframeElement = self.$iframe.get(0);
   
   // Add a loaded class to the overlay once the iframe is loaded.
-  $(iframe).load(function () {
-    $('.overlay').addClass('overlay-loaded');
+  self.$iframe.load(function () {
+    self.$dialog.addClass('overlay-loaded');
   });
   
   // Get the document object of the iframe window.
   // @see http://xkr.us/articles/dom/iframe-document/
-  var doc = (iframe.contentWindow || iframe.contentDocument);
-  if (doc.document) {
-    doc = doc.document;
+  var iframeDocument = (iframeElement.contentWindow || iframeElement.contentDocument);
+  if (iframeDocument.document) {
+    iframeDocument = iframeDocument.document;
   }
+  
   // location.replace doesn't create a history entry. location.href does.
   // In this case, we want location.replace, as we're creating the history
   // entry using URL fragments.
-  doc.location.replace(url);
+  iframeDocument.location.replace(url);
 };
 
 /**
@@ -295,14 +314,6 @@
 Drupal.overlay.close = function (args, statusMessages) {
   var self = this;
 
-  // Offer the user a chance to change their mind if there is a form on the
-  // page, which may have unsaved work on it.
-  var iframeElement = self.iframe.$element.get(0);
-  var iframeDocument = (iframeElement.contentWindow || iframeElement.contentDocument);
-  if (iframeDocument.document) {
-    iframeDocument = iframeDocument.document;
-  }
-
   // Check if the dialog can be closed.
   if (!self.canClose()) {
     delete self.beforeCloseIsBusy;
@@ -312,21 +323,22 @@
   // Hide and destroy the dialog.
   function closeDialog() {
     // Prevent double execution when close is requested more than once.
-    if (!$.isObject(self.iframe.$container)) {
+    if (!$.isObject(self.$container)) {
       return;
     }
     self.beforeCloseEnabled = true;
-    self.iframe.$container.dialog('close');
+    self.$container.dialog('close');
     if ($.isFunction(self.options.onOverlayClose)) {
       self.options.onOverlayClose(args, statusMessages);
     }
   }
-  if (!$.isObject(self.iframe.$element) || !self.iframe.$element.size() || !self.iframe.$element.is(':visible')) {
+
+  if (!$.isObject(self.$iframe) || !self.$iframe.size() || !self.$iframe.is(':visible')) {
     closeDialog();
   }
   else {
-    self.iframe.$container.animate({height: 'hide'}, { duration: 'fast', 'queue': false });
-    $('.overlay').animate({opacity: 'hide'}, closeDialog);
+    self.$container.animate({height: 'hide'}, { duration: 'fast', 'queue': false });
+    self.$dialog.animate({opacity: 'hide'}, closeDialog);
   }
   return true;
 };
@@ -344,7 +356,7 @@
   }
   location.href = link;
   return true;
-}
+};
 
 /**
  * Bind the child window.
@@ -353,10 +365,9 @@
  */
 Drupal.overlay.bindChild = function (iFrameWindow, isClosing) {
   var self = this;
-  var $iFrameWindow = iFrameWindow.jQuery;
-  var $iFrameDocument = $iFrameWindow(iFrameWindow.document);
-  var autoResizing = false;
-  self.iframe.Drupal = iFrameWindow.Drupal;
+  self.$iFrameWindow = iFrameWindow.jQuery;
+  self.$iFrameDocument = self.$iFrameWindow(iFrameWindow.document);
+  self.$iframeBody = self.$iFrameWindow('body');
 
   // We are done if the child window is closing.
   if (isClosing) {
@@ -364,47 +375,48 @@
   }
 
   // Make sure the parent window URL matches the child window URL.
-  self.syncChildLocation($iFrameDocument[0].location);
+  self.syncChildLocation(iFrameWindow.document.location);
   // Update the dialog title with the child window title.
-  $('.overlay .ui-dialog-title').html($iFrameDocument.attr('title')).focus();
+  self.$dialog.find('.ui-dialog-title').html(self.$iFrameDocument.attr('title')).focus();
   // Add a title attribute to the iframe for accessibility.
-  self.iframe.$element.attr('title', Drupal.t('@title dialog', { '@title': $iFrameDocument.attr('title') }));
+  self.$iframe.attr('title', Drupal.t('@title dialog', { '@title': self.$iFrameDocument.attr('title') }));
 
   // If the shortcut add/delete button exists, move it to the dialog title.
-  var addToShortcuts = $('.add-or-remove-shortcuts', $iFrameDocument);
-  if (addToShortcuts.length) {
+  var $addToShortcuts = self.$iFrameWindow('.add-or-remove-shortcuts');
+  if ($addToShortcuts.length) {
     // Remove any existing shortcut button markup in the title section.
-    $('.ui-dialog-titlebar .add-or-remove-shortcuts').remove();
+    self.$dialog.find('.ui-dialog-titlebar .add-or-remove-shortcuts').remove();
     // Make the link overlay-friendly.
-    var $link = $('a', addToShortcuts);
+    var $link = $('a', $addToShortcuts);
     $link.attr('href', Drupal.overlay.fragmentizeLink($link.get(0)));
     // Move the button markup to the title section. We need to copy markup
     // instead of moving the DOM element, because Webkit browsers will not
     // move DOM elements between two DOM documents.
-    var shortcutsMarkup = '<div class="' + $(addToShortcuts).attr('class') + '">' + $(addToShortcuts).html() + '</div>';
-    $('.overlay .ui-dialog-title').after(shortcutsMarkup);
-    $('.add-or-remove-shortcuts', $iFrameDocument).remove();
+    var shortcutsMarkup = '<div class="' + $($addToShortcuts).attr('class') + '">' + $($addToShortcuts).html() + '</div>';
+    self.$dialog.find('.ui-dialog-title').after(shortcutsMarkup);
+    self.$iFrameWindow('.add-or-remove-shortcuts').remove();
   }
 
   // Remove any existing tabs.
-  $('.overlay .ui-dialog-titlebar ul').remove();
+  self.$dialog.find('.ui-dialog-titlebar ul').remove();
 
   // Setting tabIndex makes the div focusable.
-  $iFrameDocument.attr('tabindex', -1);
+  self.$iFrameDocument.attr('tabindex', -1);
 
-  $('.ui-dialog-titlebar-close-bg').animate({opacity: 0.9999}, 'fast');
+  // @todo does this element exist?
+  self.$dialog.find('.ui-dialog-titlebar-close-bg').animate({opacity: 0.9999}, 'fast');
 
   // Perform animation to show the iframe element.
-  self.iframe.$element.fadeIn('fast', function () {
+  self.$iframe.fadeIn('fast', function () {
     // @todo: Watch for experience in the way we compute the size of the
     // iframed document. There are many ways to do it, and none of them
     // seem to be perfect. Note though, that the size of the iframe itself
     // may affect the size of the child document, especially on fluid layouts.
-    self.iframe.documentSize = { width: $iFrameDocument.width(), height: $iFrameWindow('body').height() + 25 };
+    self.iframeDocumentSize = { width: self.$iFrameDocument.width(), height: self.$iFrameWindow('body').height() + 25 };
 
     // Adjust overlay to fit the iframe content?
     if (self.options.autoFit) {
-      self.resize(self.iframe.documentSize);
+      self.resize(self.iframeDocumentSize);
     }
 
     // Try to enhance keyboard based navigation of the overlay.
@@ -412,13 +424,13 @@
     // http://wiki.codetalks.org/wiki/index.php/Docs/Keyboard_navigable_JS_widgets
 
     // Get a reference to the close button.
-    var $closeButton = $('.overlay .ui-dialog-titlebar-close');
+    var $closeButton = self.$dialog.find('.ui-dialog-titlebar-close');
 
     // Search tabbable elements on the iframed document to speed up related
     // keyboard events.
     // @todo: Do we need to provide a method to update these references when
     // AJAX requests update the DOM on the child document?
-    var $iFrameTabbables = $iFrameWindow(':tabbable:not(form)');
+    var $iFrameTabbables = self.$iFrameWindow(':tabbable:not(form)');
     var $firstTabbable = $iFrameTabbables.filter(':first');
     var $lastTabbable = $iFrameTabbables.filter(':last');
 
@@ -432,7 +444,7 @@
       if (event.keyCode && event.keyCode == $.ui.keyCode.TAB) {
         var $target = (event.shiftKey ? $lastTabbable : $firstTabbable);
         if (!$target.size()) {
-          $target = $iFrameDocument;
+          $target = self.$iFrameDocument;
         }
         setTimeout(function () { $target.focus(); }, 10);
         return false;
@@ -441,7 +453,7 @@
 
     // When the focus leaves the child window, then drive the focus to the
     // close button of the dialog.
-    $iFrameDocument.bind('keydown.overlay-event', function (event) {
+    self.$iFrameDocument.bind('keydown.overlay-event', function (event) {
       if (event.keyCode) {
         if (event.keyCode == $.ui.keyCode.TAB) {
           if (event.shiftKey && event.target == $firstTabbable.get(0)) {
@@ -460,54 +472,62 @@
       }
     });
 
+    var previousHeight;
     var autoResize = function () {
-      if (typeof self.iframe.$element == 'undefined') {
-        autoResizing = false;
+      if (typeof self.$iframe == 'undefined') {
+        self.autoResizing = false;
         $(window).unbind('resize', windowResize);
         return;
       }
-      var iframeElement = self.iframe.$element.get(0);
-      var iframeDocument = (iframeElement.contentWindow || iframeElement.contentDocument);
-      if (iframeDocument.document) {
-        iframeDocument = iframeDocument.document;
-      }
+      
       // Use outerHeight() because otherwise the calculation will be off
       // because of padding and/or border added by the theme.
-      var height = $(iframeDocument).find('body').outerHeight() + 25;
-      self.iframe.$element.css('height', height);
-      self.iframe.$container.css('height', height);
-      self.iframe.$container.parent().css('height', height + 45);
-      // Don't allow the shadow background to shrink so it's not enough to hide
-      // the whole page. Take the existing document height (with overlay) and
-      // the body height itself for our base calculation.
-      var docHeight = Math.min($(document).find('body').outerHeight(), $(document).height());
-      $('.ui-widget-overlay').height(Math.max(docHeight, $(window).height(), height + 145));
+      var height = self.$iframeBody.outerHeight() + 25;
+      // Only update height when changed.
+      if (height != previousHeight) {
+        self.$iframe.height(height);
+        self.$container.height(height);
+        
+        // Update the dialog size so that UI internals are aware of the change.
+        self.$container.dialog('option', {height: height + 45});
+  
+        // Don't allow the shadow background to shrink so it's not enough to hide
+        // the whole page. Take the existing document height (with overlay) and
+        // the body height itself for our base calculation.
+        // The width needs to be updated when the height change resulted in a scrollbar.
+        var docHeight = Math.min($('body').outerHeight(), $(document).height());
+        $('.ui-widget-overlay')
+          .height(Math.max(docHeight, $(window).height(), height + 145))
+          .width($('body').outerWidth());
+      }
+
+      previousHeight = height;
       setTimeout(autoResize, 150);
     };
 
     var windowResize = function () {
-      var width = $(window).width()
+      var width = $(window).width();
       var change = lastWidth - width;
-      var currentWidth = self.iframe.$element.width();
+      var currentWidth = self.$iframe.width();
       var newWidth = lastFrameWidth - change;
       lastWidth = width;
       lastFrameWidth = newWidth;
 
       if (newWidth >= 300) {
-        self.iframe.$element.css('width', newWidth);
-        self.iframe.$container.css('width', newWidth);
-        self.iframe.$container.parent().css('width', newWidth);
+        self.$iframe.width(newWidth);
+        self.$container.width(newWidth);
+        self.$dialog.width(newWidth);
         widthBelowMin = false;
       }
       else {
         widthBelowMin = true;
       }
-    }
+    };
 
-    if (!autoResizing) {
-      autoResizing = true;
+    if (!self.autoResizing) {
+      self.autoResizing = true;
       autoResize();
-      var lastFrameWidth = self.iframe.$element.width();
+      var lastFrameWidth = self.$iframe.width();
       var lastWidth = $(window).width();
       $(window).resize(windowResize);
     }
@@ -518,7 +538,7 @@
     $(document).bind('keydown.overlay-event', function (event) {
       if (event.keyCode && event.keyCode == $.ui.keyCode.TAB) {
         setTimeout(function () {
-          if (!$iFrameWindow(':tabbable:not(form):first').focus().size()) {
+          if (!self.$iFrameWindow(':tabbable:not(form):first').focus().size()) {
             $closeButton.focus();
           }
         }, 10);
@@ -527,18 +547,20 @@
     });
 
     // If there are tabs in the page, move them to the titlebar.
-    var tabs = $iFrameDocument.find('ul.primary').get(0);
-
-    // This breaks in anything less than IE 7. Prevent it from running.
-    if (typeof tabs != 'undefined' && (!$.browser.msie || parseInt($.browser.version) >= 7)) {
-      $('.ui-dialog-titlebar').append($(tabs).remove().get(0));
-      if ($(tabs).is('.primary')) {
-        $(tabs).find('a').removeClass('overlay-processed');
-        Drupal.attachBehaviors($(tabs));
+    var $tabs = self.$iFrameWindow('ul.primary');
+    if ($tabs.size()) {
+      // Copy HTML of tabs in iframe instead of moving as IE6 and below doesn't
+      // support moving elements from one DOM to another.
+      $tabs = $(self.$iFrameWindow('<div>').append($tabs.clone()).remove().html());
+
+      self.$dialog.find('.ui-dialog-titlebar').append($tabs);
+      if ($tabs.is('.primary')) {
+        $tabs.find('a').removeClass('overlay-processed');
+        Drupal.attachBehaviors($tabs);
       }
       // Remove any classes from the list element to avoid theme styles
       // clashing with our styling.
-      $(tabs).removeAttr('class');
+      $tabs.removeAttr('class');
     }
   });
 };
@@ -556,10 +578,10 @@
   iFrameWindow.jQuery(iFrameWindow.document).unbind('keydown.overlay-event');
 
   // Change the overlay title.
-  $('.overlay .ui-dialog-title').html(Drupal.t('Please wait...'));
+  self.$dialog.find('.ui-dialog-title').html(Drupal.t('Please wait...'));
 
   // Hide the iframe element.
-  self.iframe.$element.fadeOut('fast');
+  self.$iframe.fadeOut('fast');
 };
 
 /**
@@ -600,7 +622,7 @@
   }
 
   return self.adminPathRegExp.exec(path) && !self.nonAdminPathRegExp.exec(path);
-}
+};
 
 /**
  * Sanitize dialog size.
@@ -625,28 +647,22 @@
   if (typeof size.width != 'number') {
     width = maxWidth;
   }
-  // Set to at least minWidth but at most maxWidth.
-  else if (size.width < minWidth || size.width > maxWidth) {
-    width = Math.min(maxWidth, Math.max(minWidth, size.width));
-  }
   else {
-    width = size.width;
+    // Set to at least minWidth but at most maxWidth.
+    width = Math.min(maxWidth, Math.max(minWidth, size.width));
   }
 
-  // Use 100px as the minimum height. Expand to 92% of the window if height
-  // was invalid, to ensure that we have a reasonable chance to show content.
-  var minHeight = 100, maxHeight = parseInt($window.height() * .92);
+  // Use 100px as the minimum height.
+  var minHeight = 100;
   if (typeof size.height != 'number') {
-    height = maxHeight;
-  }
-  else if (size.height < minHeight) {
-    // Do not consider maxHeight as the actual maximum height, since we rely on
-    // the parent window scroll bar to scroll the window. Only set up to be at
-    // least the minimal height.
-    height = Math.max(minHeight, size.height);
+    // Expand to 92% of the window if height was invalid, to ensure that we have
+    // a reasonable chance to show content.
+    height = parseInt($window.height() * .92);
   }
   else {
-    height = size.height;
+    // Do not consider a maximum height, since we rely on the parent window scroll
+    // bar to scroll the window. Only set up to be at least the minimal height.
+    height = Math.max(minHeight, size.height);
   }
   return { width: width, height: height };
 };
@@ -683,33 +699,32 @@
   var self = this;
 
   // Compute frame and dialog size based on requested document size.
-  var titleBarHeight = $('.overlay .ui-dialog-titlebar').outerHeight(true);
+  var titleBarHeight = self.$dialog.find('.ui-dialog-titlebar').outerHeight(true);
   var frameSize = self.sanitizeSize(size);
   var dialogSize = $.extend({}, frameSize);
   dialogSize.height += titleBarHeight + 15;
 
   // Compute position on viewport.
-  var dialogPosition = self.computePosition($('.overlay'), dialogSize);
+  var dialogPosition = self.computePosition(self.$dialog, dialogSize);
 
   var animationOptions = $.extend(dialogSize, dialogPosition);
 
   // Perform the resize animation.
-  $('.overlay').animate(animationOptions, 'fast', function () {
+  self.$dialog.animate(animationOptions, 'fast', function () {
     // Proceed only if the dialog still exists.
-    if ($.isObject(self.iframe.$element) && $.isObject(self.iframe.$container)) {
+    if ($.isObject(self.$iframe) && $.isObject(self.$container)) {
       // Resize the iframe element and container.
-      $('.overlay').width(dialogSize.width).height(dialogSize.height);
-      self.iframe.$container.width(frameSize.width).height(frameSize.height);
-      self.iframe.$element.width(frameSize.width).height(frameSize.height);
+      self.$container.width(frameSize.width).height(frameSize.height);
+      self.$iframe.width(frameSize.width).height(frameSize.height);
 
       // Update the dialog size so that UI internals are aware of the change.
-      self.iframe.$container.dialog('option', { width: dialogSize.width, height: dialogSize.height });
+      self.$container.dialog('option', { width: dialogSize.width, height: dialogSize.height });
 
       // Keep the dim background grow or shrink with the dialog.
-      $('.ui-widget-overlay').height($(document).height());
-
-      // Animate body opacity, so we fade in the page as it loads in.
-      $(self.iframe.$element.get(0)).contents().find('body.overlay').animate({opacity: 0.9999}, 'slow');
+      // The width needs to be updated when the height change resulted in a scrollbar.
+      $('.ui-widget-overlay')
+        .height($(document).height())
+        .width($('body').outerWidth());
     }
   });
 };
@@ -796,9 +811,12 @@
 
   // Determine the link's original destination, and make it relative to the
   // Drupal site.
-  var fullpath = link.pathname;
-  var re = new RegExp('^' + Drupal.settings.basePath);
-  var path = fullpath.replace(re, '');
+  var path = link.pathname;
+  // Ensure a leading slash on the path, omitted in some browsers.
+  if (path.substr(0, 1) != '/') {
+    path = '/' + path;
+  }
+  path = path.replace(new RegExp(Drupal.settings.basePath), '');
   // Preserve existing query and fragment parameters in the URL.
   var fragment = link.hash;
   var querystring = link.search;
@@ -815,7 +833,7 @@
   // Assemble the overlay-ready link.
   var base = window.location.href;
   return $.param.fragment(base, {'overlay':destination});
-}
+};
 
 /**
  * Make sure the internal overlay URL is reflected in the parent URL fragment.
@@ -882,7 +900,7 @@
  */
 Drupal.theme.prototype.overlayContainer = function () {
   return '<div id="overlay-container"/>';
-}
+};
 
 /**
  * Theme function for the overlay title markup.
