/**
 * @author Timo 9.09.2005
 */
menu.tree=function(aRoot){
	//this.aRoot=aRoot;
	//if(menu.tree._aNodes==null){
		var lastInput=menu.html._aInput.length-1;//?
		var defaultName='defaultName';//?
		
		if(aRoot==null){aRoot=menu.A_ROOT;}//if(aRoot==null
		
		PARENTS[menu.tree.ROOT_INDEX]=0;
		var aTree=new Array();
		aTree[0]=aRoot;
		
		var iExit=PhraseBook.phraseBooks[PhraseBook.currentId]._aCaption.length;
		var iLoop=menu.tree.ROOT_INDEX; //1;//0;
		while(iLoop<iExit){
			var caption=PhraseBook.phraseBooks[PhraseBook.currentId]._aCaption[iLoop];
			var parentNr=PARENTS[iLoop];
			var bValidNode= caption!=null && parentNr!=null && parentNr<iLoop;
			
			if(bValidNode){
				var inputId=INPUT_TYPES[iLoop];
				if(inputId<0){
					inputId=null;
				}else if(inputId>lastInput){
					inputId=lastInput;
				}//if(inputId==null
				
				var inputName=INPUT_NAME[iLoop];
				if(inputName==null){
					if(inputId==2){//_aInput[2]="radio";//radio inputs of the same set must have the same name
						inputName=defaultName;
					}else{
						inputName='';
					}//if(inputId==2
				}//if
				
				var inputValue=VALUES[iLoop];
				if(inputValue==null){
					inputValue='';
				}//if
				
				var cssClass=menu.tree.getClassName(iLoop,inputId);      
				var checked=CHECKED[iLoop];
				if(checked!=null){
				//if(checked==true){
					checked='checked';
				}//if(checked==true
				
				var functionName=JS_FUNCTIONS[iLoop];
				var sDemo=DEMOS[iLoop];
				var sEvent=EVENTS[iLoop];
				var sHref=HREF[iLoop];
				aRoot=aTree[parentNr];
				//var s_prompt=prompt('menu.tree',' caption '+caption+' iLoop '+iLoop+' parentNr '+parentNr+' aTree '+aTree+' aRoot '+aRoot);
				aTree[iLoop]=menu.newNode(aRoot, caption, inputId, inputName, inputValue, cssClass, iLoop, checked, functionName, sEvent, sHref, sDemo);
			}else{
				aTree[iLoop]=new Array;
				//var s_prompt=prompt('menu.tree','menu.tree '+iLoop+' caption '+caption);
			}//if(caption!=null
			
			iLoop=iLoop+1;
		}//while(
		menu.tree._aNodes=aTree;
	//}
	return aTree[menu.tree.ROOT_INDEX];
}//tree
menu.tree.ROOT_INDEX=1;

menu.tree.getClassName=function(iLoop,inputId){
	var cssClass=CSS_CLASSES[iLoop];
	if(cssClass==null){
		if(inputId==1||inputId==2){
			cssClass=menu.html.S_CLASS_BORDER_0;
		}else if(inputId==5||inputId==6){
			cssClass=menu.html.S_CLASS_BUTTON;
		}else if(inputId==4){
			cssClass=menu.html.S_CLASS_TEXT;
		}else{
			cssClass='MISSING';
		}//if(cssClass==null
	}//if(cssClass==null
	return cssClass;
}//getClassName
