
var menuItemIDClicked = null;

function EZMenu () {
	
	this.id = 0;
	this.container = null;
	this.cellid = 0;
	this.menuType = 1;
	this.toplevel = true
	this.itemsToplevel = 1;
	
	//skal kende properties på container
	this.borderTop = 0
	this.borderLeft = 0
	this.borderRight = 0
	this.borderBottom = 0
	
	this.paddingTop = 0
	this.paddingLeft = 0
	this.paddingRight = 0
	this.paddingBottom = 0
	
	this.level1 = new menuLevel();
	this.level2 = new menuLevel();
		
}

function menuBehavior() {
	this.menu = new Canvas()
	this.menuitem = new Canvas()
	this.menuitem.font = new Font()
	this.picture = new Canvas()
	this.picture.image = new Image()
}


function menuLevel () {
	this.inactive = new menuBehavior()
	this.hover = new menuBehavior()
	this.iconShowAlways = false
	this.iconAlign = "right"
}


function Image() {
	this.src = ""
	this.width = ""
	this.height = ""
	this.align = "right"
}

function Font() {
	this.fontFamily = ""
	this.fontSize = ""
	this.color = ""
	this.fontWeight = ""
	this.textDecoration = ""
}


function Canvas() {

	this.width = ""
	this.height = ""
	
	this.color = ""
	this.background = ""
	this.backgroundColor = ""
	
	this.borderWidth = ""
	
	this.borderTopWidth = ""
	this.borderBottomWidth = ""
	this.borderLeftWidth = ""
	this.borderRightWidth = ""
	
	this.borderColor = ""
	
	this.borderTopColor = ""
	this.borderBottomColor = ""
	this.borderLeftColor = ""
	this.borderRightColor = ""

	this.marginTop = ""
	this.marginBottom = ""
	this.marginLeft = ""
	this.marginRight = ""
	
	this.paddingTop = ""
	this.paddingBottom = ""
	this.paddingLeft = ""
	this.paddingRight = ""
	
	this.textAlign = ""
	
	this.font = null
	this.image = null
}

function offsetX (MyEZMenu) {
	var x = 0
	obj = MyEZMenu.container
	
	while (obj.tagName != "BODY") {
		if (obj.tagName == "TD") {
			x += CZero(obj.style.borderLeftWidth)
		}
		x += obj.offsetLeft
		obj = obj.offsetParent
	}
	
	x += MyEZMenu.borderLeft
	x += MyEZMenu.paddingLeft
	
	return x;
}


function offsetY (MyEZMenu) {
	var y = 0
	obj = MyEZMenu.container
	
	while (obj.tagName != "BODY") {
		if (obj.tagName == "TD") {
			y += CZero(obj.style.borderTopWidth)
		}
		y += obj.offsetTop
		obj = obj.offsetParent
	}
	y += MyEZMenu.borderTop
	//skal ikke bruges længere
	//y += MyEZMenu.paddingTop
	
	return y;
}

function adjustMenu() {
	
	if (!document.getElementById) return
	
	if ((curEZMenu.level1.inactive.menuitem.width == '') && (curEZMenu.menuType == 2)) {
	
		var menuitemsTotalWidth	= 0
		menuitemsTotalWidth = docall('HM_Menu' + curEZMenu.id).offsetWidth
		menuitemsTotalWidth -= CZero(curEZMenu.level1.inactive.menu.borderLeftWidth)
		menuitemsTotalWidth -= CZero(curEZMenu.level1.inactive.menu.borderRightWidth)
		menuitemsTotalWidth -= CZero(curEZMenu.level1.inactive.menu.marginLeft)
		menuitemsTotalWidth -= CZero(curEZMenu.level1.inactive.menu.marginRight)
		menuitemsTotalWidth -= CZero(curEZMenu.level1.inactive.menu.paddingLeft)
		menuitemsTotalWidth -= CZero(curEZMenu.level1.inactive.menu.paddingRight)

		curEZMenu.level1.inactive.menuitem.width = Math.floor((menuitemsTotalWidth/curEZMenu.itemsToplevel))
		curEZMenu.level1.inactive.menuitem.width -= curEZMenu.level1.inactive.menuitem.marginLeft 
		curEZMenu.level1.inactive.menuitem.width -= curEZMenu.level1.inactive.menuitem.marginRight
		
	}
	
	if (curEZMenu.level2.inactive.menuitem.width == '') {
		curEZMenu.level2.inactive.menuitem.width = curEZMenu.level2.inactive.menu.width
	}
	
}

function adjustMenu40() {

	if (curEZMenu.menuType == 2) {
	
		//Check if menuitem.width is set
		//if (CZero(getStyleClass('menu' + curEZMenu.menuType + 'level1inactivemenuitem').style.width)!=0) return		
	
		var menuitemsTotalWidth
				
		menuitemsTotalWidth = document.getElementById('HM_Menu' + curEZMenu.id).offsetWidth
		
		menuitemsTotalWidth -= CZero(getStyleClass('menu' + curEZMenu.menuType + 'level1inactivemenu').style.borderLeftWidth)
		menuitemsTotalWidth -= CZero(getStyleClass('menu' + curEZMenu.menuType + 'level1inactivemenu').style.borderRightWidth)
		menuitemsTotalWidth -= CZero(getStyleClass('menu' + curEZMenu.menuType + 'level1inactivemenu').style.marginLeft)
		menuitemsTotalWidth -= CZero(getStyleClass('menu' + curEZMenu.menuType + 'level1inactivemenu').style.marginRight)
		menuitemsTotalWidth -= CZero(getStyleClass('menu' + curEZMenu.menuType + 'level1inactivemenu').style.paddingLeft)
		menuitemsTotalWidth -= CZero(getStyleClass('menu' + curEZMenu.menuType + 'level1inactivemenu').style.paddingRight)
		
		
		
		//menuitemsTotalWidth -= CZero(curEZMenu.level1.inactive.menu.borderLeftWidth)
		//menuitemsTotalWidth -= CZero(curEZMenu.level1.inactive.menu.borderRightWidth)
		//menuitemsTotalWidth -= CZero(curEZMenu.level1.inactive.menu.marginLeft)
		//menuitemsTotalWidth -= CZero(curEZMenu.level1.inactive.menu.marginRight)
		//menuitemsTotalWidth -= CZero(curEZMenu.level1.inactive.menu.paddingLeft)
		//menuitemsTotalWidth -= CZero(curEZMenu.level1.inactive.menu.paddingRight)
				
		//curEZMenu.level1.inactive.menuitem.width = 150	
		
		curEZMenu.level1.inactive.menuitem.width = Math.floor((menuitemsTotalWidth/curEZMenu.itemsToplevel))
		curEZMenu.level1.inactive.menuitem.width -= CZero(getStyleClass('menu' + curEZMenu.menuType + 'level1inactivemenuitem').style.marginLeft)
		curEZMenu.level1.inactive.menuitem.width -= CZero(getStyleClass('menu' + curEZMenu.menuType + 'level1inactivemenuitem').style.marginRight)
		
		curEZMenu.level1.inactive.menuitem.width -= curEZMenu.level1.inactive.menuitem.marginLeft 
		curEZMenu.level1.inactive.menuitem.width -= curEZMenu.level1.inactive.menuitem.marginRight
		
	}
	
	if (curEZMenu.level2.inactive.menuitem.width == '') {
		curEZMenu.level2.inactive.menuitem.width = curEZMenu.level2.inactive.menu.width
	}
	
}

function GetProperty(p1, p2) {
	var value;
	if (String(p2)!='') value = p2; else value = p1;
	return value;
}


function CZero (str) {
	if (str != '') str = parseInt(str)
	if (str == '') str = 0
	return str
}

function getEZMenu(id) {

	//Filter fx. 3_3_2 -> 3
	
	var myId = new String(id)
	var newId = ""
	var top = true
	
	//a(id)
	
	for (var i=0; i<myId.length; i++) {
		if (myId.charAt(i) != "_") {
			newId += myId.charAt(i)
		} 
		else {
			top = false
			break
		}
	}
	
	var myEZMenu
		
	for (i=0; i<EZMenues.length; i++) {
		if (typeof(EZMenues[i]) == "object") {
			if (EZMenues[i].id == newId) {
				myEZMenu = EZMenues[i]
				myEZMenu.toplevel = top
				break
			}
		}
	}
	return myEZMenu
}


function docall(id) {	
	if (document.getElementById) return document.getElementById(id)
	else if (document.getElementById) return document.getElementById(id)
}


function getStyleClass (className) {
	if (document.getElementById) {
		for (var s = 0; s < document.styleSheets.length; s++)
			for (var r = 0; r < document.styleSheets[s].rules.length; r++)
				if (document.styleSheets[s].rules[r].selectorText == '.' + className)							
				return document.styleSheets[s].rules[r];
	}else if (document.getElementById) {
		for (var s = 0; s < document.styleSheets.length; s++)
			for (var r = 0; r < document.styleSheets[s].cssRules.length;r++)
				if (document.styleSheets[s].cssRules[r].selectorText == '.' + className)
					return document.styleSheets[s].cssRules[r];
	} 
	return null;
}










