// Javascript to support expanding and collapsing nodes in a tree

var plusImg = new Image();
	plusImg.src = "/images/palta_library/plus.png"
var minusImg = new Image();
	minusImg.src = "/images/palta_library/minus.png"

function toggleNode ( node1Id, node2Id, imgId ) {
  $(node1Id).toggle();
  if (node2Id != null)
    $(node2Id).toggle();
  if ($(node1Id).visible()) {
    $(imgId).src = minusImg.src;
  } else {
    $(imgId).src = plusImg.src;
  }
}

function expandAll() {
  $$('.topic_hierarchy_child_node').invoke('show');
  $$('.topic_hierarchy_child_node_expanded').invoke('show');
  $$('img.node_toggle_button').each ( function (b) {
    b.src = minusImg.src });
  $$('img.node_toggle_button_expanded').each ( function (b) {
    b.src = minusImg.src });
}

function collapseAll() {
  $$('.topic_hierarchy_child_node').invoke('hide');
  $$('.topic_hierarchy_child_node_expanded').invoke('hide');
  $$('img.node_toggle_button').each ( function (b) {
    b.src = plusImg.src });
  $$('img.node_toggle_button_expanded').each ( function (b) {
    b.src = plusImg.src });
}

document.observe("dom:loaded", function() {
  // initially hide all topic hierarchy child nodes
  $$('.topic_hierarchy_child_node').invoke('hide');
  $$('img.node_toggle_button').each ( function (b) {
    b.src = plusImg.src });
});
