var timeout = 5; // time out used for animations

var d = document;

function subNav(l){
		var mLi = l.parentNode.getElementsByTagName("LI");
		var tD = null;
		if (document.uniqueID && document.compatMode && !window.XMLHttpRequest && document.execCommand)   
        document.execCommand('BackgroundImageCache', false, true);	
		for(var p = 0; p < mLi.length; p++){
			if(l.parentNode.parentNode.getAttribute("subLevelIn") == "subLevelIn"){
				return false;
			}
			if(mLi[p].className == "actSubNav" && mLi[p].parentNode == l.parentNode){
				var tD = mLi[p];
			}
		};

		if(l.className == "subLevel"){			

			l.setAttribute("subLevelIn", "subLevelIn");

			if(tD != null){				
				var LIold = tD.getElementsByTagName("UL");
				for(var n = 0; n < LIold.length; n++){
					if(LIold[n].className == "subList" && LIold[n].parentNode.parentNode == tD.parentNode){
						var ULold = LIold[n];					
					};
				};
				var LInew = l.getElementsByTagName("UL");
				for(var e = 0; e < LInew.length; e++){
					if(LInew[e].className == "subList" && LInew[e].parentNode.parentNode == tD.parentNode){
						var ULnew = LInew[e];					
					}
				}
				tD.className = "subPenLevel";
				l.className = "actSubNav";				
				var hh = ULnew.offsetHeight;
				ULnew.style.height = 0; 
				if(hh >= ULold.offsetHeight){
					var HT = ULold.offsetHeight;
				}else{
					var HT = hh;
				}
				window.tMoveOp = setTimeout(function(){moveOpenNew(ULnew,1,hh,ULold,ULold.offsetHeight,HT)},timeout);
			}else{
				var ULLs = l.getElementsByTagName("UL");
				for(var e = 0; e < ULLs.length; e++){
					if(ULLs[e].className == "subList" && ULLs[e].parentNode.parentNode == l.parentNode){
						var Ullka = ULLs[e];						
					};
				};				
				l.className = "actSubNav";		
				var hh = Ullka.offsetHeight;			
				Ullka.style.height = 0;
				window.tMoveOp = setTimeout(function(){moveOpen(Ullka,1,hh)}, timeout);
			}
		}
}

function moveClose(oldL,oldLH){	
	if(oldLH > 10){
		var nH = oldLH - 10;
		oldL.style.height = nH + "px";
		setTimeout(function(){moveClose(oldL,nH)}, timeout)
	}else if(oldLH >= 1){		
		var nH = oldLH - 1;
		oldL.style.height = nH + "px";
		setTimeout(function(){moveClose(oldL,nH)}, timeout)		
	}else{
		clearTimeout(window.hMenu);
		window.anchorCl = false;
		oldL.parentNode.className = "subLevel";
		oldL.style.height = "auto";	
		var sLIs = oldL.getElementsByTagName("LI");
		for(var e = 0; e < sLIs.length; e++){
			if(sLIs[e].className == "actSubNav"){
				sLIs[e].className = "subLevel"						
			};
		};		
	}
}

function moveOpen(oldL,oldLH,hh){
	if(oldLH < hh - 10){
		var nH = oldLH + 10;
		oldL.style.height = nH + "px";
		setTimeout(function(){moveOpen(oldL,nH,hh)}, timeout)
	}else if(oldLH <= hh){
		var nH = oldLH + 1;
		oldL.style.height = nH + "px";
		setTimeout(function(){moveOpen(oldL,nH,hh)}, timeout)		
	}else{		
		oldL.style.height = "auto";	
		oldL.parentNode.setAttribute("subLevelIn", "false");
	}
}

function moveOpenNew(oldL,oldLH,hh,s,sH,HT){
	if(hh > HT){
		if(sH > 9){
			var nH = oldLH + 10;
			var nM = sH - 10;
			oldL.style.height = nH + "px";
			s.style.height = nM + "px";
			setTimeout(function(){moveOpenNew(oldL,nH,hh,s,nM,HT)}, timeout)
		}else{
			s.parentNode.className = "subLevel";
			s.style.height = "auto";			
			setTimeout(function(){moveOpen(oldL,oldLH,hh)}, timeout)	
		}
	}else{
		if(oldLH < hh && sH - 10 > 0){
			var nH = oldLH + 10;
			var nM = sH - 10;
			oldL.style.height = nH + "px";
			s.style.height = nM + "px";			
			setTimeout(function(){moveOpenNew(oldL,nH,hh,s,nM,HT)}, timeout);						
		}else{			
			oldL.style.height = "auto";
			oldL.parentNode.setAttribute("subLevelIn", "false");
			setTimeout(function(){moveClose(s,sH)}, timeout);
		};
	}
}

function hideNav(mmU){
	var mU = d.getElementById(mmU);
	var LInew = mU.getElementsByTagName("UL");
	for(var e = 0; e < LInew.length; e++){
		if(LInew[e].parentNode.parentNode == mU && LInew[e].parentNode.className == "actSubNav" && window.anchorCl != true){
				window.anchorCl = true;
				var LaL = LInew[e];
				window.hMenu = setTimeout(function(){moveClose(LaL,LaL.offsetHeight)},100);					
		}
	};
}

