var height_uit = 0;
var height_in = 100;

//INSCHUIVEN MENU
function SubMenuIn(item_oud, item_nieuw, aantal_nieuw, loc_nieuw){

	height_in = height_in - 1000;
	if(height_in < 0) height_in = 0;

	var divbg = document.getElementById("bgsubmenu" + item_oud);
	var submenu = document.getElementById("item" + item_oud);

	divbg.style.background = "white";
	divbg.style.height = height_in + "px";

	if(height_in > 0) setTimeout("SubMenuIn("+item_oud+", "+item_nieuw+", "+aantal_nieuw+", '"+loc_nieuw+"')", 1);

	if(height_in == 0){
 		divbg.style.display = "none";
 		submenu.style.background = "none";
 		height_in = 100;
 		SubMenuUit(item_nieuw, aantal_nieuw, loc_nieuw);
	}
}

//UITSCHUIVEN MENU
function SubMenuUit(item, aantal, loc){

	var doorgaan = "ja";

	for(i = 1; i<=15; i++){
		if(document.getElementById("submenu" + i) && i != item){

			if(document.getElementById("submenu" + i).style.display == "block" || document.getElementById("submenu" + i).className == "current"){
				var i2 = i;
				document.getElementById("submenu" + i).style.display = "none";
				document.getElementById("bgsubmenu" + i).style.display = "block";
				document.getElementById("submenu" + i).className = "";
				height_uit=0;
				doorgaan = "nee";
				SubMenuIn(i, item, aantal, loc);
			}


		}


	}

	if(doorgaan == "ja" && document.getElementById("bgsubmenu" + item) && document.getElementById("submenu" + item).className != "current"){

		height_uit = height_uit + 15;

		var maxheight= (aantal*20)+10;

		var a = item;
		if(item <= 4) a = 0;
		var marginbgtopleft = 10+a;
		var marginbgbottomleft = 10+a+((aantal*item)/2);

		var divbg = document.getElementById("bgsubmenu" + item);
		var ulsubmenu = document.getElementById("submenu" + item);
		var submenu = document.getElementById("item" + item);

		submenu.style.background = "white url(images/bgsubmenutop2.jpg) no-repeat "+ marginbgtopleft +"px  0px";
		divbg.style.background = "white";
		divbg.style.display = "block";
		
		divbg_height = height_uit;
		if(height_uit >= maxheight) divbg_height = maxheight;

		divbg.style.height = divbg_height + "px";

		if(height_uit < maxheight) setTimeout("SubMenuUit("+item+", "+aantal+", '"+loc+"')", 1);

		if(height_uit >= maxheight){
 			divbg.style.display = "none";
 			ulsubmenu.style.display = "block"
			ulsubmenu.style.height = (maxheight-10) + "px";
			if(document.all) ulsubmenu.style.height = (maxheight+10) + "px";
 			ulsubmenu.style.background = "white  url(images/bgsubmenubottom2.jpg) no-repeat "+ marginbgbottomleft +"px bottom";
			height_in = maxheight-10;
			window.location.href = loc;
		}
	}

	if(doorgaan == "ja" && !document.getElementById("bgsubmenu" + item)) window.location.href = loc;

	if(doorgaan == "ja" && document.getElementById("bgsubmenu" + item) && document.getElementById("submenu" + item).className == "current") window.location.href = loc;

}




