//url|id|parent|order|title|openNewMenu|isFront|¤@@¤
/******************** INIT ********************/
document.menues = new Array();
var siteroot = "/"
/******************* OBJECTS *****************/
function menuDataObject(){
	//metalevel menuDataObject makes it possible to have more than one menu on the page with different datasources
	this.dataString=""
	this.topMenues= new Array();
	this.allMenuObjects= new Array();
	this.debugName="menu1"
	this.offsetId=0;
	this.includeFrontPage=false;
	
	//INTERNAL FUNCTIONS
	this.compileMenuData = __compileMenuData;
	this.cloneMenuObjects = __cloneMenuObjects;
	this.getChilds = __getChilds;
	this.sortMenues = __sortMenues; 
	return this;
}

	function __compileMenuData(){
		var arr = this.dataString.split("¤@@¤")
		var tmpArr = new Array();
		var oStr = "", i
		//chop the string into an array and assign values to menuobjects
		for(i=0;i<arr.length;i++){
			//makeMenuItem(iArr[i])
				obj = this.allMenuObjects[this.allMenuObjects.length] = new menuItem();
				tmpArr = arr[i].split("|");
				obj.orgStr = arr[i];
				obj.url="/ooizzCMS/"+tmpArr[0];
				obj.id=tmpArr[1];
				obj.parent=tmpArr[2];
				obj.order=tmpArr[3];
				obj.title=tmpArr[4];
				obj.openNewMenu=tmpArr[5]=='y';
				obj.isFront=tmpArr[6]=='y';
		}
		
		// find top menues and assign them to the topMenues Array of the menuObject
		this.topMenues = this.getChilds(this.offsetId)
		for(i=0;i<this.topMenues.length;i++){
			this.cloneMenuObjects(this.topMenues[i])
		}
		
	}

	function __cloneMenuObjects(obj){
		var i	
		obj.childs=this.getChilds(obj.id)
		for(i=0;i<obj.childs.length;i++){
			this.cloneMenuObjects(obj.childs[i])
		}
	}
	
	function __getChilds(pId){
		
		var tmpArr=new Array(), retArr=new Array(), i;
		for(i=0;i<this.allMenuObjects.length;i++){
			if(this.allMenuObjects[i].parent == pId && this.allMenuObjects[i].id != pId){
				retArr[retArr.length]=this.allMenuObjects[i];
			}
		}	
		
		retArr = this.sortMenues(retArr)
		
		return retArr;
	}

	function __sortMenues(sArr){
		var i, dArr = new Array()
		var max, min
		max = sArr.length
		min = 0
		for(j=max-1;j>0;j--){
			for(i=0;i<j;i++){
				if(parseInt(sArr[i].order)>parseInt(sArr[i+1].order)){
					tmp = sArr[i];
					sArr[i]=sArr[i+1];
					sArr[i+1]=tmp;
				}
			}
		}
		return sArr
	}
	
	
	
	
function menuItem(){
	this.orgStr="";
	this.url="";
	this.id=null;
	this.parent=null;
	this.order=null;
	this.title="";
	this.openNewMenu=false;
	this.isFront=false;
	this.childs=new Array();
	return this
}