var DDSPEED = 10;
var DDTIMER = 15;

function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  clearInterval(h.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(h.maxh && h.maxh <= h.offsetHeight){return}
    else if(!h.maxh){
      h.style.height = 'auto';
      h.maxh = h.offsetHeight;
      h.style.height = '29px';
    }
    h.timer = setInterval(function(){ddSlide(h,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(h)},50);
  }
}

// collapse the menu //
function ddCollapse(h){
  h.timer = setInterval(function(){ddSlide(h,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  clearTimeout(h.timer);
  if(h.offsetHeight < h.maxh){
    h.timer = setInterval(function(){ddSlide(h,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(h,d){
  var currh = h.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((h.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  h.style.height = currh + (dist * d) + 'px';
//  h.style.opacity = currh / h.maxh;
//  h.style.filter = 'alpha(opacity=' + (currh * 100 / h.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (h.maxh - 2) && d == 1)){
    clearInterval(h.timer);
  }
}

function ddMenu2(id,c){
  var h = document.getElementById(id + '-ddheader');
  clearInterval(h.timer);
  if (h.maxh <= h.offsetHeight){
	  var d = c}
	  else {
		  var d = (c*c)
	  }
  if(d == 1){
    clearTimeout(h.timer);
    if(h.maxh && h.maxh <= h.offsetHeight){return}
    else if(!h.maxh){
      h.style.height = 'auto';
      h.maxh = h.offsetHeight;
      h.style.height = '29px';
    }
    h.timer = setInterval(function(){ddSlide(h,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(h)},50);
  }
}