// ++++++++++++++++ minimize & maximize ++++++++++++++++
function show(el) {
  el.style.display='';
}

function hide(el) {    
  el.style.display='none';    
}

function getNodeByName(element, name) {
  children = element.childNodes;
  for (var i = 0; i < children.length; i++) {
    if (children[i].nodeName.toUpperCase() == name.toUpperCase()) {
      return children[i];
    }
  }
  return null;
}	


// probably DOM traversing problem - solved by IE hack
// Reality    
//<table>
//  <thead>
//    <th>
//      <img src='img/minus.png' 
// Firefox >IMG|>TH|>THEAD|>TABLE
//<table class="container"><thead><th><img src='img/minus.png' /> Color Coding</th></thead><tbody><tr><td>    
// IE      >IMG|>TH|>TR|   >THEAD|
//<table class="container"><thead><th><img src='img/minus.png' /> Color Coding</th></thead><tbody><tr><td>       

function traverse(image) {
  var table = image.parentNode.parentNode.parentNode;
  if ("table".toUpperCase() != table.nodeName.toUpperCase()) { // IE 
    table = table.parentNode; 
  }
  return table;
}

function resizeClick(image, plusImage, minusImage) {        
  var table = traverse(image);
  resize(table, image, plusImage, minusImage, true);
}

function resize(table, image, plusImage, minusImage, byClick) {        
  var tbody = getNodeByName(table, "tbody");
  
  if (byClick) {
    if (isCollapsed(image)) {        
      show(tbody);
      image.setAttribute("src", minusImage);
    } else { 
      hide(tbody); 
      image.setAttribute("src", plusImage); 
    }
  } else { // just hide it (do it here, because fixed width must be set before)
    if (isCollapsed(image)) {        
      hide(tbody); 
    }
  }
}

function isCollapsed(image) {
  var imagePath = image.getAttribute("src");
  var collapsed = -1 != imagePath.indexOf("Plus"); // does imagePath contains "plus"?
  return collapsed;
}

function sweepContainers(plusImage, minusImage) {  
  /*el = document.getElementById("containerImage");
  logIt(el);*/
  els = document.getElementsByName("containerImage");
  //logIt(els[0]);
  for (var i = 0; i < els.length; i++) {             
    var image = els[i];    
    var table = traverse(image);
    table.style.width = table.offsetWidth;
    //logIt(table.style.width);
    if (isCollapsed(image)) { // because we must hide it *after* width was estimated
      resize(table, image, plusImage, minusImage, false);
    }
  }
}

function logIt(text) {
  /*alert("OK");
  document.getElementById('logContainer').style.display='';*/
  document.getElementById('log').innerHTML = document.getElementById('log').innerHTML + ' ' + text;
  /*alert("OK");*/
}

function clearLog() {    
  document.getElementById('log').innerHTML = '';
  document.getElementById('logContainer').style.display='none';
}

// ---------------- minimize & maximize ----------------
