// Version 2010.08.13
//  by Solomon Chang, changyj@rtfiber.com
var node_s = [];  // array for subcat nodes

function click_to_show()
{ var node_p, index;
  node_p = document.getElementById('subcat_contents');
  index = this.getAttribute('id').slice(1);
  if(node_p.hasChildNodes())
   { node = node_p.firstChild;
     node_p.removeChild(node);
   }
  node_p.appendChild(node_s[index]);
  return false;
}
function list_cat()
{ var node_a, // anchor node
      node_p, // parent node 
      note_t, // text node
      i, j, colors = [ 'blue','orange','red' ];

  // title to the upper-left of the banner
  node_p = document.getElementById('cat1');
  node_t = document.createTextNode(cat[0]);
  node_p.insertBefore(node_t,node_p.firstChild);

  // title to the lower-right of the banner
  node_t = document.createTextNode(cat[1]);
  document.getElementById('cat2').appendChild(node_t);

  for(i=0; i < subcat.length; i++)
   { node_e = document.createElement('li');
     node_e.appendChild(str_to_nodes(subcat[i]));
     node_e.setAttribute('id','b'+i);  // id = `b' + index, `b': button
     node_e.onclick = click_to_show;
     node_e.style.listStyleImage = 'url(icon/' + colors[i%3] + '.png)';

     document.getElementById('subcat_list').appendChild(node_e);
     
     // create an `li' element as the root node for a subcat
     // [li marker] [subcat name]
     //     +-------[ol][index][title name]
     node_e = document.createElement('li');
     node_e.setAttribute('id','l'+i);
     node_s[i] = node_e;
     node_e.style.listStyleImage = 'url(icon/' + colors[i%3] + '.png)';
   
     node_p = node_e;

     // create a node describing this subcat  and attach it to `li'
     node_p.appendChild(str_to_nodes(subcat[i]));
    
     // create an OL element and attach it to `li' 
     node_e = document.createElement('ol');
     node_e.style.listStyleImage = 'none';
     node_p.appendChild(node_e);
     node_p = node_e;

     for(j=0; j < titles[i].length; j++)
      { // attach `li' to `ol'
        node_e = document.createElement('li');
        node_a = str_to_nodes(titles[i][j][0],'a');
        node_a.setAttribute('href', 'html/'+ titles[i][j][1] + '.html');
        node_a.setAttribute('target','c');
        node_e.appendChild(node_a);
        node_p.appendChild(node_e);
      }
   }
}

