treeview async persist problem

treeview async persist problem

i'm using the treeview async together with php and everything works good. however, i'm having problems getting the tree to stay expanded with the help of the option "persist: location"
 
the current page is always in this format: a.php?page=NNNN where NNNN is replaced by the ContentId.
 
i've tried to modify the "case: location" method in the .js file, but still without success. whatever i do, the tree is reloaded, but stays collapsed until i manually expand some branch. the php to retrieve the tree looks like this:
 
  1.   function getLeftMenu($page, $parent, $count, $lang, $team) {
      $page = mysql_real_escape_string($page);
      if ($page == "source") {
       $page = intval($_GET['page']);
       $page = mysql_real_escape_string($page);
      }
      $lang = mysql_real_escape_string($lang);
      $counter = $count++;







  2.  
      if ($page != "") {
       $childItems = mysql_query("SELECT DISTINCT ContentId, Title, ParentId, Status
       FROM tableA
       WHERE ParentId = '".$page."'");
       if (!$childItems) { die(mysql_error()); }
       $array_count = mysql_num_rows($childItems);
       }






  3.    if ($array_count == 0) {
        $dNode = $this->getTop($page, $parent, $team, "0", $lang);
       }


  4.     while ($theRow = mysql_fetch_array($childItems)) {
  5.       // CODE TO GET DATA AND JSON ENCODE IT     
        }
       }


  6.   if (isset($theRow)) {
       return $theRow;
      }
      else {
       return false;
      }
     }






  7.  function getTop($page, $parent, $team, $count, $lang) {
      $counter = $count;
      $childItems = mysql_query("SELECT DISTINCT ContentId, Title, ParentId, Status
       FROM tableA
       WHERE ParentId = '".$page."'");
      while ($row = mysql_fetch_array($childItems)) {
       if ($parent == $row["ParentId"]) {
        $childItems = mysql_query("SELECT DISTINCT ContentId, Title, ParentId, Status
       FROM tableA
       WHERE ContentId = '".$page."'");
        while ($row = mysql_fetch_array($childItems)) {
         $parent = $row["ParentId"];
         $ps = $row["ContentId"];
         if ($counter == 0) {
         $current = $row["ContentId"];
         }
        }
       }
      }
      $counter++;
      if ($parent != "-1") {
       if ($counter < 8) {
       $this->getTop($page, $parent, $team, $counter, $lang);
       }
       else {
       return "error";
       }
      }
      else {
       $this->getLeftMenu($ps, $parent, $counter, $lang, $team);
      }





























  8.  }
everytime the page is reloaded, root equals "source". how can i initiate the source and then followed by root=NNNN ? perhaps i should be looking at the js rather than the php? can anyone please help?