var MovingSPEED = 5;
var MovingTIMER = 30;

// On Click Mouse //
function openTab(tab,flag)
{
var body = document.getElementById(tab + '-tabcontent');
  //alert(tab);
  //alert(flag);
  clearInterval(body.timer);
  
    var title = document.getElementById(tab + '-tabheader');
  if(flag == 1)
  {
    if ( body.status == "expand" )
    {
        openTab(tab,-1);
        return;
    }
    selectTab(tab);
    
    clearTimeout(title.timer);

    if (body.maxh && body.maxh <= body.offsetHeight) 
    {
    	return
    }
    else if(!body.maxh)
    {
      body.style.display = 'block';     
      body.style.height = 'auto';
      body.maxh = body.offsetHeight;
      body.style.height = '0px';
     
    }
    body.status="expand";
    body.timer = setInterval(function(){tabSlide(body,1)},MovingTIMER);
  }
  
  else
  {
    body.status="collapse";
    title.timer = setTimeout(function(){tabCollapse(body)},50);
  }
  
}

// Close Tab //
function tabCollapse(body)
{
  body.timer = setInterval(function(){tabSlide(body,-1)},MovingTIMER);
}

// Close on Mouse Over //
function tabHide(tab)
{
  var title = document.getElementById(tab + '-tabheader');
  
  clearTimeout(title.timer);
  
  var body = document.getElementById(tab + '-tabcontent');
  clearInterval(body.timer);  
  if(body.offsetHeight < body.maxh)
  {
    body.timer = setInterval(function(){tabSlide(body,1)},MovingTIMER); 
  }
}

// Contract/Expand tabs incrementally also change opacity //
function tabSlide(body,flag)
{
  var currh = body.offsetHeight;
  var length;
  if(flag == 1)
  {
    length = (Math.round((body.maxh - currh) / MovingSPEED));
  }
  else
  {
    length = (Math.round(currh / MovingSPEED));
  }
  if(length <= 1 && flag == 1){
    length = 1;
  }
  body.style.height = currh + (length * flag) + 'px';
  if((currh < 5 && flag != 1) || (currh > (body.maxh - 2) && flag == 1))
  {
      if(flag==-1)
      {
          body.style.height=0;
          
          //closeTab(body.control.substr(0,body.control.indexOf('-',0)));
      }
    clearInterval(body.timer);
  }
}

function selectTab(body)
{
}
    
function closeTab(body)
{
}