position: relative;
 }
 
-h2.plc { 
-    text-align: center;
-}
-
-/* tmp - for visual checking */
-/*.plc-local {
-    border: 1px solid #00f; */
-}
 .plc-foreign {
     background:  #e0e0e0;
 }
 
                                         "Click the button in the D(etails) column to get more details")));
 $table->end();
   
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';
 
 $details->end();
 $form->end();
 
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
   // Print footer
 include 'plc_footer.php';
 
     // and add them to the 'values' argument if any
 
     // extract var=value settings from url if any
-    $split=split_url($full_url);
+    $split=plkit_split_url($full_url);
     $this->url=$split['url'];
     
     $url_values=$split['values'];
 
 function my_is_int ($x) {
     return (is_numeric($x) ? intval($x) == $x : false);
 }
+
+//// belongs to plkit
+// returns array ['url' => path, 'values' => hash (key=>value)* ]
+function plkit_split_url ($full_url) {
+  list($url,$args) = explode("?",$full_url);
+  $values=array();
+  if ($args) {
+    $pairs=explode("&",$args);
+    foreach ($pairs as $pair) {
+      list ($name,$value) = explode("=",$pair);
+      $values[$name]=$value;
+    }
+  }
+  return array("url"=>$url,"values"=>$values);
+}
+
+
+
 //////////////////////////////////////////////////////////// roles & other checks on global $plc
 function plc_is_admin () {
   global $plc;
 function l_person ($person_id)         { return "/db/persons/index.php?id=$person_id"; }
 function l_person_t ($person_id,$text) { return href (l_person($person_id),$text); }
 function l_persons_site ($site_id)     { return "/db/persons/index.php?site_id=$site_id"; }
+function l_person_obj ($person)                { return l_person_t($person['person_id'],$person['email']); }
 
 function l_tags ()                     { return "/db/tags/index.php"; }
 function l_tag ($tag_type_id)          { return "/db/tags/index.php?id=$tag_type_id"; }
 
 ////////////////////
 
-// returns array ['url' => path, 'values' => hash (key=>value)* ]
-function split_url ($full_url) {
-  list($url,$args) = explode("?",$full_url);
-  $values=array();
-  if ($args) {
-    $pairs=explode("&",$args);
-    foreach ($pairs as $pair) {
-      list ($name,$value) = explode("=",$pair);
-      $values[$name]=$value;
-    }
-  }
-  return array("url"=>$url,"values"=>$values);
-}
-
 //////////////////////////////////////////////////////////// validation functions
 function topdomain ($hostname) {
   $exploded=array_reverse(explode(".",$hostname));
   }
   return $hash;
 }
-  
 
 //////////////////////////////////////////////////////////// nodegroups
 // hash by 'tagname=value'
   return $formatted;
 }
 
-function plc_section ($text,$line=true) {
-  if ($line) { print "<hr/>";}
-  print "<h2 class=plc> $text </h2>\n";
-}
-
 function plc_error ($text) {
   // should use the same channel as the php errors..
   print "<div class='plc-error'> Error " . $text . "</div>";
 
     if ( ! $todo['method'] ) $todo['method']='GET';
     // extract var=value settings from url if any
     $full_url=$todo['url'];
-    $split=split_url($full_url);
+    $split=plkit_split_url($full_url);
     $url=$split['url'];
     $url_values=$split['values'];
 
 
   function trigger ()          { print $this->trigger_html(); }
   function trigger_html () {
     $trigger_id=$this->id_name('trigger');
-    $tagname='span';
     if (array_key_exists ('trigger-tagname',$this->options)) $tagname=$this->options['trigger-tagname'];
     if (array_key_exists ('trigger-bubble',$this->options)) $bubble=$this->options['trigger-bubble'];
+    if (empty($tagname)) $tagname="span";
     
     $html="<$tagname";
     $html .= " id=$trigger_id";
 
 require_once 'plc_minitabs.php';
 require_once 'plc_details.php';
 require_once 'plc_tables.php';
-require_once 'prototype.php';
+require_once 'plc_toggles.php';
 
 require_once 'plc_drupal.php';
 include 'plc_header.php';
 
 
 //////////////////////////////////////// tags
+$toggle=new PlcToggle ('tags','Tags',array('trigger-tagname'=>'h2'));
+$toggle->start();
+
 $form = new PlcForm (l_actions(),array('interface_id'=>$interface_id));
 $form->start();
 
 function get_tagname ($tag) { return $tag['tagname'];}
 $tagnames = array_map ("get_tagname",$tags);
   
-plc_section("Tags");
+
 $headers=array("Name"=>"string",
               "Value"=>"string",
               );
   
 $table->end();
 $form->end();
+$toggle->end();
 
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';
 
 ////////////////////////////////////////////////////////////
 $peers->block_end($peer_id);
 
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';
 
 
 $table->end();
 
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';
 
 $details->th_td("Number of slices",href(l_slices_peer($peer_id),"$nb slices"));
 $details->end();
 
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';
 
   $table->end();
  }
                    
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';
 
 require_once 'plc_tables.php';
 require_once 'plc_details.php';
 require_once 'plc_forms.php';
+require_once 'plc_toggles.php';
 
 // -------------------- 
 // recognized URL arguments
 $details->form_end();
 
 //////////////////// slices
-plc_section('Slices');
+$toggle=new PlcToggle ('slices','Slices',array('trigger-tagname'=>'h2'));
+$toggle->start();
 
 if( ! $slices) {
   plc_warning ("User has no slice");
   }
   $table->end();
  }
+$toggle->end();
 
 // we don't set 'action', but use the submit button name instead
 $form=new PlcForm(l_actions(), array("person_id"=>$person_id));
 $form->start();
 
 //////////////////// keys
-plc_section ("Keys");
+$toggle=new PlcToggle ('keys',"Keys",array('trigger-tagname'=>'h2'));
+$toggle->start();
                
 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
 if ( empty( $key_ids ) ) {
 }
 
 $table->end();
+$toggle->end();
 
 //////////////////// sites
-plc_section('Sites');
+$toggle=new PlcToggle('sites','Sites',array('trigger-tagname'=>'h2'));
+$toggle->start();
   
 if (empty( $sites ) ) {
   plc_warning('This user is not affiliated with a site !!');
   $table->row_end();
  }
 $table->end();
+$toggle->end();
 
 //////////////////// roles
-plc_section("Roles");
+$toggle=new PlcToggle ('roles','Roles',array('trigger-tagname'=>'h2'));
+$togle->start();
+
 if (! $roles) plc_warning ("This user has no role !");
 
 $can_manage_roles= ($local_peer && plc_is_admin());
   $table->row_end();
  }
 $table->end();
+$toggle->end();
 
 //////////////////////////////
 $form->end();
 $peers->block_end($peer_id);
   
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';
 
 // --------------------
 drupal_set_title($title);
 
-plc_tabs($tabs);
+//plc_tabs($tabs);
 
 if ( ! $persons ) {
   drupal_set_message ('No account found');
 $notes=array("The S column shows the number of slices for the given user");
 $table->end(array('notes'=>$notes));
 
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';
 
 require_once 'plc_tables.php';
 require_once 'plc_details.php';
 require_once 'plc_forms.php';
+require_once 'plc_toggles.php';
 
 // -------------------- 
 // recognized URL arguments
 
 ////////////////////
 // Get all columns as we focus on only one entry
-$sites= $api->GetSites( array($site_id));
+$sites = $api->GetSites( array($site_id));
 
 if (empty($sites)) {
   drupal_set_message ("Site " . $site_id . " not found");
 // extra privileges to admins, and (pi||tech) on this site
 $privileges = plc_is_admin () || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
   
-// get peer details
+// get peer 
 $peer_id= $site['peer_id'];
 $peers = new Peers ($api);
 
-$adress_ids= $site['address_ids'];
+$address_ids= $site['address_ids'];
 $pcu_ids= $site['pcu_ids'];
 $node_ids= $site['node_ids'];
 $person_ids= $site['person_ids'];
 
 $api->begin();
 // gets address info
-$api->GetAddresses( $adress_ids );
+$api->GetAddresses( $address_ids );
 
 // gets pcu info
 // GetPCUs is not accessible to the 'user' role
   
 }
 
+$has_disabled_persons = count ($disabled_persons) !=0;
+
 drupal_set_title("Details for site " . $sitename);
 $local_peer = ! $peer_id;
   
 $details->form_start(l_actions(),array('action'=>'update-site','site_id'=>$site_id));
 $details->th_td("Full name",$sitename,'name',array('width'=>50));
 $details->th_td("Abbreviated name",$abbreviated_name,'abbreviated_name',array('width'=>15));
-$details->th_td("URL",$site_url,'url',array('width'=>50));
+$details->th_td("URL",$site_url,'url',array('width'=>40));
 $details->th_td("Latitude",$site_lat,'latitude');
 $details->th_td("Longitude",$site_long,'longitude');
 
   $details->space();
   $details->th_td("Peer",$peers->peer_link($peer_id));
  }
+$details->end();
 
+//////////////////// mode details - for local object
 if ( $local_peer ) {
 
-  // Nodes
-  $details->space();
+  //////////////////// nodes
+  // xxx missing : would need to add columns on attached PCU name and port if avail
   $nb_boot = 0;
   if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++;
-  $node_label = $nb_boot . " boot / " .  count($nodes) . " total";
-  $details->th_td("# Nodes", href(l_nodes_site($site_id),$node_label));
-  function n_link ($n) { return l_node_t($n['node_id'],$n['hostname'] . " (" . $n['boot_state'] . ")");}
-  $nodes_label= plc_vertical_table(array_map ("n_link",$nodes));
-  $details->th_td ("Hostnames",$nodes_label);
-  $button=new PlcFormButton (l_node_add(),"add_node","Add node","POST");
-  $details->tr($button->html(),"right");
 
-  // Users
-  $details->space();
-  $user_label = count($person_ids) . " Total / " .
-    count ($pis) . " PIs / " .
-    count ($techs) . " Techs";
-  if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >=50)) 
-    $user_label = plc_warning_html ($user_label);
-  $details->th_td ("# Users",href(l_persons_site($site_id),$user_label));
-  function p_link ($p) { return l_person_t($p['person_id'],$p['email']); }
-  // PIs
-  $details->th_td("PI's",plc_vertical_table (array_map ("p_link",$pis)));
-  // techs
-  $details->th_td("Techs's",plc_vertical_table (array_map ("p_link",$techs)));
-  if (count ($disabled_persons)) 
-    $details->th_td("Disabled",plc_vertical_table (array_map ("p_link",$disabled_persons)));
-
-  // Slices
-  $details->space();
+  $nodes_title = "# Nodes : ";
+  $nodes_title .= count($nodes) . " total";
+  $nodes_title .= " / " . $nb_boot . " boot";
+  if ($nb_boot < 2 ) 
+    $nodes_title = plc_warning_html ($nodes_title);
+  $nodes_title .= href(l_nodes_site($site_id)," (See as nodes)");
+
+  $toggle=new PlcToggle ('nodes',$nodes_title,array('trigger-tagname'=>'h2'));
+  $toggle->start();
+
+  $headers=array();
+  $headers['hostname']='string';
+  $headers['state']='string';
+
+  $table = new PlcTable ('nodes',$headers,'0',array('search_area'=>false,
+                                                   'notes_area'=>false,
+                                                   'pagesize_area'=>false));
+  $table->start();
+  foreach ($nodes as $node) {
+    $table->row_start();
+    $table->cell (l_node_obj($node));
+    $table->cell ($node['boot_state']);
+    $table->row_end();
+  }
+  $table->tfoot_start();
+  $table->row_start();
+  $button=new PlcFormButton (l_node_add(),"node_add","Add node","POST");
+  $table->cell($button->html(),$table->columns(),"right");
+  $table->row_end();
+  $table->end();
+  $toggle->end();
+    
+  //////////////////// Users
+  $persons_title = "# Users : ";
+  $persons_title .= count($person_ids) . " total";
+  $persons_title .= " / " . count ($pis) . " PIs";
+  $persons_title .= " / " . count ($techs) . " Techs";
+  if ($has_disabled_persons) 
+    $persons_title .= " / " . ($disabled_persons) . " Disabled";
+  if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >= 30) || count($disabled_persons) != 0 ) 
+    $persons_title = plc_warning_html ($persons_title);
+  $persons_title .= href(l_persons_site($site_id)," (See as users)");
+
+  $toggle=new PlcToggle ('persons',$persons_title,array('trigger-tagname'=>'h2'));
+  $toggle->start();
+
+  $headers = array ();
+  $headers["email"]='string';
+  $headers["PI"]='string';
+  $headers['User']='string';
+  $headers["Tech"]='string';
+  if ($has_disabled_persons) $headers["Disabled"]='string';
+  $table=new PlcTable('persons',$headers,'1r-3r-0',array('search_area'=>false,
+                                                        'notes_area'=>false,
+                                                        'pagesize_area'=>false));
+  $table->start();
+  foreach ($persons as $person) {
+    $table->row_start();
+    $table->cell(l_person_obj($person));
+    $table->cell( in_array ('20',$person['role_ids']) ? "yes" : "no");
+    $table->cell( in_array ('30',$person['role_ids']) ? "yes" : "no");
+    $table->cell( in_array ('40',$person['role_ids']) ? "yes" : "no");
+    if ($has_disabled_persons) $table->cell( $person['enabled'] ? "no" : "yes");
+    $table->row_end();
+  }
+  $table->end();
+  $toggle->end();
+
+  //////////////////// Slices
+  // xxx to review after slices gets reworked
+  $toggle=new PlcToggle ('slices',"Slices",array('trigger-tagname'=>'h2'));
+  $toggle->start();
+  $details=new PlcDetails (false);
+  $details->start();
   // summary on slices
   $slice_label = count($slice_ids) . " running / " . $max_slices . " max";
   if (count($slice_ids) >= $max_slices) 
      $details->th_td($slice['instantiation'],l_slice_obj($slice));
   $button=new PlcFormButton (l_slice_add(),"slice_add","Add slice","POST");
   $details->tr($button->html(),"right");
+  $details->end();
+  $toggle->end();
 
   // Addresses
-  if ($addresses) {
-    $details->space();
+  $toggle=new PlcToggle ('addresses',"Addresses",array('trigger-tagname'=>'h2',
+                                                      'start-visible'=>false));
+  $toggle->start();
+  if ( ! $addresses) {
+    print "No known address for this site";
+  } else {
+    $details=new PlcDetails (false);
+    $details->start();
     $details->th_td("Addresses","");
     foreach ($addresses as $address) {
       $details->th_td(plc_vertical_table($address['address_types']),
                                                $address['postalcode'],
                                                $address['country'])));
     }
+    $details->end();
   }
+  $toggle->end();
 
  }
 
-$details->end();
-
 ////////////////////////////////////////
 $peers->block_end($peer_id);
 
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';
 
 
 $table->end(array('notes'=>$notes));
 
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';
 
 require_once 'plc_minitabs.php';
 require_once 'plc_tables.php';
 require_once 'plc_details.php';
+require_once 'plc_toggles.php';
 
 // -------------------- 
 // recognized URL arguments
 $details->end();
 
 // xxx : add & delete buttons would make sense here too
-plc_section("Nodes");
+$toggle=new PlcToggle('nodes',"Nodes",array('trigger-tagname'=>'h2'));
+$toggle=>start();
 
 $headers["Hostname"]="string";
 
 }
 
 $table->end ();
+$toggle->end();
 
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';
 
 
 $table->end();
 
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';
 
 require_once 'plc_details.php';
 require_once 'plc_tables.php';
 require_once 'plc_forms.php';
+require_once 'plc_toggles.php';
 
 // -------------------- 
 // recognized URL arguments
 
 // xxx could outline values corresponding to a nodegroup
 if (count ($node_tags)) {
-  plc_section("Nodes");
+  $toggle=new PlcToggle('tag_nodes',"Nodes",array('trigger-tagname'=>'h2'));
+  $toggle->start();
   $table=new PlcTable ("tag_nodes",array("Hostname"=>"string","value"=>"string"),0,$table_options);
   $table->start();
   foreach ($node_tags as $node_tag) {
     $table->row_end();
   }
   $table->end();
+  $toggle->end();
  }
 
 if (count ($interface_tags)) {
-  plc_section("Interfaces");
+  $toggle=new PlcToggle('tag_interfaces',"Interfaces",array('trigger-tagname'=>'h2'));
+  $toggle->start();
   $table=new PlcTable ("tag_interfaces",array("IP"=>"IPAddress","value"=>"string"),0,$table_options);
   $table->start();
   foreach ($interface_tags as $interface_tag) {
     $table->row_end();
   }
   $table->end();
+  $toggle->end();
  }
 
 // grouping both kinds of slice tags 
 // xxx don't show hostnames yet
 $slice_tags = array_merge ($slice_tags,$sliver_tags);
 if (count ($slice_tags)) {
-  plc_section("Slice and sliver tags");
+  $toggle=new PlcToggle('tag_slices',"Slice and sliver tags",array('trigger-tagname'=>'h2'));
+  $toggle->start();
   $table=new PlcTable ("tag_slices",array("Slice"=>"string","value"=>"string","Node id"=>"int"),0,$table_options);
   $table->start();
   foreach ($slice_tags as $slice_tag) {
     $table->row_end();
   }
   $table->end();
+  $toggle->end();
  }
 
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';
 
 $headers['Description']="string";
 $headers['Category']="string";
 $headers['Min role']="string";
+// xxx ref count would be helpful
+//if (plc_is_admin()) $headers['#']='int';
 $headers["Id"]="int";
 if (plc_is_admin()) $headers[plc_delete_icon()]="none";
 
   $table->cell(wordwrap($tag_type['description'],$description_width,"<br/>"));
   $table->cell($tag_type['category']);
   $table->cell($role_name);
+  // ref count
+  //  if (plc_is_admin())     $table->cell('xxx');
   $table->cell($tag_type_id);
   if (plc_is_admin()) 
     $table->cell ($form->checkbox_html('tag_type_ids[]',$tag_type_id));
 $table->end();
 $form->end();
 
-plc_tabs ($tabs,"bottom");
+//plc_tabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';