var active_submenu = null;

function fade_element_property(element, property, from, to, step, interval, oncomplete)
{
 if (element)
 {
  if (from < to && step < 0 || from > to && step > 0) step = -step;
  var p = from;
  var timer;
  var f = function()
  {
   p += step;
   if (from < to && p > to || from > to && p < to) p = to;
   element.style[property] = p + "px";
   if (p == to && timer)
   {
    clearInterval(timer);
    if (typeof oncomplete == "function")
     oncomplete(element, property, from, to, step, interval);
   }
  }
  timer = setInterval(f, interval);
 }
}

function open_submenu(element)
{
 var min_height = 0, max_height = 30;
 if (typeof element != "object")
  element = document.getElementById(element);
 if (element != active_submenu)
 {
  if (active_submenu) close_submenu(active_submenu);
  active_submenu = element;
 }
 if (!element.style.height || parseInt(element.style.height) <= min_height)
  fade_element_property(element, "height", min_height, max_height, 5, 10);
}

function close_submenu(element)
{
 var min_height = 0, max_height = 30;
 if (typeof element != "object")
  element = document.getElementById(element);
 if (element.style.height && parseInt(element.style.height) >= max_height)
  fade_element_property(element, "height", max_height, min_height, 5, 10, function(element, property, from, to, step, interval) { element.style[property] = "1%" });
}
