function clearPx(value){
	if (value.substr(value.length -2 ,value.length) == 'px'){
  	value = value.substr(0 ,value.length -2 );
  }
  return value;
}

function getCleanMenuHeight(TabEl){
	var cleanHeight 	= TabEl.offsetHeight;

	var marginTop 		= clearPx(TabEl.style.marginTop);
	var marginBottom 	= clearPx(TabEl.style.marginBottom);
	var paddingTop 	= clearPx(TabEl.style.paddingTop);
	var paddingBottom = clearPx(TabEl.style.paddingBottom);
  
	cleanHeight -= marginTop;
	cleanHeight -= marginBottom;
	cleanHeight -= paddingTop;
	cleanHeight -= paddingBottom;
	
	return cleanHeight;
}

var mainHeight = 0;

function resizeMenuContent(ulElementId, aLink, state){	
	if(state == 'open'){
		aLink.onclick 	= function(){ resizeMenuContent(ulElementId, aLink, 'close')};
		aLink.innerHTML= 'sluiten';
		aLink.className= 'close';
		aLink.blur();
	}else{
		aLink.onclick 	= function(){ resizeMenuContent(ulElementId, aLink, 'open')};
		aLink.innerHTML= 'meer onderwerpen';
		aLink.className= 'more';
		aLink.blur();
	}

	currentTab = document.getElementById(ulElementId);
	
	if(mainHeight == 0) mainHeight = clearPx(currentTab.style.height);
	
	if(currentTab.anim && currentTab.anim.isAnimated()) currentTab.anim.stop(true);
	
	var oldHeight = YAHOO.util.Dom.getStyle(currentTab, 'height');
	if(oldHeight == 'auto') oldHeight = getCleanMenuHeight(currentTab)+'px';

	//Temporarily set it to its actual height, read it and set it back.
	YAHOO.util.Dom.setStyle(currentTab, 'height', 'auto');  
	var newHeight = getCleanMenuHeight(currentTab);
	
	// actual height inc padding
	if(state == 'open'){
		if(newHeight <= mainHeight){
			newHeight = mainHeight;
		}else{
			newHeight = newHeight + 5;
		}
	}else{
		var newHeight = mainHeight;
	}

	YAHOO.util.Dom.setStyle(currentTab, 'height', oldHeight); 
	
	//Start the animation       
	doAnim(currentTab, newHeight);
};

function doAnim(currentTab, newHeight){ 
	currentTab.anim = currentTab.anim || new YAHOO.util.Anim(currentTab);
	currentTab.anim.duration = 0.5;
	currentTab.anim.attributes.height = {to: newHeight};
	currentTab.anim.method = YAHOO.util.Easing.easeOutStrong; 
	currentTab.anim.animate();
}