function showPosition(id){

	position = document.getElementById(id);

	position.style.display='block';

}



var menuIndex = -1;

var menus = new Array();



function createMenu(openRight){

	if (!currentMenuId) {

		alert(1);

		return;

	} else {

		menus[++menuIndex] = new DynamicMenu('menu_'+currentMenuId,menuIndex,openRight);

		delete currentMenuId;

	}

}





function DynamicMenu(menuId,menuIndex,openRight){

	

	

	var interval=null;

	var menuIndex=menuIndex;

	this.menu = document.getElementById(menuId);



	this.menu.id='menu_'+menuIndex;



	this.buttons = this.menu.childNodes;

	var children = new Array();

	

	var submenusWidth = new Array();

	

	for (var i=0;i<this.buttons.length;i++){

		if (!isNaN(this.buttons[i].id) && this.buttons[i].id>0 ){

			children.push(this.buttons[i]);

		}

	}
	function getInternetExplorerVersion() {

	    var rv = -1; // Return value assumes failure.
	
	    if (navigator.appName == 'Microsoft Internet Explorer') {
	
	        var ua = navigator.userAgent;
	
	        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	
	        if (re.exec(ua) != null)
	
	            rv = parseFloat(RegExp.$1);
	
	    }
	
	    return rv;
	
	}
	this.showSubMenu = function(){

		

		currentItems = new Array();

		var regulated = true;

		

		clearTimeout(interval);

		this.hideAll(this.menuLevel);

		

		var prevHeight = 0;

		for (var i=0;i<children.length;i++){

//		for (var i in children){

			if (children[i].getAttribute('parent_id')==this.id){

				children[i].style.display='block';

				

				children[i].menuLevel = this.menuLevel+1;

				

				var offsetLeft=this.offsetLeft;;

				var offsetTop=this.offsetTop;;
				

				if (!this.getAttribute('parent_id')>0 && document.all){
					
					//offsetLeft=getOffsetPropertyInIE(this,'offsetLeft');
					offsetLeft=this.offsetParent.offsetLeft+this.offsetLeft;
					if(getInternetExplorerVersion()>=8){
						offsetTop=this.offsetParent.offsetTop+this.offsetTop;
					}else{
						offsetTop=getOffsetPropertyInIE(this,'offsetTop');
					}

				}

				

				if (this.getAttribute('parent_id')>0 || openRight){

					children[i].style.left=(offsetLeft + this.offsetWidth) + 'px';

					children[i].style.top=(offsetTop + prevHeight) +'px';

				} else {

					children[i].style.left=offsetLeft + 'px';

					children[i].style.top=(offsetTop + this.offsetHeight + prevHeight) +'px';

				}

				prevHeight+=children[i].offsetHeight;

				

				currentItems.push(children[i]);

			}

		}

		this.regulateWidths(currentItems);

		

	}

	

	this.regulateWidths = function(items){

		

		var maxWidth=0;

		for (var i=0;i<items.length;i++){

//		for (i in items){

			if (items[i].regulated){

				return;

			}

			if (maxWidth < items[i].offsetWidth){

				maxWidth = items[i].offsetWidth;

			}

		}

		if (maxWidth<100)

			maxWidth=100;

		for (var i=0;i<items.length;i++){

//		for (i in items){

			items[i].style.width=maxWidth+'px';

			items[i].regulated=true;

		}

	}

	

	this.hideAll = function(level){

//		for (var i in children){

		for (var i=0;i<children.length;i++){

			if (children[i].menuLevel>level){

				children[i].style.display='none';

			}

		}

	}

	

	this.hideSubMenu = function(){

		interval = setTimeout("menus["+menuIndex+"].hideAll(0)",1000);

	}

	



	

//	for (var i in children){

	for (var i=0;i<children.length;i++){

		children[i].menuLevel=0;

		children[i].style.zIndex=1000000+i;

		children[i].hideAll=this.hideAll;

		children[i].regulateWidths=this.regulateWidths;

		children[i].onmouseover = this.showSubMenu;

		children[i].onmouseout = this.hideSubMenu;

	}

}



function getOffsetPropertyInIE(node,property){

	var n = node;

	

	var val = n[property];


	while (n.parentNode && n.parentNode.parentNode && n.parentNode.parentNode){

		

		n = n.parentNode;

		if (!isNaN(n[property])){

			val+=n[property];

		}
		
	}
	return val;

}

