

function createSubMenuus(){

	if(typeof(document.getElementById) != "undefined"){

		if(typeof(arrMenu) != "undefined"){

			for(var m=0; m<arrMenu.length; m++){

				if(!arrMenu[m][1]){

					//*** creeer side submenu if any, will create subsubmenu if necessary
					var nsm = new SubMenu(arrMenu[m][0], arrMenu[m][2]);

					SUBMENUUS.addSubMenu(nsm);

				}else{

					//*** loop through subarray if any, to create subsubmenu where necessary
					if(arrMenu[m][2].length > 0){

						var arrSubs = arrMenu[m][2];
						var intSLength = arrSubs.length;

						for(var s=0; s<intSLength; s++){

							//*** if not open
							if(!arrSubs[s][1]){

								if(arrSubs[s][2].length > 0){

									//*** create SubSubMenu with blnOpenMain = true
									var nsm = new SubSubMenu(arrSubs[s][0], arrSubs[s][2], true, arrMenu[m][0]);

									SUBMENUUS.addSubMenu(nsm);

								}else{

									//*** add functionality to hide active sub
									var objSub = document.getElementById("sub_"+ arrSubs[s][0]);
									objSub.onmouseover = function(){

										SUBMENUUS.clearActiveMenu();
									}

								}

							}else{

								//*** add functionality to hide active sub
								var objSub = document.getElementById("sub_"+ arrSubs[s][0]);
								objSub.onmouseover = function(){

									SUBMENUUS.clearActiveMenu();
								}


							}
						}
					}
				}
			}
		}
	}
}


//***********************************************************************************
//* Class:		SubMenu 															*
//* Goal:		Represents a SubMenu instance with or without accompanying			*
//*				SubSubMenu															*
//***********************************************************************************
//* Created:	Frank (Chevalier Media), 2006										*
//***********************************************************************************

function SubMenu(intParentId, arrSubs){

	this.intParentId = intParentId;
	this.blnClearAll = false;
	this.intTo = -1;

	this.objMain = document.getElementById("main_"+ intParentId);
	this.objSubMenu = document.getElementById("submenu_"+ intParentId);

	if((this.objMain) && (this.objSubMenu)){

		var intObjMainRight = SubMenuFindPosX(this.objMain) + SubMenuGetObjectProperty(this.objMain, "offsetWidth");
		var intObjMainTop = SubMenuFindPosY(this.objMain);

		SubMenuSetObjectProperty(this.objSubMenu, "left", intObjMainRight);
		SubMenuSetObjectProperty(this.objSubMenu, "top", intObjMainTop);

		/*
			add mouse functionality
		*/

		this.objSubMenu.submenuId = this.intParentId;
		this.objMain.submenuId = this.intParentId;

		this.objSubMenu.onmouseout = function(){
			//*** clear menu's if not cancelled
			SUBMENUUS.clearAllFrom(this.submenuId);
		};

		this.objSubMenu.onmouseover = function(){
			//*** cancel clearing of menu's
			SUBMENUUS.cancelClearAllFrom(this.submenuId);
		};

		this.objMain.onmouseover = function(){

			//*** reset global activestate
			SUBMENUUS.clearActiveMenu();

			//*** change active state
			SUBMENUUS.setActiveMain(this.submenuId);

		};

		this.objMain.onmouseout = function(){
			//*** clear menu's if not cancelled
			SUBMENUUS.clearAllFrom(this.submenuId);
		};

		if(arrSubs.length > 0){

			var intSCount = arrSubs.length;

			for(var s=0; s<intSCount; s++){

				//*** create SubSubMenu with blnOpenMain = false
				if(arrSubs[s][2].length > 0){

					var nsm = new SubSubMenu(arrSubs[s][0], arrSubs[s][2], false, this.intParentId);
					SUBMENUUS.addSubMenu(nsm);

				}else{

					//*** add functionality to hide active sub

					var objSub = document.getElementById("sub_"+ arrSubs[s][0]);
					objSub.onmouseover = function(){

						SUBMENUUS.clearActiveSub();
					}

				}
			}

		}
	}
}

SubMenu.prototype.getParentId = function(){
	return this.intParentId;
};


SubMenu.prototype.showMenu = function(){
	this.cancelClearAll();
	this.objSubMenu.style.visibility = "visible";
};

SubMenu.prototype.hideMenu = function(){
	this.cancelClearAll();
	this.objSubMenu.style.visibility = "hidden";
};

SubMenu.prototype.hiliteSub = function(intSubId){
	var objSub = document.getElementById("sub_"+ intSubId);
	objSub.className = "sideActive";
}

SubMenu.prototype.unhiliteSub = function(intSubId){
	var objSub = document.getElementById("sub_"+ intSubId);
	objSub.className = "sideNormal";
}


SubMenu.prototype.initClearAll = function(){
	this.blnClearAll = true;
	var objThis = this;
	this.intTo = this.setTimeout(objThis, "clearAll", 444, new Array());
};

SubMenu.prototype.cancelClearAll = function(){
	this.blnClearAll = false;
	if(this.intTo != -1){
		clearTimeout(this.intTo);
		this.intTo = -1;
	}
};

SubMenu.prototype.clearAll = function(){
	if(this.blnClearAll){
		SUBMENUUS.clearActiveMenu();
	}
};


SubMenu.prototype.setTimeout = function(a, b, c, arrArgs){
	var ID, func = function(){
		a[b].apply(a, arrArgs);
		clearInterval(ID);//***	clear own interval, so function 'a' executes only once
	}
	ID = setInterval(func, c, arrArgs);
	return ID;
}





//***********************************************************************************
//* Class:		SubSubMenu 															*
//* Goal:		Represents a SubSubMenu instance, can be with or without			*
//*				accompanying SubMenu												*
//***********************************************************************************
//* Created:	Frank (Chevalier Media), 2006										*
//***********************************************************************************

function SubSubMenu(intParentId, arrSubsubs, blnOpenMain, intMainId){

	/*
		if blnOpenMain then there is no side submenu, it's  a beneath-the-main submenu
		might ask for different mouse-over/out actions
	*/
	this.intTo = -1;
	this.blnClearAll = false;
	this.intParentId = intParentId;
	this.blnOpenMain = blnOpenMain;
	this.intMainId = intMainId;

	this.objSub = document.getElementById("sub_"+ this.intParentId);
	this.objSubSubMenu = document.getElementById("subsubmenu_"+ this.intParentId);

	if((this.objSub) && (this.objSubSubMenu)){

		var intObjSubTop = SubMenuFindPosY(this.objSub);

		if(blnOpenMain){

			var objMain = document.getElementById("main_"+ intMainId);
			var intObjSubRight = SubMenuFindPosX(objMain) + SubMenuGetObjectProperty(objMain, "offsetWidth");

			//intObjSubTop += 4;
		}else{
			var intObjSubRight = SubMenuFindPosX(this.objSub) + SubMenuGetObjectProperty(this.objSub, "offsetWidth");
			//intObjSubTop += -1;
		}

		SubMenuSetObjectProperty(this.objSubSubMenu, "left", intObjSubRight);
		SubMenuSetObjectProperty(this.objSubSubMenu, "top", intObjSubTop);


		//*** add mouse functions depending on blnOpenMain
		this.objSub.subId = this.intParentId;
		this.objSubSubMenu.subId = this.intParentId;
		this.objSubSubMenu.submenuId = this.intMainId;

		if(blnOpenMain){

			this.objSub.onmouseover = function(){

				//*** reset global activestate
				SUBMENUUS.clearActiveMenu();
				SUBMENUUS.setActiveSub(this.subId);
				SUBMENUUS.cancelClearAllFrom(this.subId);
				this.className = "active";
			};

			this.objSub.onmouseout = function(){

				SUBMENUUS.clearAllFrom(this.subId);
			};

			this.objSub.className = "";

			this.objSubSubMenu.onmouseout = function(){
				SUBMENUUS.clearAllFrom(this.subId);
			};

			this.objSubSubMenu.onmouseover = function(){
				SUBMENUUS.cancelClearAllFrom(this.subId);
			};

		}else{

			this.objSub.onmouseover = function(){
				SUBMENUUS.setActiveSub(this.subId);
				SUBMENUUS.cancelClearAllFrom(this.subId);
			};


			this.objSubSubMenu.onmouseout = function(){
				SUBMENUUS.clearAllFrom(this.subId);
			};

			this.objSubSubMenu.onmouseover = function(){
				SUBMENUUS.cancelClearAllFrom(this.subId);
				SUBMENUUS.cancelClearAllFrom(this.submenuId);
			};
		}
	}
}

SubSubMenu.prototype.getParentId = function(){
	return this.intParentId;
};

SubSubMenu.prototype.getMainId = function(){
	return this.intMainId;
};

SubSubMenu.prototype.sideSubMenu = function(){
	return !this.blnOpenMain;
};

SubSubMenu.prototype.showMenu = function(){
	this.cancelClearAll();
	this.objSubSubMenu.style.visibility = "visible";
};

SubSubMenu.prototype.hideMenu = function(){
	this.cancelClearAll();
	this.objSubSubMenu.style.visibility = "hidden";

	if(!this.sideSubMenu()){
		//*** unhilite the sub
		this.objSub.className = "";
	}
};

SubSubMenu.prototype.initClearAll = function(){
	this.blnClearAll = true;
	var objThis = this;
	this.intTo = this.setTimeout(objThis, "clearAll", 444, new Array());
};

SubSubMenu.prototype.cancelClearAll = function(){
	this.blnClearAll = false;
	if(this.intTo != -1){
		clearTimeout(this.intTo);
		this.intTo = -1;
	}
};

SubSubMenu.prototype.clearAll = function(){
	if(this.blnClearAll){
		SUBMENUUS.clearActiveMenu();
	}
};


SubSubMenu.prototype.setTimeout = function(a, b, c, arrArgs){
	var ID, func = function(){
		a[b].apply(a, arrArgs);
		clearInterval(ID);//***	clear own interval, so function 'a' executes only once
	}
	ID = setInterval(func, c, arrArgs);
	return ID;
}



//***********************************************************************************
//* Class:		SubMenuContainer 													*
//* Goal:		Represents a container for all SubMenu and SubSubMenu instances in 	*
//*				a webpage. Submenu instances are controlled via this container		*
//***********************************************************************************
//* Created:	Frank (Chevalier Media), 2006										*
//***********************************************************************************

function SubMenuContainer(){

	this.arrSubMenuus	= new Array();
	this.arrSubMenuusActive = new Array(-1, -1);
	return this;
}

SubMenuContainer.prototype.addSubMenu = function(objSubMenu){

	if(!this.arrSubMenuus[objSubMenu.getParentId()]){

		this.arrSubMenuus[objSubMenu.getParentId()]	= objSubMenu;
	}else{
		alert("SubMenu with parent ID '"+ objSubMenu.getParentId() +"' already exists!");
	}
}

SubMenuContainer.prototype.getSubMenu = function(strSubMenuId){

	if(this.arrSubMenuus[strSubMenuId]){

		return this.arrSubMenuus[strSubMenuId];
	}else{
		alert("SubMenu with parent ID '"+ strSubMenuId +"' doesn't exist!");
		return null;
	}
}

SubMenuContainer.prototype.clearActiveMenu = function(){

	if(this.arrSubMenuusActive[1] != -1){

		//*** hide subsubmenu
		var objSubSubMenu = this.getSubMenu(this.arrSubMenuusActive[1]);
		objSubSubMenu.hideMenu();

		//*** unhilite sub if necessary
		/*
			only if submenu is a side menu
		*/
		if(objSubSubMenu.sideSubMenu()){
			var objSub = document.getElementById("sub_"+ this.arrSubMenuusActive[1]);
			objSub.className = "sideNormal";
		}
	}

	//*** hide submenu if necessary and unhilite main
	if(this.arrSubMenuusActive[0] != -1){
		//*** sub
		var objSubMenu = this.getSubMenu(this.arrSubMenuusActive[0]);
		objSubMenu.hideMenu();

		var objMain = document.getElementById("main_"+ this.arrSubMenuusActive[0]);
		objMain.className = "";
	}

	this.arrSubMenuusActive = new Array(-1, -1);
};

SubMenuContainer.prototype.setActiveMain = function(intMainId){

	if(this.arrSubMenuusActive[0] != intMainId){
		//*** clear old one if necessary

		var objMain = document.getElementById("main_"+ intMainId);
		objMain.className = "active";

		this.arrSubMenuusActive[0] = intMainId;

		//*** show submenu
		var objSubmenu = this.getSubMenu(intMainId);
		objSubmenu.showMenu();
	}
};

SubMenuContainer.prototype.setActiveSub = function(intSubId){

	if(this.arrSubMenuusActive[1] != intSubId){

		//*** clear old one if necessary
		if(this.arrSubMenuusActive[1] != -1){

			//*** hide subsubmenu
			var objSubSubMenu = this.getSubMenu(this.arrSubMenuusActive[1]);
			objSubSubMenu.hideMenu();

			//*** unhilite sub if submenu is a side menu
			if(objSubSubMenu.sideSubMenu()){
				var objSub = document.getElementById("sub_"+ this.arrSubMenuusActive[1]);
				objSub.className = "sideNormal";
			}
		}

		//*** show subsubmenu
		var objSubSubMenu = this.getSubMenu(intSubId);
		objSubSubMenu.showMenu();

		//*** hilite sub
		var objSub = document.getElementById("sub_"+ intSubId);
		objSub.className = "sideActive";

		this.arrSubMenuusActive[1] = intSubId;
	}
};


SubMenuContainer.prototype.clearActiveSub = function(){

	//*** clear old one if necessary
	if(this.arrSubMenuusActive[1] != -1){

		//*** hide subsubmenu
		var objSubSubMenu = this.getSubMenu(this.arrSubMenuusActive[1]);
		objSubSubMenu.hideMenu();

		//*** unhilite sub if submenu is a side menu
		if(objSubSubMenu.sideSubMenu()){
			var objSub = document.getElementById("sub_"+ this.arrSubMenuusActive[1]);
			objSub.className = "sideNormal";
		}

		this.arrSubMenuusActive[1] = -1;
	}

};


SubMenuContainer.prototype.clearAllFrom = function(intId){

	var objMenu = this.getSubMenu(intId);
	objMenu.initClearAll();
};

SubMenuContainer.prototype.cancelClearAllFrom = function(intId){

	var objMenu = this.getSubMenu(intId);
	objMenu.cancelClearAll();
};


/*
	ToDo:

		change active state for a submenu in an open main

		styles for 800x600

*/


//***********************************************************************************
//* Goal:		Convenience functions												*
//***********************************************************************************
function SubMenuFindPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent){

			curleft += obj.offsetLeft;
			obj = obj.offsetParent;

			if(obj.id == "menu") break;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}


function SubMenuFindPosY(obj)
{
	var curTop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent){

			curTop += obj.offsetTop;
			obj = obj.offsetParent;

			if(obj.id == "menu") break;
		}
	}
	else if (obj.y)
		curTop += obj.y;
	return curTop;
}


//*** return browser specific requested property of an object
function SubMenuGetObjectProperty(obj, strProperty){
	switch(strProperty){

		case "top":
				if(typeof(obj.style.top) != "undefined"){
					return parseInt(obj.style.top);
				}else{
					return -1;
				}
			break;

		case "left":
				if(typeof(obj.style.left) != "undefined"){
					return parseInt(obj.style.left);
				}else{
					return -1;
				}
			break;

		case "offsetTop":
				if(typeof(obj.offsetTop) != "undefined"){
					return obj.offsetTop;
				}else{
					return -1;
				}
			break;

		case "height":
				if(typeof(obj.clientHeight) != "undefined"){
					return obj.clientHeight;
				}else{
					return -1;
				}
			break;

		case "styleHeight":
				if(typeof(obj.style.height) != "undefined"){
					return parseInt(obj.style.height);
				}else{
					return -1;
				}
			break;

		case "offsetHeight":
				if(typeof(obj.offsetHeight) != "undefined"){
					return obj.offsetHeight;
				}else{
					return -1;
				}
			break;

		case "offsetWidth":
				if(typeof(obj.offsetWidth) != "undefined"){
					return obj.offsetWidth;
				}else{
					return -1;
				}
			break;

		default:
			if(typeof(obj.style[strProperty]) != "undefined"){
				return obj.style[strProperty];
			}

		break;
	}
	return "undefined";
}

//*** set browser specific property of an object
function SubMenuSetObjectProperty(obj, strProperty, value){
	switch(strProperty){

		case "left":
				if(typeof(obj.style.left) != "undefined"){
					obj.style.left = value +"px";
				}else{

				}
			break;

		case "top":
				if(typeof(obj.style.top) != "undefined"){
					obj.style.top = value +"px";
				}else{

				}
			break;

		case "offsetTop":
				if(typeof(obj.offsetTop) != "undefined"){
					obj.offsetTop = value;
				}else{

				}
			break;

		case "height":
				if(typeof(obj.style.height) != "undefined"){
					obj.style.height =  value +"px";
				}else{

				}
			break;

		case "offsetHeight":
				if(typeof(obj.offsetHeight) != "undefined"){
					obj.offsetHeight = value;
				}else{

				}
			break;

		default:
			break;
	}
}

//***********************************************************************************
//* Goal:		Create the global container instance								*
//***********************************************************************************
var SUBMENUUS	= new SubMenuContainer();