/* This script is the result of many pieces of code from various ideas - 2009 */
/* Specially modified for Lodge Logs */

var speed = 5;
var timer = 15;


function menuBar(id,d){
  var h = document.getElementById(id + '-headerSec');
  var c = document.getElementById(id + '-contentSec');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){opacStyle(c,1)},timer);
  }else{
    h.timer = setTimeout(function(){foldMenu(c)},50);
  }
}


function foldMenu(c){
  c.timer = setInterval(function(){opacStyle(c,-1)},timer);
}

function viewNow(id){
  var h = document.getElementById(id + '-headerSec');
  var c = document.getElementById(id + '-contentSec');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){opacStyle(c,1)},timer);
  }
}


function opacStyle(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / speed));
  }else{
    dist = (Math.round(currh / speed));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}
