var DDSPEEDside = 5;
var DDTIMERside = 10;

function showMenuSide(id, d) {
	//var dlg = document.getElementById(id);
	//dlg.style.display = "block";
	var h = document.getElementById(id);
	var c = document.getElementById(id);
			
	clearInterval(c.timer);
	
	if(d == 1){
    	clearTimeout(h.timer);
		if(c.maxh && c.maxh <= c.offsetHeight){
			c.style.display = 'block';
		  	return;
		}
		else if(!c.maxh){
		  c.style.display = 'block';
		  c.style.height = 'auto';
		  c.maxh = c.offsetHeight;
		  c.style.height = '0px';
		} else {
		
			c.style.display = 'block';
			
		}
			
    	c.timer = setInterval(function(){ddSlideSide(c,1)},DDTIMERside);
	}else{
    	c.timer = setTimeout(function(){ddCollapseSide(c)},50);
  	}
}

function cancelHideSide(id){
  var h = document.getElementById(id);
  var c = document.getElementById(id);
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlideSide(c,1)},DDTIMERside);
  }
}

function ddCollapseSide(c){
  c.timer = setInterval(function(){ddSlideSide(c,-1)},DDTIMERside);
  //alert("Collapse");
}

function ddSlideSide(c,d){
	
	var divheight = c.style.height;
	
	if (divheight == 0) {
		currh = c.offsetHeight;
	} else {
		currh = Left(divheight, divheight.length - 2);
		currh = parseInt(currh);
	}
 
 	
  var dist;
    
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEEDside));
  }else{
    dist = (Math.round(currh / DDSPEEDside));
  }
  
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  
  var cHeight = currh + (dist * d);
  
  if(d == -1) {
	  //alert("height: " + currh + ", Dist: " + dist + ", New Height: " + cHeight);
	  //alert("Height: " + currh + ", Style Height: " + c.style.height);
	
	//alert(currh);
  }
  
  c.style.height = cHeight + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  //alert(currh);
  if((currh < 5 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
	//alert(currh);
	if(currh <= 4) {
		c.style.display = 'none';
	}
  } else {
	 //alert(currh);
	 
  }
}

function hideMenuSide(el) {
	var dlg = document.getElementById(el);
	dlg.style.display = "none";
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
