Index: advanced_forum.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/advanced_forum/advanced_forum.module,v
retrieving revision 1.21.2.57
diff -u -r1.21.2.57 advanced_forum.module
--- advanced_forum.module	16 Sep 2008 21:05:28 -0000	1.21.2.57
+++ advanced_forum.module	17 Sep 2008 04:59:46 -0000
@@ -19,6 +19,7 @@
     drupal_add_css("$style_directory/advanced_forum.css" );
     _advanced_forum_load_preprocessors();
     drupal_add_js(drupal_get_path('module', 'advanced_forum') . '/advanced_forum.js');
+    drupal_add_js(array('advf_ajax' => url('advf/collapse')), 'setting');
   }
 }
 
@@ -45,6 +46,11 @@
     'page callback' => 'drupal_get_form',
     'title' => 'Advanced Forum',
   );
+  $items['advf/collapse'] = array(
+    'access arguments' => array('access content'),
+    'page callback' => 'advanced_form_ajax',
+    'type' => MENU_CALLBACK,
+  );
   return $items;
 }
 
@@ -801,6 +807,55 @@
   return $forums;
 }
 
+// COLLAPSABLE CONTAINERS ****************************************************/
+
+/**
+ * Allows users with javascript enabled to collapse / expand containers.
+ */
+function advanced_form_ajax($op, $container_id = NULL) {
+  global $base_url;
+  $base_url = str_replace('.', '_', $base_url);
+  switch($op) {
+    case 'load':
+      if(!isset($_COOKIE[$base_url.'_advanced_forum'])) {
+        //Set defaults in the cookie.
+        $defaults = variable_get('advforum_collapse_defaults', '');
+        if($defaults != '') {
+          $initial_state = unserialize($defaults);
+        } 
+        else {
+          $initial_state = array();
+        }
+        setcookie($base_url.'_advanced_forum[tids]', serialize($initial_state), time()+60*60*24*30, '/');
+      }
+      else {
+        $initial_state = unserialize($_COOKIE[$base_url.'_advanced_forum']['tids']);
+      }
+      print drupal_json(array('tids' => $initial_state));
+      //print_r($_COOKIE);
+      break;
+    case 'toggle':
+      if(!$container_id)
+        exit;
+      if(!isset($_COOKIE[$base_url.'_advanced_forum'])) {
+        $defaults = variable_get('advforum_collapse_defaults', '');
+        if($defaults) {
+          $initial_state = unserialize($defaults);
+        } 
+        else {
+          $initial_state = array();
+        } 
+      }
+      else {
+        $initial_state = unserialize($_COOKIE[$base_url.'_advanced_forum']['tids']);
+      }
+      $initial_state[$container_id] = 1 - $initial_state[$container_id];
+      setcookie($base_url.'_advanced_forum[tids]', serialize($initial_state), time()+60*60*24*30, '/');
+      break;
+  }
+}
+
+
 
 // MARK AS READ **************************************************************/
 
Index: advanced_forum.install
===================================================================
RCS file: /cvs/drupal/contributions/modules/advanced_forum/advanced_forum.install,v
retrieving revision 1.1.2.9
diff -u -r1.1.2.9 advanced_forum.install
--- advanced_forum.install	31 Jul 2008 21:18:05 -0000	1.1.2.9
+++ advanced_forum.install	17 Sep 2008 04:59:45 -0000
@@ -10,6 +10,7 @@
   variable_del('advanced_forum_themedir');
   variable_del('advanced_forum_theme_all_comments');
   variable_del('advforum_topic_pager_max');
+  variable_del('advforum_collapse_defaults');
 }
 
 function advanced_forum_update_5000() {
Index: advanced_forum.js
===================================================================
RCS file: /cvs/drupal/contributions/modules/advanced_forum/advanced_forum.js,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 advanced_forum.js
--- advanced_forum.js	14 Sep 2008 13:43:45 -0000	1.1.2.3
+++ advanced_forum.js	17 Sep 2008 04:59:45 -0000
@@ -5,12 +5,20 @@
 function jq_collapse (container_id) {
 	$(document).ready(function(){
 		$('.in-container-' + container_id).toggle();
-  	if($.cookie('cookie_container-' + container_id) !== 'collapsed') {
-   	 $.cookie('cookie_container-' + container_id, 'collapsed');
-		}
-		else {
-			$.cookie('cookie_container-' + container_id, 'expanded');
-		}
+  	$.get(Drupal.settings.advf_ajax + '/toggle/' + container_id, null, function(data) {});
+  	
   return false;
 	});
-}
\ No newline at end of file
+}
+
+$(document).ready(function(){
+  $.getJSON(Drupal.settings.advf_ajax + '/load', function(data) {
+    $.each(data.tids, function(tid, hide){
+    if(hide) {
+      $('.in-container-' + tid).toggle();
+    }
+    });
+  });
+    
+  return false;
+});
\ No newline at end of file
Index: styles/naked/advf-forum-list.tpl.php
===================================================================
RCS file: /cvs/drupal/contributions/modules/advanced_forum/styles/naked/advf-forum-list.tpl.php,v
retrieving revision 1.1.2.10
diff -u -r1.1.2.10 advf-forum-list.tpl.php
--- styles/naked/advf-forum-list.tpl.php	16 Sep 2008 21:07:49 -0000	1.1.2.10
+++ styles/naked/advf-forum-list.tpl.php	17 Sep 2008 04:59:46 -0000
@@ -49,8 +49,7 @@
     <?php foreach ($forums as $child_id => $forum): ?>
     
         <?php if ($forum->is_container): ?>
-          <tr id="forum-list-<?php print $child_id; ?>" class="<?php print $forum->zebra; ?> <?php print $forum->row_position;?> container-<?php print $forum->container_id;?>" <?php print 'onclick="jq_collapse(\'' . $forum->container_id . '\', \'' . drupal_get_path('module', 'advanced_forum') . '\')"';?>
-          
+          <tr id="forum-list-<?php print $child_id; ?>" class="<?php print $forum->zebra; ?> <?php print $forum->row_position;?> container-<?php print $forum->container_id;?>" onclick="jq_collapse('<?php print $forum->container_id ?>')">
             <td colspan="5" class="container">   
               <div class="forum-details">  
                 <div class="name">
@@ -83,7 +82,7 @@
             </td>
         
             <td class="topics">
-              <div class="num num-topics"><?php print $forum->num_topics ?></div>
+              <div class="num num-topics"><?php print $forum->num_topics ?>
                 <?php if ($forum->new_topics): ?>
                   <div class="num num-new-topics"><a href="<?php print $forum->new_url; ?>"><?php print $forum->new_text; ?></a></div>
                 <?php endif; ?>
