$(document).ready(function() {
  // initially close all containerboxed which are appropriately flagged
  $('a.contState.close').closest('tr').next('tr').hide();
  
  $('a.contState').each(function (i) {
    if($(this).hasClass('open')) {
      $(this).attr('title', 'Schließen');
    }
    else {
      $(this).attr('title', 'Öffnen');
    }
  });
  
  $('.middle a.contState').each(function (i) {
    if($(this).hasClass('open')) {
      $(this).text('Schließen');
    }
    else {
      $(this).text('Öffnen');
    }
  });
  
  // attach onClick handler to open/close containerboxes
  $('a.contState').click(function () {
    if($(this).hasClass('open')) {
      $(this).closest('tr').next('tr').hide();
      $(this).removeClass('open').addClass('close');
      $(this).attr('title', 'Öffnen');
      if($(this).text()) $(this).text('Öffnen');
    }
    else {
      $(this).closest('tr').next('tr').show();
      $(this).removeClass('close').addClass('open');
      $(this).attr('title', 'Schließen');
      if($(this).text()) $(this).text('Schließen');
    }
    return false;
  })
  
  // attach onClick handler to open/close retrospects archive
  $('a.retrospectsArchiveToggle').click(function () {
    if($(this).hasClass('close')) {
      $(this).parent().parent().find('.retrospectsArchive').each(function (i) {
        $(this).show();
      });
      $(this).removeClass('close').addClass('open');
      $(this).text('Ältere Rückblicke ausblenden ...');
    }
    else {
      $(this).parent().parent().find('.retrospectsArchive').each(function (i) {
        $(this).hide();
      });
      $(this).removeClass('open').addClass('close');
      $(this).text('Ältere Rückblicke einblenden ...');
    }
    return false;
  })
});
