/**
 *-----------------------------------------------------------*----------------*
 *     Web Project Manager                                   |   backSystem   |
 *-----------------------------------------------------------*----------------*
 *     @category backSystem
 *     @package javascript
 *     @version 0.1 [2008/02/06]
 *
 *     @author Tomáš Režňák <tomas.reznak@web-project-manager.com>
 *     @copyright Copyright © 2008, Tomáš Režňák
 *     @link http://www.web-project-manager.com/
 *----------------------------------------------------------------------------*
 *     definition of javascript functions for HTML tree menus
 */

/**
 * expand / collapse tree menu folder
 * 
 * @param mixed obj    object or object's id - folder which should be expanded/collapsed
 * @return void
 */
function expandFolder(obj) {
  if (document.getElementById(obj)) {    // object identified by its id
    obj = document.getElementById(obj);
  }

  if (obj.className == "folder_plus") {    // expand collapsed folder
    obj.className = "folder_minus";
  } else {    // collapse expanded folder
    obj.className = "folder_plus";
  }
	
  sibling = obj.nextSibling;
  
  while (sibling) {    // process all siblings (hide/show)
    if (sibling.nodeName == "UL") {
      if (sibling.className == "dis_none") {
        sibling.className = "dis_block";
      } else {
        sibling.className = "dis_none";
      }
    }

    sibling = sibling.nextSibling;
  }
}

/**
 * walk through tree menu and expand all folders above obj menu item (expand all forfathers)
 * 
 * @param mixed obj    object or object's id - menu item (typically actual item in menu)
 * @return void
 */
function findInMenu(obj) {
  if (document.getElementById(obj)) {    // object identified by its id
    obj = document.getElementById(obj);
  }
  
  var parent = obj.parentNode;
  while (parent) {
    if (parent.nodeName == "UL" && parent.className == "dis_none") {
      parent.className = "dis_block";    

      sibling = parent.previousSibling;
      while(sibling) {
        if (sibling.nodeName == "A" && sibling.className == "folder_plus") {
          sibling.className = "folder_minus";
        }
        sibling = sibling.previousSibling;
      }
    }
    
    parent = parent.parentNode;
  }
}

