// params
if (!SPEED)
	var SPEED = 2;
if (!TIMER)
	var TIMER = 1;
if (!MAXOPACITY)
	var MAXOPACITY = 1; // ranges 0 - 1
	
// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else{
      c.style.display = 'block';
     if(!c.maxh) c.maxh = c.offsetHeight;
      c.style.height = '2px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},TIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

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

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

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;  
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / SPEED));
  }else{
    dist = (Math.round(currh / SPEED));
  }
  if(dist < 1){
    dist = 1;
  }
  var height = currh + (dist * d);
  
  if((height < 2 && d != 1) || (height > (c.maxh - 2) && d == 1)){
	clearInterval(c.timer);
	if (d != 1) c.style.display = 'none';
  } else {
	  c.style.height = height  + 'px';
  }
  /*if (navigator.platform != 'MacPPC' || navigator.userAgent.search('Firefox/2.') == -1) { // no opacity for firefox2 on mac
	c.style.opacity = (currh / c.maxh) * MAXOPACITY;
	c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) * MAXOPACITY + ')';	
  }*/
}