//
// Schiebe-Menu
//
// c2008 Uli Schmidts
//

var speed = 10;	// Framedauer in msec
var step = 5;	// Pixel pro Frame

function showSubmenu(m){
	subNr = m.id.substring(1, m.id.length);
	subMenu = document.getElementById("s"+subNr);
	animateStart(subNr, 1);
}

function hideSubmenu(m){
	subNr = m.id.substring(1, m.id.length);
	subMenu = document.getElementById("s"+subNr);
	animateStart(subNr, -1);
}

function animateStart(subNr, dir){
	subMenu = document.getElementById("s"+subNr);
	subMenu.anim = dir;
	animateStep(subNr, dir);
}

function animateStep(subNr, dir){
	subMenu = document.getElementById("s"+subNr);
	if(subMenu.anim != 0){
		stepDone = false;
		if(subMenu.anim > 0){	// oeffnen
			if (subMenu.h < subMenu.h2){
				subMenu.h = subMenu.h + step;
				stepDone = true;
			}
		}else{					// schliessen
			if (subMenu.h > subMenu.h1){
				subMenu.h = subMenu.h - step;
				stepDone = true;
			}
		}
		if(stepDone){	// step durchfuehren
			subMenu.style.height = "" + subMenu.h + "px";
			setTimeout("animateStep(" + subNr + ", " + dir + ")", speed);
		}else{
			subMenu.anim = 0;
		}
	}
}


function getSubHeight(subMenu){
	//itemHeight = 24;	// Hoehe eines Items (wie im css)
	subCount = subMenu.childNodes.length;
	subCountReal = 0;
	for(i=0;i<subCount;i++){
		if(subMenu.childNodes[i].tagName == "DIV"){	// nur divs zaehlen
			//subCountReal++;
			subCountReal = subCountReal + subMenu.childNodes[i].clientHeight;
		}
	}
	return subCountReal+ 4;
}

function init(){	// alle submenus init
	for(var i=1;i<10;i++){
		if(document.getElementById("s"+i)){
			subMenu = document.getElementById("s"+i);
			subMenu.h = 1;
			subMenu.anim = 0;
			subMenu.h1 = 1;
			subMenu.h2 = getSubHeight(subMenu);
		}
	}
	activateMenu();
}

function activateMenu(){
	if(typeof(activeMenu)!= "undefined"){
   		if (activeMenu != "" && activeMenu > 0 && activeMenu != " "){
			as = document.getElementById("s_");
     		as.childNodes[activeMenu-1].style.background = "#f2f2ed";
     		//bild = "m" + activeMenu;
     		//document[bild].src = eval("p" + activeMenu + "o.src");
		}
    }
}


window.onload = init;

