function Tree(id)
{
 var ul = document.getElementById(id);
 this.parcours(ul);
}

Tree.prototype.isElement = function(el, type)
{
 return (1==el.nodeType && type==el.nodeName.toLowerCase());
};

Tree.prototype.countLI = function(ul) {
 var r = 0;
 for (var i=0; i<ul.childNodes.length; i++) {
  if (this.isElement(ul.childNodes[i], 'li')) {
   r++;
  }
 }
 return r;
};
Tree.prototype.isLastLeaf = function(li) {
 var ul = li.parentNode;
 var tmp = null;
 for (var i = ul.childNodes.length-1; i>0; --i) {
  tmp = ul.childNodes[i];
  if (this.isElement(tmp, 'li')) {
   return (li == tmp);
  }
 }
 return (i==this.countLI(ul)-1);
};
Tree.prototype.getUL = function(li) {
 for (var j=0; j<li.childNodes.length; j++) {
  if (this.isElement(li.childNodes[j], 'ul')) {
   return li.childNodes[j];
  }
 }
 return false;
};

Tree.prototype.placeEvt = function(ul, li)
{
 li.onclick = function(evt)
 {
  var cn = '';
  if (Tree.is_ie) {
   evt = window.event;
   if (evt.srcElement.tagName!='LI') { return true; }
  } else {
   if (li!=evt.originalTarget) { return true; }
  }
  ul.style.display = (ul.style.display=='block')? 'none':'block';
  switch(li.className) {
   case 'node_open':
    cn = 'node_close';
   break;
   case 'node_open_last':
    cn = 'node_close_last';
   break;
   case 'node_close':
    cn = 'node_open';
   break;
   case 'node_close_last':
    cn = 'node_open_last';
   break;
  }
  li.className = cn;
  if (Tree.is_ie) {
   evt.cancelBubble = true;
   evt.returnValue = false;
  } else {
   evt.preventDefault();
   evt.stopPropagation();
  }
  return false;
 };
};

Tree.prototype.parcours = function(ul) {
  if ( !ul ) { return false; }
 var new_ul = null;
 var li = null;
 for (var i=0; i<ul.childNodes.length; i++) {
  li = ul.childNodes[i];
  if (this.isElement(li, 'li')) {
   new_ul = this.getUL(li);
   if (false!==new_ul) {
    if (this.isLastLeaf(li)) {
     li.className="node_close_last";
    } else {
     li.className="node_close";
    }
    new_ul.style.display = 'none';
    this.placeEvt(new_ul, li);
    this.parcours(new_ul);
   } else {
    if (this.isLastLeaf(li)) {
     li.className="leaf_last";
    } else {
     li.className="leaf";
    }
   }
  }
 }
};
Tree.is_ie = false;
/*@cc_on Tree.is_ie = true; @*/