//----------- lang panel -----------//
var SPEED = 10;
var TIMER = 15;

function ddMenu(id,dir) {
  var head = document.getElementById('spLang');
  var cont = document.getElementById('spContentLang');
  clearInterval(cont.timer);
  if(dir == 1) {
    clearTimeout(head.timer);
    if(cont.maxh && cont.maxh <= cont.offsetHeight) {
      return;
    } else if(!cont.maxh) {
      cont.style.display = 'block';
      cont.maxh = cont.offsetHeight;
      cont.style.height = '0px';
    }
    cont.style.display = 'block';
    cont.timer = setInterval("ddSlide('spContentLang', 1)", TIMER);
  } else {
    head.timer = setTimeout("ddHide('spContentLang')", 50);
  }
}

function cancelHide(id) {
  var head = document.getElementById('spLang');
  var cont = document.getElementById('spContentLang');
  clearTimeout(head.timer);
  clearInterval(cont.timer);
  if(cont.offsetHeight < cont.maxh) {
    cont.timer = setInterval("ddSlide('spContentLang', 1)", TIMER);
  }
}

function ddHide(id) {
  var cont = document.getElementById(id);
  cont.timer = setInterval("ddSlide('" + id + "', -1)", TIMER);
}

function ddSlide(id,dir) {
  var cont = document.getElementById(id);
  var currheight = cont.offsetHeight;
  var dist;
  if(dir == 1) {
    dist = (Math.round((cont.maxh - currheight) / SPEED));
  } else {
    dist = (Math.round(currheight / SPEED));
  }
  if(dist <= 1) {
    dist = 1;
  }
  cont.style.height = currheight + (dist * dir) + 'px';
  if((currheight < 2 && dir != 1) || (currheight > (cont.maxh - 2) && dir == 1)) {
    if(currheight < 2 && dir != 1){ cont.style.display = 'none';}
    clearInterval(cont.timer);
  }
}
