<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -8,28 +8,67 @@ Drupal.behaviors.style = function(context) {
   });
 
 
-  function replaceStylesheet(oldStylesheet, newStylesheet) {
-    $('link[@href*=/drupal6/themes/cleanstate/styles/]').each(function(i) {
-      //console.log(style_name);
-      //style_file = &quot;/drupal6/themes/cleanstate/styles/&quot; + style_name + &quot;/cleanstate.css&quot;;
-      style_file = &quot;/drupal6/&quot; + newStylesheet + &quot;/cleanstate.css&quot;;
+  function replaceStylesheet(oldStylesheetDir, newStylesheetDir) {
+    
+    
+    $('link[@href*=' + Drupal.settings.basePath + Drupal.settings.style.local_dir + ']').each(function(i) {
+      style_file = Drupal.settings.basePath + newStylesheetDir + &quot;/&quot; + Drupal.settings.style.theme_name + &quot;.css&quot;;
       $(this).attr({href : style_file});
+        $.preloadCssImages();
+    });
+    
+    $('link[@href*=' + Drupal.settings.basePath + Drupal.settings.style.files_dir + ']').each(function(i) {
+      style_file = Drupal.settings.basePath + newStylesheetDir + &quot;/&quot; + Drupal.settings.style.theme_name + &quot;.css&quot;;
+      $(this).attr({href : style_file});
+        $.preloadCssImages();
     });
 
   }
 
   function pickRandom() {
-    styles = new Array('fire','bubbles','forest', 'space');
-    style_name = styles[Math.floor(Math.random()*styles.length)];
-  }
+      styles = new Array('fire','bubbles','forest', 'space');
+   
+      style_name = styles[Math.floor(Math.random()*styles.length)];
+  } 
 
-  $('#edit-theme-cleanstate-style').change(function() {
-    // console.log(this);
-    var skin = this.options[this.selectedIndex].value;
-
-    // console.log(skin);
+  $('#edit-theme-' + Drupal.settings.style.theme_name + '-style').change(function() {
+    //console.log(this);
+     var skin = this.options[this.selectedIndex].value;
+    //console.log(skin); 
     replaceStylesheet('moo', skin);
-    //console.log(Drupal.settings.basePath);
-  });
+    
+    console.log(pathinfo(skin));
+    console.log(Drupal.settings.basePath); 
+  });    //console.log(this);
+     
+     
+  function pathinfo(path, options)
+  {
+    var re = /(([^\\/]*?)(?:\.([^.]*))?)$/;
+    var re2 = /(.*)[\\/]/;
+    
+    var path_arr = re.exec(path);
+    var dir_arr = re2.exec(path);
+    
+    // To be PHP compatible, no directory becomes &quot;.&quot;
+    if (dir_arr == null || dir_arr == &quot;&quot;) dir_arr = [&quot;&quot;,&quot;.&quot;];
+    
+    var path_obj = {dirname:dir_arr[1],basename:path_arr[0],extension:path_arr[3],filename:path_arr[2]};
+    
+    if (typeof options == &quot;undefined&quot;) {
+      if (path_obj.extension == &quot;&quot; &amp;&amp; path_obj.filename.slice(-1) != &quot;.&quot;) {
+        // To be PHP compatible, if there is no dot (.) in the name, the extension value is not set.
+        delete path_obj.extension;
+      }
+      return path_obj;
+    } else {
+      switch (options) {
+        case &quot;PATHINFO_DIRNAME&quot;: return path_obj.dirname;
+        case &quot;PATHINFO_BASENAME&quot;: return path_obj.basename;
+        case &quot;PATHINFO_EXTENSION&quot;: return path_obj.extension;
+        case &quot;PATHINFO_FILENAME&quot;: return path_obj.filename;
+      }
+    }
+  }
 
 };</diff>
      <filename>style.js</filename>
    </modified>
    <modified>
      <diff>@@ -45,8 +45,24 @@ function style_styles_exist($style_dir, $refresh = FALSE) {
   }
 }
 
+function style_scan_styles2($theme_name) {
+  $files_dir = style_get_files_skin_dir($theme_name);
+  $local_dir = style_get_local_skin_dir($theme_name);
+    
+  $styles = array();
+  drupal_set_message(&quot;files {$files_dir} | local: {$local_dir}&quot;); 
+ 
+  if (is_dir($files_dir) &amp;&amp; style_styles_exist($files_dir)) {
+     $styles += style_file_tree($files_dir);
+  }
+  if (is_dir($local_dir) &amp;&amp; style_styles_exist($local_dir)) {
+    $styles += style_file_tree($local_dir);
+  }
+  return $styles;
+}
+
 /**
- *  Scan for style folders in style directory
+ *  Scans for directories, not recursive.
  *
  *  @param string $dir
  *    Directory of the theme or module styles
@@ -86,24 +102,28 @@ function style_scan_styles($dir, $refresh = FALSE) {
 }
 
 /**
- *  Scan for styles.
+ *  Return files in an array tree. :D
  *
  *  @param string $dir
  *    Directory of style
  *  @param boolean $refresh
  *    Bypass cache
  *  @return array
- *    Recursive output of files.
+ *    Recursive tree of files.
  */
-function style_scan_style_files($dir, $refresh = FALSE) {
+function style_file_tree($dir, $refresh = FALSE) {
   static $style;
 
+  if (!is_dir($dir)) {
+    drupal_set_message(&quot;{$dir} is not a directory&quot;);
+  }
+
   // Caching, can be bypassed with $refresh
   if (isset($style[$dir]) &amp;&amp; $refresh !== TRUE) {
     return $style[$dir];
   }
 
-  $style[$dir] = _style_scan_style_files($dir);
+  $style[$dir] = _style_file_tree($dir);
   return $style[$dir];
 }
 
@@ -117,7 +137,7 @@ function style_scan_style_files($dir, $refresh = FALSE) {
  *  @return array
  *    Recursive output of files.
  */
-function _style_scan_style_files($dir, $show_files = TRUE) {
+function _style_file_tree($dir, $show_files = TRUE) {
   $d = dir($dir); $x = array();
   while (($r = $d-&gt;read()) !== FALSE) {
     if ($r != &quot;.&quot; &amp;&amp; $r != &quot;..&quot; &amp;&amp; (($show_files == FALSE &amp;&amp; is_dir($dir.$r)) || $show_files == TRUE)) {
@@ -128,7 +148,7 @@ function _style_scan_style_files($dir, $show_files = TRUE) {
   foreach ($x as $key =&gt; $value) {
     if (is_dir($dir.$key.&quot;/&quot;)) {
       // Move recursively into directories
-      $x[$key] = _style_scan_style_files($dir.$key.&quot;/&quot;, $show_files);
+      $x[$key] = _style_file_tree($dir.$key.&quot;/&quot;, $show_files);
     }
   }
   ksort($x);
@@ -143,7 +163,7 @@ function _style_scan_style_files($dir, $show_files = TRUE) {
  *  @return array
  *    Formatted as array[full_path + /styledir] = stylename
  */
-function style_list_styles($directory, $files = FALSE) {
+function style_dirs($directory, $files = FALSE) {
   // If styles exists in the directory
   // First by seeing if styles dir itself exists
   // Then by seeing if individual styles are present in dir
@@ -204,7 +224,7 @@ function style_settings_page() {
                         /files/themes/themename/styles.'),
     );
   foreach	($themes as $theme) {
-    $style_info = style_list_styles('theme', $theme);
+    $style_info = style_dirs('theme', $theme);
 
     $style_list = $style_info['list'];
 
@@ -232,12 +252,27 @@ function style_settings_page() {
   return system_settings_form($form);
 }
 
+/**
+ *  Inject pertinent style variables for current theme into Drupal.settings.style
+ *  scope.
+ *
+ */
+function style_create_js_vars($theme_key) {
+  
+   $styles = style_scan_styles2($theme_key);
+   drupal_add_js(array('style' =&gt; array('styles' =&gt; $styles)), 'setting');
+   
+}
+
 function style_preprocess_page(&amp;$vars) {
   // Our variables from Drupal's global scope
   global $theme_key, $theme_info, $base_url;
 
   // Get our theme directory
   $theme_dir = theme_get_setting('theme_'.$theme_key.'_style');
+  
+  $local_dir = style_get_local_skin_dir($theme_key);
+  $files_dir = style_get_files_skin_dir($theme_key);
 
   // Does the directory exist?
   if (dir($theme_dir)) {
@@ -250,13 +285,12 @@ function style_preprocess_page(&amp;$vars) {
     }
   
     // Grab the CSS files from our style.
-    $newcss = style_scan_style_files($theme_dir);
+    $newcss = style_file_tree($theme_dir);
 
     // Create an array for new styles
     $new_styles = array();
     foreach (array_keys($newcss) as $css) {
-      $new_styles[] = $theme_dir . '/' . $css;
-    }
+      $new_styles[] = $theme_dir . '/' . $css;    }
     $color_paths = $new_styles;
   }
                                                                     ///
@@ -309,7 +343,21 @@ function style_preprocess_page(&amp;$vars) {
   if (file_exists(theme_get_setting('theme_'.$theme_key.'_style') . '/logo.png')) {
     $vars['logo'] = $base_url . '/' . theme_get_setting('theme_'.$theme_key.'_style') . '/logo.png';
   }
+  
+}
+
 
+function style_get_local_skin_dir($theme_name) {
+  $local_dir = drupal_get_path('theme', $theme_name)  . '/styles/';
+  
+  return $local_dir;
+  
+}
+
+function style_get_files_skin_dir($theme_name) {
+  $files_dir = file_directory_path() . '/' . drupal_get_path('theme', $theme_name) . '/styles/';
+  
+  return $files_dir;
 }
 
 /**
@@ -332,15 +380,15 @@ function style_form_alter(&amp;$form, $form_state, $form_id) {
       $theme_name = arg(4);
 
       // Get the directories we want to scan for files in.
-      $local_dir = drupal_get_path('theme', $theme_name)  . '/styles/';
-      $files_dir = file_directory_path() . '/' . drupal_get_path('theme', $theme_name) . '/styles/';
+      $local_dir = style_get_local_skin_dir($theme_name);
+      $files_dir = style_get_files_skin_dir($theme_name);
 
       $style_list = array();
       // Grab various information about styles.
-      if (count($style_list_local = style_list_styles($local_dir)) &gt; 0) {
+      if (count($style_list_local = style_dirs($local_dir)) &gt; 0) {
         $style_list += $style_list_local;
       }
-      if (count($style_list_files = style_list_styles($files_dir, TRUE)) &gt; 0) {
+      if (count($style_list_files = style_dirs($files_dir, TRUE)) &gt; 0) {
         $style_list += $style_list_files;
       }
 
@@ -350,9 +398,15 @@ function style_form_alter(&amp;$form, $form_state, $form_id) {
 
         // Add our stylesheet to tighten things up
         drupal_add_css(drupal_get_path('module', 'style') .'/style.form.css', 'module', 'all', TRUE);
+        
+        drupal_add_js(drupal_get_path('module', 'style') . '/preloadCssImages.jQuery_v5.js');
         drupal_add_js(drupal_get_path('module', 'style') . '/style.js');
-
-
+        
+        // Add our theme's style roots to Drupal.Settings JS variable scope
+        drupal_add_js(array('style' =&gt; array('local_dir' =&gt; $local_dir, 'files_dir' =&gt; $files_dir, 'theme_name' =&gt; $theme_name), ), 'setting');
+ 
+        style_create_js_vars($theme_name);
+ 
         // Does $form['style'] already exist?
         if (!isset($form['style'])) {
           $form['style'] = array();</diff>
      <filename>style.module</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d96c9ae309e76aa0e4c9f12116a860b7deea4950</id>
    </parent>
  </parents>
  <author>
    <name>Tony Narlock</name>
    <email>kiwi@kiwi.(none)</email>
  </author>
  <url>http://github.com/skiquel/drupal-style/commit/0913d41293faf047f55fe4ab2c80487726c9322b</url>
  <id>0913d41293faf047f55fe4ab2c80487726c9322b</id>
  <committed-date>2009-03-04T11:09:25-08:00</committed-date>
  <authored-date>2009-03-04T11:09:25-08:00</authored-date>
  <message>tweaking module and javascript :D</message>
  <tree>492612468e2bb6669210e4b28d7a700a8b14f967</tree>
  <committer>
    <name>Tony Narlock</name>
    <email>kiwi@kiwi.(none)</email>
  </committer>
</commit>
