var width=180;
var border=2;

function startbox()
{
   document.write('<center><table border=2 cellspacing=0 cellpadding=10 bgcolor=#efefd5 background=/images/parchment.jpg>');
   document.write('<tr><td><font class="txt2">');
}

function endbox()
{
   document.write('</font></td></tr></table></center><p>');
}

function display1(title, image, link, caption)
{
   if ((link==null)||(link==''))    { link=image; }
   if (caption==null)               { caption=''; }
   document.write('<center><table class="pic" cellpadding="10" cellspacing="0" border="'+border+'" background=/images/parchment.jpg><tr valign="top"><td>');
   document.write('   <font class="txt1"><nobr>'+title+'</nobr></font>');
   document.write('   <center><a href="'+link+'"><img src="'+image+'" width="'+width+'" border="0"></a></center>');
   document.write('   <font class="txt2">'+caption+'</font>');
   document.write('</td></tr></table></center>');
   return true;
}

function display2(title1, image1, link1, caption1, title2, image2, link2, caption2)
{
   if ((link1==null)||(link1==''))    { link1=image1; }
   if (caption1==null)                { caption1=''; }
   if ((link2==null)||(link2==''))    { link2=image2; }
   if (caption2==null)                { caption2=''; }
   document.write('<center><table cellpadding="0" cellspacing="10" border="0"><tr valign=top align=center><td>');
   display1(title1,image1,link1,caption1);
   document.write('</td><td>');
   display1(title2,image2,link2,caption2);
   document.write('</td></tr></table></center>');
   return true;
}

function display3(title1, image1, link1, caption1, title2, image2, link2, caption2, title3, image3, link3, caption3)
{
   if ((link1==null)||(link1==''))    { link1=image1; }
   if (caption1==null)                { caption1=''; }
   if ((link2==null)||(link2==''))    { link2=image2; }
   if (caption2==null)                { caption2=''; }
   if ((link3==null)||(link3==''))    { link3=image3; }
   if (caption3==null)                { caption3=''; }
   document.write('<center><table cellpadding="0" cellspacing="10" border="0"><tr valign=top align=center><td>');
   display1(title1,image1,link1,caption1);
   document.write('</td><td>');
   display1(title2,image2,link2,caption2);
   document.write('</td><td>');
   display1(title3,image3,link3,caption3);
   document.write('</td></tr></table></center>');
   return true;
}

// ----------------------------------------------------------------------
// list tree-view functions
// ----------------------------------------------------------------------
// ----- save entire list
function save(thislist)
{
   thislist.savelist = new Array();
   for (var i=0; i < thislist.length; i++)
   {
      opt = thislist.options[i];
      thislist.savelist[i] = new Option(opt.text, opt.value, opt.defaultSelected, opt.selected);
   }
}
// ----- add an option to the list
function add(thislist,index,txt,val,def,sel)
{ thislist.options[index] = new Option(txt, val, def, sel); return index+1; }
// ----- clear entire list contents
function clear(thislist)
{ while (thislist.length > 0) { thislist.options[0] = null; } }
// ----- emit a list item with indentation and + or > prefix
function opt(val,title)
{
   pre = val.substr(0,val.indexOf('|'));
   url = val.substr(val.indexOf('|')+1);
   document.write('<option value="'+val+'">');
   for (indent=pre.indexOf('.');(indent>0); indent=pre.indexOf('.',indent+1))
      { document.write('&nbsp;&nbsp;&nbsp;'); }
   if (url == "") { document.write('+ '); }
   else           { if (pre!='') {document.write('&nbsp;&nbsp;&nbsp;> '); } else { document.write('&nbsp;&nbsp;&nbsp;'); } }
   document.write(title+'</option>');
   return true;
}
// ----- show the tree branch containing matching item
function show(thislist,match)
{
   if (thislist.savelist == null) { save(thislist); }

   // split selection into prefix and URL
   match_pre = match.substr(0,match.indexOf('|'));
   match_url = match.substr(match.indexOf('|')+1);
   // empty the current list, loop through saved list and restore items on open branch
   clear(thislist);
   j = 0; selpos = 0;
   for (var i=0; i < thislist.savelist.length; i++)
   {
      opt = thislist.savelist[i];
      // split this item into prefix and URL
      opt_pre = opt.value.substr(0,opt.value.indexOf('|'));
      opt_url = opt.value.substr(opt.value.indexOf('|')+1);         
      // trim last category from prefix for category items (blank URL)
      // so that 'sibling' categories will match and be shown
      if (opt_url == "") { opt_pre = opt_pre.substr(0,opt_pre.lastIndexOf('.')); }
      // if prefix+URL matches, select this item
      if ((match!='')&&(opt.value==match)) { selpos = j; }
      // or if URL matches, select this item
      if ((selpos==0)&&(match_url!='')&&(opt_url==match_url)) { selpos = j; }
      // if prefix matches, show this item
      if (opt_pre == match_pre.substr(0,opt_pre.length))
         { j = add(thislist,j,opt.text,opt.value,false,false); }
   }
   thislist.selectedIndex = selpos;
}
// ----- re-direct with history
function go(thislist)
{
   pre = "/jungleib/archive/";  // ROOT PATH FOR PAGES IN LIST
   val = thislist.options[thislist.selectedIndex].value;
   // remove category prefix
   prepos = val.indexOf('|'); if (prepos > -1) { val=val.substr(prepos+1); }
   if (val == '') return false;
   window.location = pre+val;
   return false;
}
// ----- scroll/select previous item in list
function prev(thislist)
{
   if (thislist.selectedIndex > 0)
   {
      thislist.selectedIndex = thislist.selectedIndex-1;
      thisitem = thislist.options[thislist.selectedIndex];
      show(thislist,thisitem.value);
      go(thislist);
   }
}
// ----- scroll/select next item in list
function next(thislist)
{
   if (thislist.selectedIndex < thislist.length-1)
   {
      thislist.selectedIndex = thislist.selectedIndex+1;
      thisitem = thislist.options[thislist.selectedIndex];
      show(thislist,thisitem.value);
      go(thislist);
   }
}

