            function tween(id, start, end, millisec, delay, effect) {
            	if (!effect) {
            		changeH(end, id);
            		return;
            	}
            	
                //speed for each frame
                var speed = Math.round(millisec / 100);
                var timer = 0;

                //determine the direction for the blending, if start and end are the same nothing happens
                if(start > end) {
                    for(i = start; i >= end; i--) {
                    	time = (timer++ * speed)+delay;
                        setTimeout("changeH(" + i + ",'" + id + "')",time);
                    }
                } else if(start < end) {
                    for(i = start; i <= end; i++) {
                    	time = (timer++ * speed)+delay;
                        setTimeout("changeH(" + i + ",'" + id + "')",time);
                    }
                }
                
                if (time > movetime)
                	movetime = time;
                
            }

           function changeH(h, id) {
              document.getElementById(id).style.height = h+"px";              
            }

            function abaControl(aba, nivel, effect) {
            	if (!moving || !effect) {
            		moving = true;
	            	move(aba, nivel, effect);

	            	if (effect) { 
		            	//contrai os pais para nao ficar buraco vazio abaixo
		            	fim = 0;
		            	for (var i=nivel-1; i>=0; i--) {
		            		fim += menuQtd[last[i]];
		            		tween("menu"+last[i], document.getElementById("menu"+last[i]).offsetHeight, fim, speed, 0, effect);
		            	}
	            	}
	            	setTimeout("moving=false", movetime);
	            	setTimeout("movetime=0", movetime);
            	}
            	
            }
            
            function move(aba, nivel, effect) {
              speed = 150;
              delay = 0;
              
              //fecha a ultima aba aberta no mesmo nivel
              if (last[nivel]) {
            	  
            	//calcula a demora para esconder (assim nao corta na metade do slide)
                delay = document.getElementById("menu"+last[nivel]).offsetHeight * Math.round(speed / 100);

                tween("menu"+last[nivel], document.getElementById("menu"+last[nivel]).offsetHeight, 0, speed, 0, effect);
                setTimeout('document.getElementById("label'+last[nivel]+'").style.backgroundPosition = "top"', 0);
//                setTimeout('document.getElementById("menu'+last[nivel]+'").style.display = "none"', delay);
              }
              
              //fecha as abas abertas dentro da arvore da aba
              if (last[nivel+1])
                move(last[nivel+1], nivel+1, effect);
              
              if (aba != last[nivel]) {
        	    //esta abrindo outra aba
                setTimeout('document.getElementById("label'+aba+'").style.backgroundPosition = "bottom"', 0);
//                setTimeout('document.getElementById("menu'+aba+'").style.display = "block"', 0);
                tween("menu"+aba, 0, menuQtd[aba], speed, 0, effect);
                last[nivel] = aba;

                //expande os pais para nao ter overflow hidden
                total = 0;
                for (var i=nivel; i>=0; i--) {
                  total += menuQtd[last[i]];
                  tween("menu"+last[i], document.getElementById("menu"+last[i]).offsetHeight, total, speed, 0, effect);
                }
                
              } else {
            	//esta fechando a aba
            	  
            	  /*
	              total = 0;
	              for (var i=nivel-1; i>=0; i--) {
	                total += menuQtd[last[i]];
	              }

                  //contrai o pai para nao ficar buraco vazio abaixo
	              tween("menu"+last[0], document.getElementById("menu"+last[0]).offsetHeight, total, speed, 0, effect);
	              */
            	  
            	  last[nivel] = null;
              }
              

              
            }
            
