var DOWNSPEED = 10;
var DOWNTIMER = 15;

function newnavMenu(id,d){
  var head = document.getElementById(id + '-downheader');
  var content = document.getElementById(id + '-downcontent');
  clearInterval(content.timer);
  if(d == 1){
    clearTimeout(head.timer);
    if(content.maxh && content.maxh <= content.offsetHeight){return}
    else if(!content.maxh){
      content.style.display = 'block';
      content.style.height = 'auto';
      content.maxh = content.offsetHeight;
      content.style.height = '0px';
    }
    content.timer = setInterval(function(){downSlide(content,1)},DOWNTIMER);
  }else{
    head.timer = setTimeout(function(){downCollapse(content)},50);
  }
}

function downCollapse(content){
  content.timer = setInterval(function(){downSlide(content,-1)},DOWNTIMER);
}

function cancelIt(id){
  var head = document.getElementById(id + '-downheader');
  var content = document.getElementById(id + '-downcontent');
  clearTimeout(head.timer);
  clearInterval(content.timer);
  if(content.offsetHeight < content.maxh){
    content.timer = setInterval(function(){downSlide(content,1)},DOWNTIMER);
  }
}

function downSlide(content,d){
  var currh = content.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((content.maxh - currh) / DOWNSPEED));
  }else{
    dist = (Math.round(currh / DOWNSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  content.style.height = currh + (dist * d) + 'px';
  content.style.opacity = currh / content.maxh;
  content.style.filter = 'alpha(opacity=' + (currh * 100 / content.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (content.maxh - 2) && d == 1)){
    clearInterval(content.timer);
  }
}