var hiddentext = new Array();

function appendButton(p, t, ev)
{
  var ctl = p.appendChild(document.createElement('A'));
  ctl.className = 'HideControl';
  ctl.setAttribute('href', '#');
  ctl.onclick = ev;
  ctl.appendChild(document.createTextNode(t));
}

// Replace contents of a specified node with revealed text given
// by id of that node
function revealText(node)
{
  while(node.childNodes.length) node.removeChild(node.firstChild);
  appendButton(node, 'hide', hideTextEvent);
  var txt = node.appendChild(document.createElement('SPAN'));
  txt.className = 'RevealedText';
  txt.appendChild(document.createTextNode(' '+hiddentext[node.id]+' '));
  // txt.innerHTML = ' '+hiddentext[node.id]+' ';
  appendButton(node, '<<', hideTextEvent);
}

// Replace contents of a specified node with hidden text unit
function hideText(node)
{
  while(node.childNodes.length) node.removeChild(node.firstChild);
  appendButton(node, 'reveal', revealTextEvent);
  appendButton(node, '>>', revealTextEvent);
}

// Event handler veneers
function hideTextEvent(event)
{
  hideText(this.parentNode);
  return false;
}

function revealTextEvent(event)
{
  revealText(this.parentNode);
  return false;
}
