Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1052
diff -u -r1.1052 common.inc
--- includes/common.inc	26 Nov 2009 05:54:48 -0000	1.1052
+++ includes/common.inc	29 Nov 2009 23:07:02 -0000
@@ -3069,7 +3069,7 @@
  * which on normal pages is up through the preprocess step of theme('html').
  * Adding a link will overwrite a prior link with the exact same 'rel' and
  * 'href' attributes.
- * 
+ *
  * @param $attributes
  *   Associative array of element attributes including 'href' and 'rel'.
  * @param $header
@@ -3285,7 +3285,7 @@
     ),
   );
   $rendered_css = array();
-  $inline_css = '';
+  $inline_css = array();
   $external_css = '';
   $preprocess_items = array();
   foreach ($css as $data => $item) {
@@ -3309,7 +3309,7 @@
         break;
       case 'inline':
         // Include inline stylesheets.
-        $inline_css .= drupal_load_stylesheet_content($item['data'], $item['preprocess']);
+        $inline_css[$item['media']] .= drupal_load_stylesheet_content($item['data'], $item['preprocess']);
         break;
       case 'external':
         // Preprocessing for external CSS files is ignored.
@@ -3333,16 +3333,20 @@
     }
   }
   // Enclose the inline CSS with the style tag if required.
-  if (!empty($inline_css)) {
+  foreach ($inline_css as $media => $items) {
     $element = $css_element;
     $element['#tag'] = 'style';
     $element['#value'] = $inline_css;
     unset($element['#attributes']['rel']);
-    $inline_css = "\n" . theme('html_tag', array('element' => $element));
+    // Skip media attribute when set to "all".
+    if ($media != 'all') {
+      $element['#attributes']['media'] = $media;
+    }
+    $inline_css[$media] = "\n" . theme('html_tag', array('element' => $element));
   }
 
   // Output all the CSS files with the inline stylesheets showing up last.
-  return implode($rendered_css) . $external_css . $inline_css;
+  return implode($rendered_css) . $external_css . implode($inline_css);
 }
 
 /**
@@ -3475,7 +3479,7 @@
     $contents = preg_replace('{
       (?<=\\\\\*/)([^/\*]+/\*)([^\*/]+\*/)  # Add a backslash also at the end ie-mac hack comment, so the next pass will not touch it.
                                             # The added backshlash does not affect the effectiveness of the hack.
-      }x', '\1\\\\\2', $contents);    
+      }x', '\1\\\\\2', $contents);
     $contents = preg_replace('<
       \s*([@{}:;,]|\)\s|\s\()\s* |          # Remove whitespace around separators, but keep space around parentheses.
       /\*[^*\\\\]*\*+([^/*][^*]*\*+)*/ |    # Remove comments that are not CSS hacks.
