diff --git a/includes/common.inc b/includes/common.inc
index 1454cf0..4f11231 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -1,5 +1,5 @@
 <?php
-// $Id: common.inc,v 1.980 2009-08-31 17:05:33 dries Exp $
+// $Id: common.inc,v 1.981 2009/08/31 18:43:12 webchick Exp $
 
 /**
  * @file
@@ -3177,14 +3177,21 @@ function drupal_get_js($scope = 'header', $javascript = NULL) {
 }
 
 /**
- * Adds all the attached libraries, JavaScript and CSS to the page.
- *
- * @param $libraries
- *   An array of depending libraries to be added.
- * @param $js
- *   An array of JavaScript components to add.
- * @param $css
- *   An array of cascading stylesheets to add.
+ * Adds all the attached libraries, JavaScript, CSS and other types of custom
+ * attachments to the page.
+ *
+ * @param $attachments
+ *   An array of attachments to be added to the page. Each item in the array is
+ *   an array of attachments, keyed with the type of the attachment.
+ *   Attachment types include:
+ *   - 'library'
+ *     An array of depending libraries to be added.
+ *   - 'js'
+ *     An array of JavaScript components to add.
+ *   - 'css'
+ *     An array of cascading stylesheets to add.
+ *  Besides these types, any custom type may be specified, for example
+ *  'dialogs'. 
  * @param $weight
  *   The default weight of JavaScript and CSS being added. This is only applied
  *   to the stylesheets and JavaScript items that don't have an explicit weight
@@ -3199,10 +3206,16 @@ function drupal_get_js($scope = 'header', $javascript = NULL) {
  *
  * @see drupal_add_library(), drupal_render()
  */
-function drupal_process_attached(array $libraries = array(), array $js = array(), array $css = array(), $weight = JS_DEFAULT, $dependency_check = FALSE) {
+function drupal_process_attached(array $attachments = array(), $weight = JS_DEFAULT, $dependency_check = FALSE) {
+  $attachments += array(
+    'library' => array(),
+    'js' => array(),
+    'css' => array(),
+  );
+  
   // Add the libraries first.
   $success = TRUE;
-  foreach ($libraries as $library) {
+  foreach ($attachments['library'] as $library) {
     if (drupal_add_library($library[0], $library[1]) === FALSE) {
       $success = FALSE;
       // Exit if the dependency is missing.
@@ -3213,7 +3226,7 @@ function drupal_process_attached(array $libraries = array(), array $js = array()
   }
 
   // Add both the JavaScript and the CSS.
-  foreach (array('js' => $js, 'css' => $css) as $type => $items) {
+  foreach (array('js' => $attachments['js'], 'css' => $attachments['css']) as $type => $items) {
     foreach ($items as $data => $options) {
       // If the value is not an array, it's a filename and passed as first
       // (and only) argument.
@@ -3234,6 +3247,13 @@ function drupal_process_attached(array $libraries = array(), array $js = array()
       call_user_func('drupal_add_' . $type, $data, $options);
     }
   }
+
+  // Attach other types of attachments specified in the reder() structure.
+  $types = array_diff(array_keys($attachments), array('library', 'css', 'js'));
+  foreach ($types as $type) {
+    call_user_func_array('drupal_add_'. $type, $attachments[$type]);
+  }
+  
   return $success;
 }
 
@@ -3266,7 +3286,12 @@ function drupal_add_library($module, $name) {
   if (!isset($added[$module][$name])) {
     if ($library = drupal_get_library($module, $name)) {
       // Add all components within the library.
-      $added[$module][$name] = drupal_process_attached($library['dependencies'], $library['js'], $library['css'], JS_LIBRARY, TRUE);
+      $attachments = array(
+        'library' => $library['dependencies'],
+        'js' => $library['js'],
+        'css' => $library['css'],
+      );
+      $added[$module][$name] = drupal_process_attached($attachments, JS_LIBRARY, TRUE);
     }
     else {
       // Requested library does not exist.
@@ -4115,12 +4140,15 @@ function drupal_render(&$elements) {
     }
   }
 
-  // Add additional libraries, CSS and JavaScript associated with this element.
-  drupal_process_attached(
-    isset($elements['#attached_library']) ? $elements['#attached_library'] : array(),
-    isset($elements['#attached_js']) ? $elements['#attached_js'] : array(),
-    isset($elements['#attached_css']) ? $elements['#attached_css'] : array()
-  );
+  // Add additional libraries, CSS, JavaScript an other custom
+  // attachment associated with this element.
+  $attached = element_attached($elements);
+  $attachments = array();
+  foreach ($attached as $key)  {
+    $type = str_replace('#attached_', '', $key);
+    $attachments[$type] = $elements[$key];
+  }
+  drupal_process_attached($attachments);
 
   $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : '';
   $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : '';
@@ -4226,12 +4254,15 @@ function drupal_render_cache_get($elements) {
   $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
 
   if (!empty($cid) && $cache = cache_get($cid, $bin)) {
-    // Add additional libraries, CSS and JavaScript associated with this element.
-    drupal_process_attached(
-      isset($cache->data['#attached_library']) ? $cache->data['#attached_library'] : array(),
-      isset($cache->data['#attached_js']) ? $cache->data['#attached_js'] : array(),
-      isset($cache->data['#attached_css']) ? $cache->data['#attached_css'] : array()
-    );
+    // Add additional libraries, CSS and JavaScript an other custom
+    // attachment associated with this elementassociated with this element.
+    $attached = element_attached($cache->data);
+    $attachments = array();
+    foreach ($attached as $key)  {
+      $type = str_replace('#attached_', '', $key);
+      $attachments[$type] = $cache->data[$key];
+    }
+    drupal_process_attached($attachments);
     // Return the rendered output.
     return $cache->data['#markup'];;
   }
@@ -4409,6 +4440,21 @@ function element_property($key) {
 }
 
 /**
+ * Check if the key is an attachment.
+ */
+function element_attachment($key) {
+  return strpos($key, '#attached_') === 0;
+}
+
+/**
+ * Get attachments of a structured array element. Attachments begin with
+ * '#attached_'.
+ */
+function element_attached($element) {
+  return array_filter(array_keys((array) $element), 'element_attachment');
+}
+
+/**
  * Get properties of a structured array element. Properties begin with '#'.
  */
 function element_properties($element) {
@@ -4479,8 +4525,6 @@ function drupal_common_theme() {
     'maintenance_page' => array(
       'arguments' => array('content' => NULL, 'show_messages' => TRUE),
       'template' => 'maintenance-page',
-      'path' => 'includes',
-      'file' => 'theme.maintenance.inc',
     ),
     'update_page' => array(
       'arguments' => array('content' => NULL, 'show_messages' => TRUE),
@@ -5411,3 +5455,37 @@ function xmlrpc($url) {
   return call_user_func_array('_xmlrpc', $args);
 }
 
+/**
+ * Adds a dialog using jQuery UI.
+ *
+ * @param $options
+ *   An array of options, with following keys:
+ *   - trigger_selector
+ *     A jQuery selector which should open a dialog when clicked.
+ *     Example: 'a#modal-link'
+ *   - content_selector
+ *     A jQuery selector which contains the content for display in the dialog.
+ *  -  options
+ *     An array of dialog options keyed by option name.
+ *     See http://docs.jquery.com/UI/Dialog#options for available options.
+ */
+function drupal_add_dialog(array $options = array()) {
+	kpr($options);
+  $dialogs = &drupal_static(__FUNCTION__, array());
+  if (!count($dialogs)) {
+    drupal_add_library('system', 'ui.dialog');
+    drupal_add_library('system', 'ui.draggable');
+    drupal_add_library('system', 'ui.resizable');
+    drupal_add_js('misc/dialog.js');
+  }
+  $trigger_selector = $options['trigger_selector'];
+  if (!isset($dialogs[$trigger_selector])) {
+    $dialogs[$trigger_selector] = array(
+      'content_selector' => $options['content_selector'],
+      'options' => $options['options'],
+    );
+
+    drupal_add_js(array('dialogs' => $dialogs), 'setting');
+  }
+  return $dialogs;
+}
diff --git a/modules/filter/filter.admin.inc b/modules/filter/filter.admin.inc
index 92b3cd1..7780e89 100644
--- a/modules/filter/filter.admin.inc
+++ b/modules/filter/filter.admin.inc
@@ -1,5 +1,5 @@
 <?php
-// $Id: filter.admin.inc,v 1.42 2009-08-28 16:23:04 dries Exp $
+// $Id: filter.admin.inc,v 1.42 2009/08/28 16:23:04 dries Exp $
 
 /**
  * @file
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index 6ab8245..9577ffc 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -1,5 +1,5 @@
 <?php
-// $Id: filter.module,v 1.287 2009-08-30 06:04:09 dries Exp $
+// $Id: filter.module,v 1.287 2009/08/30 06:04:09 dries Exp $
 
 /**
  * @file
@@ -57,9 +57,6 @@ function filter_theme() {
       'arguments' => array('tips' => NULL, 'long' => FALSE),
       'file' => 'filter.pages.inc',
     ),
-    'filter_tips_more_info' => array(
-      'arguments' => array(),
-    ),
     'filter_guidelines' => array(
       'arguments' => array('format' => NULL),
     ),
@@ -635,10 +632,18 @@ function filter_form($selected_format = FILTER_FORMAT_DEFAULT, $weight = NULL, $
   );
   $form['format_help'] = array(
     '#prefix' => '<div id="' . $element_id . '-help" class="filter-help">',
-    '#markup' => theme('filter_tips_more_info'),
+    '#attached_dialog' => array(array(
+       'trigger_selector' => ".filter-tips-modal",
+       'content_selector' => "#filter-tips-modal-dialog",
+       'options' => array(
+         'width' => 600,
+         'height' => 500,
+        ),
+    )),
     '#suffix' => '</div>',
     '#weight' => 1,
   );
+  $form['format_help'] = array_merge($form['format_help'], filter_tips_more_info());
 
   return $form;
 }
@@ -736,12 +741,16 @@ function filter_dom_serialize($dom_document) {
 }
 
 /**
- * Format a link to the more extensive filter tips.
- *
- * @ingroup themeable
+ * Build a render() array which links to the more extensive filter tips.
  */
-function theme_filter_tips_more_info() {
-  return '<p>' . l(t('More information about text formats'), 'filter/tips') . '</p>';
+function filter_tips_more_info() {
+  $build['more'] = array('#markup' => l(t('More information about text formats'), 'filter/tips', array('attributes' => array('class' => 'filter-tips-modal'))));
+  $build['long'] = array(
+    '#prefix' => '<div id="filter-tips-modal-dialog" class="ui-helper-hidden" title="' . t('Filter Tips') . '">',
+    '#markup' => filter_tips_long(),
+    '#suffix' => '</div>',
+  );
+  return $build;
 }
 
 /**
diff --git a/modules/filter/filter.pages.inc b/modules/filter/filter.pages.inc
index 5d76af4..a2b2f0d 100644
--- a/modules/filter/filter.pages.inc
+++ b/modules/filter/filter.pages.inc
@@ -1,5 +1,5 @@
 <?php
-// $Id: filter.pages.inc,v 1.7 2009-03-08 21:25:18 dries Exp $
+// $Id: filter.pages.inc,v 1.7 2009/03/08 21:25:18 dries Exp $
 
 /**
  * @file
@@ -11,14 +11,7 @@
  * Menu callback; show a page with long filter tips.
  */
 function filter_tips_long() {
-  $format = arg(2);
-  if ($format) {
-    $output = theme('filter_tips', _filter_tips($format, TRUE), TRUE);
-  }
-  else {
-    $output = theme('filter_tips', _filter_tips(-1, TRUE), TRUE);
-  }
-  return $output;
+  return theme('filter_tips', _filter_tips(-1, TRUE), TRUE);
 }
 
 
