var nrofMenus = 2;
var closing_Height = 30;	//height of topimages, adjusts position where the animation stops when closing
var	top_Subbuttons = 30;	//position of topbuttons, compared to topmenus. adjusts position where the animation stops when opening
var divtop;
var index = -1;
function childMouseout(e) {
	var tarG;
	if(!e) var e =window.event;
	if(e.target) tarG = e.target;
	if(e.toElement) tarG = e.toElement;
	eventToClass = (tarG)?tarG.className:"undefined";
	if(eventToClass!="topbut" && eventToClass!="topsubs")return false;
	else return true;
}
function opeN(num){
  if (divtop != null && divtop!="undefined" && divtop.length > 0){
     if(divtop[num].curr_height < divtop[num].open_height){
		divtop[num].curr_height+=3;
		divtop[num].style.height = divtop[num].curr_height +"px";
		if(divtop[num].doClose!=true){
			setTimeout("opeN("+num+")",20);
		}
	}
  }
}
function closE(num){
  if (divtop != null && divtop!="undefined"&& divtop.length > 0){
	if(divtop[num].curr_height > divtop[num].close_height){
		divtop[num].curr_height-=3;
		divtop[num].style.height = divtop[num].curr_height + "px";
		setTimeout("closE("+num+")",20);
	}
  }
}
function closeRest(num){
  if (divtop != null && divtop!="undefined"&& divtop.length > 0){
	for(var i=0; i < nrofMenus; i++){
		if(num!='all'){
			if(i!=num){
				closE(i);
				if(index != i) divtop[i].ImG.setAttribute("src",divtop[i].ImGout);
				divtop[i].doClose=true;
			}
		}else{
			closE(i);
			if(i != index)divtop[i].ImG.setAttribute("src",divtop[i].ImGout);
			divtop[i].doClose=true;
		}
	}
  }
}
function togglE(action,num){
  if (divtop != null && divtop!="undefined"&& divtop.length > 0){
	if(action=="open"){
		divtop[num].doClose=false;
		divtop[num].ImG.setAttribute("src",divtop[num].ImGover);
		opeN(num);
		closeRest(num);
	}else if(action=="close"){
		if(!childMouseout()){
			divtop[num].doClose=true;
			if(num != index)	divtop[num].ImG.setAttribute("src",divtop[num].ImGout);
			closE(num);
		}
	}
  }
}


function init_topmenu(newIndex){
	index = newIndex;
	divtop = new Array();
		for(var i=0; i<nrofMenus; i++){
				divtop[i] = document.getElementById("topmenu_top"+i);
		divtop[i].open_height = top_Subbuttons + document.getElementById("topsubs"+i).offsetHeight;;
		divtop[i].close_height = closing_Height;
		divtop[i].curr_height = divtop[i].close_height;
		divtop[i].doClose=false;
		divtop[i].ImG = document.getElementById("image"+i);
		divtop[i].ImGover= eval("topmenu_img_rollout"+i);
		divtop[i].ImGout= eval("topmenu_img_rollover"+i);

	}
}
