var dropdown_DDSPEED = 10;
var dropdown_DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(dropdown_id,dropdown_d){
  var dropdown_h = document.getElementById(dropdown_id + '-ddheader');
  var dropdown_c = document.getElementById(dropdown_id + '-ddcontent');
  clearInterval(dropdown_c.timer);
  if(dropdown_d == 1){
    clearTimeout(dropdown_h.timer);
    if(dropdown_c.maxh && dropdown_c.maxh <= dropdown_c.offsetHeight){return}
    else if(!dropdown_c.maxh){
      dropdown_c.style.display = 'block';
      dropdown_c.style.height = 'auto';
      dropdown_c.maxh = dropdown_c.offsetHeight;
      dropdown_c.style.height = '0px';
    }
    dropdown_c.timer = setInterval(function(){ddSlide(dropdown_c,1)},dropdown_DDTIMER);
  }else{
    dropdown_h.timer = setTimeout(function(){ddCollapse(dropdown_c)},50);
  }
}

// collapse the menu //
function ddCollapse(dropdown_c){
  dropdown_c.timer = setInterval(function(){ddSlide(dropdown_c,-1)},dropdown_DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(dropdown_id){
  var dropdown_h = document.getElementById(dropdown_id + '-ddheader');
  var dropdown_c = document.getElementById(dropdown_id + '-ddcontent');
  clearTimeout(dropdown_h.timer);
  clearInterval(dropdown_c.timer);
  if(dropdown_c.offsetHeight < dropdown_c.maxh){
    dropdown_c.timer = setInterval(function(){ddSlide(dropdown_c,1)},dropdown_DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(dropdown_c,dropdown_d){
  var dropdown_currh = dropdown_c.offsetHeight;
  var dropdown_dist;
  if(dropdown_d == 1){
    dropdown_dist = (Math.round((dropdown_c.maxh - dropdown_currh) / dropdown_DDSPEED));
  }else{
    dropdown_dist = (Math.round(dropdown_currh / dropdown_DDSPEED));
  }
  if(dropdown_dist <= 1 && dropdown_d == 1){
    dropdown_dist = 1;
  }
  dropdown_c.style.height = dropdown_currh + (dropdown_dist * dropdown_d) + 'px';
  dropdown_c.style.opacity = dropdown_currh / dropdown_c.maxh;
  dropdown_c.style.filter = 'alpha(opacity=' + (dropdown_currh * 100 / dropdown_c.maxh) + ')';
  if((dropdown_currh < 2 && d != 1) || (dropdown_currh > (dropdown_c.maxh - 2) && dropdown_d == 1)){
    clearInterval(dropdown_c.timer);
  }
}