var basic_step=15;
var acceleration=3;

var step;

var open=false;
var opening=false;
var closing=false;

var action=new Array;

var height=new Array;
var rol_menu_timer=false;

function open_rol_menu(id){
  if(isNaN(height[id])){
		document.getElementById('rol_menu_'+id).style.display='block';
		height[id]=document.getElementById('rol_menu_'+id).offsetHeight;
		if((height[id]==4)||(height[id]==18)){ 
			height[id]=0;
			document.getElementById('rol_menu_'+id).style.display='none';
		}
		document.getElementById('rol_menu_'+id).style.height='0px';
	}

	document.getElementById('rol_menu_'+id).style.height=height[id]+'px';
	open=id;

	return false;
}

function click_on_menu(id_num){
	var this_height;

	document.getElementById('rol_menu_section_'+id_num).className='section_open';
	
//	document.getElementById('text').innerHTML='open='+open+'  opening='+opening+'  closing='+closing;

	// velkost elementu (ak je to prvykrat, zisti podla nastaveneho div-u)
	if(isNaN(height[id_num])){
		document.getElementById('rol_menu_'+id_num).style.display='block';
		height[id_num]=document.getElementById('rol_menu_'+id_num).offsetHeight;

  	//document.getElementById('rol_menu_section_'+id_num).innerHTML='ahoj '+height[id_num];

		if((height[id_num]==4)||(height[id_num]==18)){ 
			height[id_num]=0;
			document.getElementById('rol_menu_'+id_num).style.display='none';
		}
		document.getElementById('rol_menu_'+id_num).style.height='0px';
	}		

	// ak sa prave tato teraz otvara
	if(opening==id_num){
		if(closing==false){
			opening=false;
			closing=id_num;
		}
		return false;
	}

	// ak sa prave tato teraz zatvara
	if(closing==id_num){
		closing=false;
		if(open!=false) closing=open;
		if(opening!=false) closing=opening;
		
		opening=id_num;
		return false;
	}

	// ak je nejaka otvorena
	if(open!=false){
		if(closing!=false) return false;  // aby sa nezatvarali 2 veci naraz
		closing=open;
		if(open!=id_num){
			opening=id_num;
			if(height[opening]!=0) document.getElementById('rol_menu_'+opening).style.display='block';
		}
		open=false;
	}else{
		// nie je ziadna otvorena
		if(opening!=false){
			if(closing!=false) return false; // opat by sa mali zatvarat 2 veci naraz
			closing=opening;
		}
		opening=id_num;
		if(height[opening]!=0) document.getElementById('rol_menu_'+opening).style.display='block';
	}

	step=basic_step;

	if(rol_menu_timer==false){
		rol_menu_timer=setInterval('rol_menu_timer_function();',100);
	}

	return false;
}

function rol_menu_timer_function(){
	var this_height, new_height;
	var stop=true;
	
	step=step+acceleration;
	
	if(opening!=false){
		this_height=document.getElementById('rol_menu_'+opening).offsetHeight;
		new_height=this_height+step;
		if(new_height>height[opening]) new_height=height[opening];

		document.getElementById('rol_menu_'+opening).style.height=new_height+'px';
		
		if(new_height==height[opening]){ 
			open=opening; opening=false; 
			if(height[open]==0){
				//if it is empty div... call href...
				document.location=document.getElementById('rol_menu_section_'+open).href;
			}
		}else stop=false;
	}

	if((opening==false)&&(closing!=false)){
		this_height=document.getElementById('rol_menu_'+closing).offsetHeight;
		new_height=this_height-step;
		if(new_height<0) new_height=0;
	
		document.getElementById('rol_menu_'+closing).style.height=new_height+'px';

		if(new_height==0){ 
			document.getElementById('rol_menu_'+closing).style.display='none'; 
			document.getElementById('rol_menu_section_'+closing).className='section';
			closing=false;
		}else{
			stop=false;
		}
	}

//document.getElementById('text2').innerHTML='open='+open+'  opening='+opening+'  closing='+closing';

	if(stop==true){
		clearInterval(rol_menu_timer);
		rol_menu_timer=false;
	}
}