/*
  $Id: left_menu_categories.js,v 1.2 2008-03-03 09:09:46 kristoffer Exp $
  
  Copyright 2008 VLP Oy
  
  Released under the GNU General Public License
*/


//{{{ class LeftMenuCategories
function LeftMenuCategories (id)
{
  this.id = id;
  this.toggle = toggle;
}

  function toggle (id)
  {
    var sub = document.getElementById('cat_menu_'+this.id+'_'+id);
    if (sub) {
      var cat = document.getElementById('cat_node_'+this.id+'_'+id);
      if (sub.style.display == 'block') {
        cat.className = cat.className.replace("expanded", "");
        sub.style.display = 'none';
      } else {
        cat.className += " expanded";
        sub.style.display = 'block';
      }
    }
  }
  
  function select (id)
  {
    var prev = document.getElementById('cat_node_'+this.id+'_'+this.selected);
    if (prev) {
      var s = prev.className.replace('selected', '');
      prev.className = trimString(s);
    }
    var curr = document.getElementById('cat_node_'+this.id+'_'+id);
    if (curr) {
      curr.className += " selected";
    }
    this.selected = id;
  }
//}}}

function trimString (str) {
  while (str.charAt(0) == ' ')
    str = str.substring(1);
  while (str.charAt(str.length - 1) == ' ')
    str = str.substring(0, str.length - 1);
  return str;
}

