var menuItemHeight = 21;

function parseElements(openMenuId) //menu_20
{
	
	var allMenuElements = $$('#sidebar li');
	if(openMenuId !=''){
		var openMenu = $(''+openMenuId);
		var parentArray = new Array();
		parentArray.push(openMenu);
		while(openMenu.getParent()!=null && openMenu.getParent().getParent() !=null && openMenu.getParent().getParent().getTag() == 'li'){
			openMenu = openMenu.getParent().getParent();
			parentArray.push(openMenu);
		}
		var item;
		var delayTime;
		for(var i=parentArray.length; i>0; i--){
			delayTime = ((parentArray.length-i+0.5)*300);
			item = parentArray[(i-1)];
			toggle.delay(delayTime,item);
		}
	}
}

function parseInfoPanels(){
	var infoPanels = $$('#infoPanel .infoPanel');
	disableSelection(document.getElementById('menuKolom'));
	var fx = new Fx.Elements(infoPanels, {wait: false, duration: 300, transition: Fx.Transitions.quadOut});
	infoPanels.each(function(infoPanel, i){
		infoPanel.addEvent('click', function(e){
			var obj = {};
			obj[i] = {
				'width': [infoPanel.getStyle('width').toInt(), 463]
			};
			infoPanels.each(function(other, j){
				if (other != infoPanel){
					var w = other.getStyle('width').toInt();
					if (w != 100) obj[j] = {'width': [w, 100]};
				}
			});
			fx.start(obj);
		});
	});
}
function getUrl(event,menuId,paginaType,paginaId){
	if (window.event) window.event.cancelBubble=true;
  	else event.stopPropagation();
	self.location.href=''+menuId;
}
function toggle(){
	var theElement = $(this).getElement('ul');
	if(theElement != null && theElement != ''){
		if(theElement.hasClass('showItem')){
			theElement.style.overflow = 'hidden';
			theElement.effect('height', {duration: 300, onComplete: function(item){item.toggleClass('showItem');item.toggleClass('hideItem');},transition:Fx.Transitions.quadOut}).start(theElement.getSize().size.y,0);
		}	
		else{
			var newHeight = getElemHeight(this);
			if(newHeight !== false){ //er is sprake van een uitklapbaar menu
				theElement.style.overflow = 'hidden';
				theElement.style.height = '0px';
				theElement.toggleClass('hideItem');
				theElement.toggleClass('showItem');
				theElement.effect('height', {duration: 300,onComplete: function(item){item.style.height = 'auto';},transition:Fx.Transitions.quadOut}).start(0,newHeight);
			}
			else return;//er is geen sprake van een uitklapbaar menu
		}
	}
	else return;//er is geen sprake van een uitklapbaar menu
}
function getElemHeight(elem){
	var height = 0;
	var firstULElement = $(elem).getElement('ul');
	if(firstULElement != null && firstULElement != '')
		height += firstULElement.getChildren().length*menuItemHeight;
	var allVisibleULElements = $(elem).getElements('ul');
	allVisibleULElements = allVisibleULElements.filterByClass('showItem');
	if(allVisibleULElements != null && allVisibleULElements != ''){
		allVisibleULElements.each(function(item){
			return height += ((item.getChildren()).length*menuItemHeight);
		});
	}
	if(height == 0) return false;
	else return height;
}
function disableSelection(target){
	if (typeof target.onselectstart!="undefined") //IE route
		target.onselectstart=function(){return false}
	else if (target.unselectable)
		target.unselectable = "on"; 
	else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
		target.style.MozUserSelect="none"
	else if (typeof target.style.KhtmlUserSelect !="undefined") //Firefox route
		target.style.KhtmlUserSelect="none"
	else //All other route (ie: Opera)
		target.onmousedown=function(){return false}
	target.style.cursor = "default"
}
