function initTabs(what) {
  var set_tab = false;

  var a = window.location.hash;
  if (a.length > 0) {
    set_tab = 'tab-'+a.substr(1,6);
  }

  try {
	  if ($('tab-'+what+'-0')) {
	    activeTab($('tab-'+what+'-0'), what);
	  }
	  else {
	    // dit is een stukje legacy omdat de indices op de tabs gewijzigd zijn van 1+ naar 0+
	    activeTab($('tab-'+what+'-1'), what);
	  }
  }
  catch (e) {}

  var tabs = $$('#tabs-'+what+' li');

  tabs.each(function(n,i) {
    n.onclick = function() {
      activeTab(n, what);
    }
  });

  if (set_tab) {
    activeTab($(set_tab), what);
  }
}

function activeTab(n, what) {	
  if (!n) return;
  
  var tabid = n.id.substr(5+what.length);

  var tabs = $$('.tabs li');
  var dspl = 'none';

  tabs.each(function(n,i) {
    if (n.id) {

      if (n.id.substr(0,5) == 'tabs-') {
        dspl = n.id == 'tabs-'+what+'-'+tabid ? 'block' : 'none';
        n.style.display = dspl;

        dspl = n.id == 'tabs-'+what+'-'+tabid ? 'visible' : 'hidden';
        n.style.visibility = dspl;

        if (n.id == 'tabs-'+what+'-'+tabid) {
          $('tab-'+what+'-'+tabid).addClassName('active');

          window.location.hash = '#'+what+'-'+tabid;
        }
        else {
          var curid = n.id.substr(6+what.length);
          try {
        	  $('tab-'+what+'-'+curid).removeClassName('active');
          }
          catch(e) {}
        }
      }
    }
  });

  try {
    selectedTab(tabid);
  }
  catch(e) {}
  
}

var currenthovertab = false;
var hovering = false;

function hoverTab(what) {
  hovering = true;

  if (currenthovertab && currenthovertab != what) {
    if ($(currenthovertab) != 'undefined') {
      $(currenthovertab).style.display = 'none';
    }
  }

  $(what).style.display = 'block';

  currenthovertab = what;

  setTimeout(function() { clearHovertab(); }, 1500);
}

function clearHovertab()
{
  if (!hovering) {
    if (currenthovertab) {
      if ($(currenthovertab) != 'undefined') {
        $(currenthovertab).style.display = 'none';
      }
    }

    currenthovertab = false;
  }
  else {
    hovering = false;

    setTimeout(function() { clearHovertab(); }, 1500);
  }
}
