$(document).ready(function() {
  var setClose, idle = false;
  var closingTime = 8000;
  var $panelBodies = $('div.panel_body');
  $panelBodies.slice(1).hide();
  
  var closeAll = function() {
    setClose = setTimeout(function() {
      idle = true;
      $panelBodies.hide().prev().removeClass('visible');
    },closingTime);
  };
  var resetClose = function() {
    clearTimeout(setClose);
    closeAll();
  };
  
  closeAll();
  var slideTabs = function() {
    var $this = $(this);
    if (!$this.next().is(':animated')) {
      resetClose();
      $this.parent().siblings().children('div.panel_body')
      .animate({height: 'hide'}, 300, function() {
        $(this).prev().removeClass('visible');
      });
      if (idle == false) {
        $this.next(':hidden').animate({height: 'show'}, 300, function() {
          $(this).prev().addClass('visible');
        });
      }
    }
  };
  $('div.panel_container > h3').mouseover(slideTabs);

  $('html, body').mousemove(function() {
    if (idle) idle = false;
  });  

});
