function initializeDocument() 
{ 
  preLoadIcons();
  switch(navigator.family)
  {
    case 'ie4':
      browserVersion = 1; //Simply means IE > 3.x
      break;
    case 'opera':
      browserVersion = (navigator.version > 6 ? 1 : 0); //opera7 has a good DOM
      break;
    case 'nn4':
      browserVersion = 2; //NS4.x 
      break;
    case 'gecko':
      browserVersion = 3; //NS6.x
      break;
    case 'safari':
      browserVersion = 1; //Safari Beta 3 seems to behave like IE in spite of being based on Konkeror
      break;
	default:
      browserVersion = 0; //other, possibly without DHTML  
      break;
  }

  supportsDeferral = ((navigator.family=='ie4' && navigator.version >= 5 && navigator.OS != "mac") || browserVersion == 3);
  foldersTree.initialize(0); 

  
  if (supportsDeferral && !STARTALLOPEN) {
		if (hidemaincat){
			for (i=0; i<=foldersTree.nChildren-1; i++)
				foldersTree.children[i].renderOb(null);
		} else {
			foldersTree.renderOb(null);
		}
  } else {
	//Used with NS4 and STARTALLOPEN
	if (hidemaincat){
        for (i=0 ; i < foldersTree.nChildren; i++) {
			renderAllTree(foldersTree.children[i], null);
		}
		if (!STARTALLOPEN) {
			
			hideWholeTree(foldersTree, false, 0);
			//for (i=0 ; i < foldersTree.nChildren; i++)
			//	foldersTree.children[i].folderMstr(null);
		}
    } else {
		renderAllTree(foldersTree, null);
		if (!STARTALLOPEN) hideWholeTree(foldersTree, false, 0);
    }
    
  }
  //To force the scrollable area to be big enough
  if (browserVersion == 2) {
	  doc.write("<layer top=" + doc.yPos + ">&nbsp;</layer>");
      }
  if (!STARTALLOPEN)
    clickOnNodeObj(foldersTree);
    if (initialcat != ''){
		openBySeq(initialcat);
	}

}
function blockStartHTML(idprefix) {
  var idParam = "id=\"" + idprefix + this.id + "\"";
  var docW = "";
  var strClass = "";
  if (this.nChildren > 0)
	strClass = "layerwithsub lvl" + this.level;
  else
	strClass = "layernosub lvl" + this.level;
  
  if (browserVersion == 2)
    docW = "<layer "+ idParam + " top=\"" + doc.yPos + "\" visibility=\"show\" class=\"" + strClass + "\">";
  else if (browserVersion != 0)
    docW = "<div " + idParam + " style=\"display:block; position:block; \" class=\"" + strClass + "\">";  
 
 docW = docW + "<ul>"
  
  return docW;
}

function blockEndHTML() {
  var docW = "";
  docW = docW + "<\/ul>";
  if (browserVersion == 2) 
    docW = docW + "<\/layer>";
  else if (browserVersion != 0)
    docW = docW + "<\/div>";
  return docW;
}

function drawNode(insertAtObj) 
{ 
	var docW = "";
	var fullLink = "";
	
	if (this.level > 0){
		if (this.link != '')
		{
			fullLink = "href=\"" + this.link + "\" target=\"" + this.target + "\" onClick=\"setActiveNode('" + this.id + "');clickOnNode('" + this.id + "');setLastNodeClicked('" + this.id + "');\"";
			if (usehover)
			fullLink = fullLink + " onMouseOver=\"hoverOverNode('" + this.id + "\');\" onMouseOut=\"hoverOutNode('" + this.id + "\');\"";
		} else {
			if (this.nChildren > 0) 
				fullLink = "href=\"javascript:clickOnNode('" + this.id + "');setLastNodeClicked('" + this.id + "');\" onMouseOver=\"window.status='';return true\"";
		}
	} else {
		if (this.link != '')
			fullLink = "href=\"" + this.link + "\" target=\"" + this.target + "\" onClick=\"setActiveNode('" + this.id + "');setLastNodeClicked('" + this.id + "');\""; 
	}
	
	docW = docW + this.blockStartHTML("item");
	
	
	docW = docW + "<li>";
	if (this.level == 1 ) {
		docW = docW + "<div class=\"link\">";
	}
	
	docW = docW + "<img alt=\"item\" id=\"itemIcon" + this.id + "\" name=\"itemIcon" + this.id + "\" src=\"";
	docW = docW + this.iconImageSrc() + "\" border=\"0\">";
	
	docW = docW + "<a " + fullLink  + " id=\"itemTextLink" + this.id + "\" class=\"";
    
    if (this.nChildren > 0)
		{
		if (this.link != '')
			docW = docW + "folderlinklevel ";
		else
			docW = docW + "foldernolinklevel ";
		}
	else
		{
		if (this.link != '')
			docW = docW + "filelinklevel ";
		else
			docW = docW + "filenolinklevel ";
		}
	docW = docW + "lvl" + this.level;
    docW = docW + "\">" + this.desc + "<\/a>";
    if (this.level == 1 ) {
		docW = docW + "<\/div>";
    }
    docW = docW + "<\/li>";
	docW = docW + this.blockEndHTML();
	
	if (browserVersion == 2) { 
    if (!doc.yPos)
      doc.yPos=yposition;
	} 
  
	if (insertAtObj == null)
	{
		if (supportsDeferral) {
			doc.write("<div id=domRoot></div>"); //transition between regular flow HTML, and node-insert DOM DHTML
			insertAtObj = getElById("domRoot");
			insertAtObj.insertAdjacentHTML("beforeEnd", docW);
		}
		else
			doc.write(docW);
	}
	else
	{
		insertAtObj.insertAdjacentHTML("afterEnd", docW);
	}

	this.isRendered = 1;
	
	if (browserVersion == 2) 
	{ 
		this.navObj = doc.layers["item"+this.id];
		this.iconImg = this.navObj.document.images["itemIcon"+this.id];
		doc.yPos=doc.yPos+this.navObj.clip.height;
	} 
	else if (browserVersion != 0)
	{ 
		this.navObj = getElById("item"+this.id);
		this.iconImg = getElById("itemIcon"+this.id);
	}
}