var default_duration = 0.1, default_fps = 30;

function decHeight(element) {
	return function() {
		var newHeight = element.clientHeight - Math.round(element.step);
		if (newHeight - (element.height_fix ? element.height_fix : 0) <= 0) {
			element.style.height = "";
			element.style.display = "none";
			element.style.overflow = element._overflow;
			clearInterval(element.timer);
			element.blinding = false;
		} else {
			setHeight(element, newHeight);
		}
	}
}

function incHeight(element) {
	return function() {
		var newHeight = element.clientHeight + Math.round(element.step);
		if (newHeight - (element.height_fix ? element.height_fix : 0) >= element.origHeight) {
			element.style.height = "";
			element.style.overflow = element._overflow;
			clearInterval(element.timer);
			element.blinding = false;
		} else {
			setHeight(element, newHeight);
		}
	}
}

function setHeight(element, newHeight) {
	element.style.height = newHeight - (element.height_fix ? element.height_fix : 0) + "px";
	if (element.clientHeight != newHeight) {
		element.height_fix = element.clientHeight - newHeight;
		element.style.height = newHeight - (element.height_fix ? element.height_fix : 0) + "px";
	}
}


function blindsUp(elem, duration, fps) {
	if (elem.blinding && elem.blinding == true)
		return;
	elem.blinding = true;

	if (!duration)
		duration = default_duration;
	if (!fps)
		fps = default_fps;

	elem._overflow = elem.style.overflow;
	elem.style.overflow = "hidden";
	if (elem.clientHeight == 0)
		elem.style.height = elem.offsetHeight + "px";
	elem.step = Math.round(elem.clientHeight / (fps * duration)); //
	elem.step = Math.max(1, elem.step);
	elem.timer = setInterval(decHeight(elem), Math.round(1000 * duration / (elem.clientHeight / elem.step))); //
	decHeight(elem);
}

function blindsDown(elem, duration, fps) {	if (elem.style.display != 'none')
		return;
	if (elem.blinding && elem.blinding == true)
		return;
	elem.blinding = true;

	if (!duration)
		duration = default_duration;
	if (!fps)
		fps = default_fps;

	elem._overflow = elem.style.overflow;
	elem.style.overflow = "hidden";
    var els = elem.style;
    var origVis = els.visibility;
    var origPos = els.position;
    els.visibility = 'hidden';
    els.position = 'absolute';
    els.display = '';
	elem.origHeight = elem.clientHeight;
    els.position = origPos;
    els.visibility = origVis;
    els.height = "0px";
	elem.step = Math.round(elem.origHeight / (fps * duration)); //
	elem.step = Math.max(1, elem.step);
	elem.timer = setInterval(incHeight(elem), Math.round(1000 * duration / (elem.origHeight / elem.step))); //
	incHeight(elem);
}

var arrLayer = new Array;
var bCloseAll = false;

function closeAll() { if (bCloseAll == true) {  for (var i = 1; i < 5; i++) {
   if (arrLayer[i] == 1 || document.getElementById('padding_menu_'+i).style.display != 'none') {
    blindsUp(document.getElementById('padding_menu_'+i));
    arrLayer[i] = 0;
   }
  }
  bCloseAll = false;
 }
}

function scroller(layer) { bCloseAll = true; for (var i = 1; i < 5; i++) {  if (arrLayer[i] == 1 || document.getElementById('padding_menu_'+i).style.display != 'none') {   blindsUp(document.getElementById('padding_menu_'+i));
   arrLayer[i] = 0;
  }
 }

 if (document.getElementById('padding_menu_'+layer).style.display == 'none') {
  blindsDown(document.getElementById('padding_menu_'+layer));
  arrLayer[layer] = 1;
 }
}

