
		// common functions
		var closeTime = null;
		var closeTiming = 1000;
		var selectedMenu = new Array();
		var menuIDs = new Array();

		function VivianMenuItem(name, url, selected, iconNormal) {
			this.type = "item";
			this.name = name;
			this.url = url;
			this.iconNormal = iconNormal;
			this.selected = selected;
		}		

		function VivianMenuAddItem(name, url, selected) {
			var iconNormal = "";
			if (arguments.length > 3) iconNormal = arguments[3];
			var newItem = new VivianMenuItem(name, url, selected, iconNormal);
			this.childs[this.childs.length] = newItem;
		}

		function VivanMenuAddMenu(name, alias, selected) {
			var newMenu = new VivianMenu(name, alias, selected);
			this.childs[this.childs.length] = newMenu;
			newMenu.parent = this;
			newMenu.index = this.childs.length-1;
			return newMenu;
		}
		
		function VivianMenuPrintStructure() {
			document.write('<ul>');
			for (var i = 0; i < this.childs.length; i++) {
				if (this.childs[i].type == "item") {
					document.write('<li>'+this.childs[i].name+'</li>');
				} else if (this.childs[i].type == "menu") {
					document.write('<li>'+this.childs[i].name+'</li>');
					this.childs[i].printStructure();
				}
			}
			document.write('</ul>');		
		}
		
		function VivianMenu(name, alias, selected) {
			this.type = "menu";
			this.name = name;
			this.index = 0;
			this.parent = null;
			this.alias = alias;
			this.selected = selected;
			this.addItem = VivianMenuAddItem;
			this.addMenu = VivanMenuAddMenu;
			this.printStructure = VivianMenuPrintStructure;
			this.childs = new Array();
		}	

		function openMenu(menuID, openingPlace) {
			// get the opening position
			var openproperties = openingPlace.split(',');
			var openingPlaceVert = openproperties[0];
			var openingPlaceHorz = openproperties[1];
			var widthset = "";
			if (openproperties.length > 2) widthset = openproperties[2];
			
			//var openingPlaceVert = openingPlace.substring(0, openingPlace.indexOf(','));
			//var openingPlaceHorz = openingPlace.substring(openingPlace.indexOf(',') + 1, openingPlace.length);

			var opener = document.getElementById(menuID);
			var menuBlock = document.getElementById(menuID+"-block");
			//alert(menuID+"-block");
			var xPos = findXPos(opener);
			var yPos = findYPos(opener);
			var width = getWidth(opener);
			width -= (menuItemSpace + Math.round(menuItemSpace / 2) );
			xPos += Math.round(menuItemSpace / 2);
			var height = getHeight(opener);

			var found = false;
			for (var i = 0; i < menuIDs.length; i++) {
				if (menuIDs[i] == menuID) found = true;
			}
			if (!found) menuIDs[menuIDs.length] = menuID;

			if (openingPlaceVert == "b") { // bottom, align the top of the block with the bottom of the opener
				menuBlock.style.top = (yPos + height)+"px";
			}
			if (openingPlaceVert == "t") { // bottom, align the top of the block with the bottom of the opener
				menuBlock.style.top = yPos+"px";
			}
			if (openingPlaceHorz == "l") { // left, align the left of the block with the left of the opener
				menuBlock.style.left = (xPos)+"px";
			}
			if (openingPlaceHorz == "lr") { // left, align the left of the block with the left of the opener
				menuBlock.style.left = (xPos+width)+"px";
			}
			menuBlock.style.display = "block";
			if (widthset == "min") {
				var blockWidth = getWidth(menuBlock);
				if (blockWidth < width) menuBlock.style.width = width + "px";
			}
			
			
			var menuPath = menuID.split("-");
			selectedMenu = new Array();
			for (var i = 1; i < menuPath.length; i++) {
				selectedMenu[i -1] = menuPath[i];
			}

			var now = new Date();
			closeTime = Date.parse(now) + closeTiming;
			hideItems();
			closeTime = null;
		}

		function delayedHideItems() {
			var now = new Date();
			closeTime = Date.parse(now) + closeTiming;
			selectedMenu = new Array();
			setTimeout("hideItems()", closeTiming);
		}

		function hideItems() {
			if (closeTime == null) return;
			var openMenus = new Array();

			var menuID = "";
			for (i = 0; i < selectedMenu.length; i++) {
				menuID = menuID + selectedMenu[i];
				openMenus[openMenus.length] = menuID;
				if (i < (selectedMenu.length -1)) menuID = menuID + "-";
			}
			//alert(menuID);

			for (i = 0; i < menuIDs.length; i++) {
				var open = false;
				for (j = 0; j < openMenus.length; j++) {
					//alert(menuIDs[i] + " - menu-" + openMenus[j]);
					if (menuIDs[i] == "menu-"+openMenus[j]) {
						open = true;
					}
				}
				if (!open) {
					var menuBlock = document.getElementById(menuIDs[i] + "-block");
					if (menuBlock != null) {
						menuBlock.style.display = "none";
					}
				}
			}
		}

		function keepOpen(menuID) {
			//closeTime = null;
			var menuPath = menuID.split("-");
			selectedMenu = new Array();
			for (var i = 1; i < menuPath.length; i++) {
				selectedMenu[i -1] = menuPath[i];
			}
		}
