// generate the Menu structure that HV_Menu wants from the Actinic section tree structures.

if (SingleRoot) NoOffFirstLineMenus = 1; else NoOffFirstLineMenus = section_tree_names.length;

// Menu tree structure ( X is 1..n 1st level, 1_1..n second level 1_1_1..n third, etc
//	MenuX=new Array(Text to show, Link, background image (optional), number of sub elements, height, width);

function BuildMenuArray(pItem, pURL, base)
 {
 if ( MaxDepth == 0) MaxDepth = 1000;
 if (ThisLevel == 0) { var LineWidth=FirstLineWidth; var LineHeight=FirstLineHeight; var BGImage=FirstBGImage}
   else { var LineWidth=SubLineWidth; var LineHeight=SubLineHeight; var BGImage=SubBGImage} 
 ThisLevel++;
 for (var i = 1; i <= pItem.length; i++)
   {
   if ((pItem[i].pChild) && (ThisLevel < MaxDepth)) var children = pItem[i].pChild.length; else children = 0;
   // build a menu line from actinic section array and also fix the &#nn; stuff that Actinic puts in
   var LinkURL = pURL[i].sURL;
   // deal with V5 Preview by stripping all but page name
   if (location.href.indexOf('PreviewHTML') != -1 ) LinkURL = LinkURL.replace(/.*SECTIONID=(.*)&NOLOGIN.*/, "$1");
   eval('Menu' + base + i + '=new Array("' 
        + pItem[i].sName.replace(/&#([\da-fA-F]{1,3}?);/g, function(match, bit) {return String.fromCharCode(bit - 0)})
	+ '","' + LinkURL + '","' + BGImage + '",' + children + ',' + LineHeight + ',' + LineWidth + ');');
   // recurse if child section
   if ((pItem[i].pChild) && (ThisLevel < MaxDepth)) { BuildMenuArray(pItem[i].pChild, pURL[i].pChild, base + i + '_'); }
   }
 ThisLevel--;
 }

 var ThisLevel = 0;
 if (SingleRoot) 
   {
   eval('Menu1=new Array("' + FirstLineText + '","' + FirstLineURL + '","' + FirstBGImage 
        + '",' + section_tree_names.length + ',' + FirstLineHeight + ',' + FirstLineWidth + ');');
   ThisLevel++;
   BuildMenuArray(section_tree_names,section_tree_URLs, '1_');
   }
  else                                          // multiple level base
   {
   BuildMenuArray(section_tree_names,section_tree_URLs, '');
   }
// free up actinic arrays
section_tree_names.length = 0;
section_tree_URLs.length = 0;
// end of - generate the Menu structure that HV_Menu wants from the Actinic section tree structures.
