$(document).ready(function() {
    // Suchfeld leeren
    $('#search-input').focus(function () {
        $(this).attr('value','');
    });

    // Slideshow
    $('#content-text').cycle({ slideExpr: 'span.slideshowimage', timeout: 6000, speed: 3000 });
  

    $(".contenttable tr").each(function(){
        $(this).find('th:last').addClass('th-last');
        $(this).find('td:last').addClass('td-last');
     });
    
    // Aufklappliste / Akkordion
    $('.accordion .csc-header').css({cursor: "pointer"});
    
    $('.accordion').addClass('hidden')


    if(document.location.hash != '') {
        var anchorSiblings = $(document.location.hash).siblings();
        $('.accordion').children().not('.csc-header').not(anchorSiblings).hide();
    }
    else {
        $('.accordion').children().not('.csc-header').hide();
    }

    $('.accordion').click(
        function(){
            $('.preview-thumb').css({'display' : 'block'});
            if($(this).children().not('.csc-header').css("display")=="none" )
            {
                // If thumbnail exists, hide it
                if ($(this).find('.preview-thumb').length > 0)
                {
                    $(this).find('.preview-thumb').css({'display' : 'none'})
                }
                $(this).addClass('shown').removeClass('hidden');
                $('.accordion').not(this).addClass('hidden').removeClass('shown').children().not('.csc-header').hide();
                $(this).children().slideDown("fast");
                //$('.accordion .csc-header h3').addClass('outfolded');
            }
            else
            {
                // If thumbnail exists, show it
                if ($(this).find('.preview-thumb').length > 0)
                {
                    $(this).find('.preview-thumb').css({'display' : 'block'})
                }
                $(this).addClass('hidden').removeClass('shown');
                $(this).children().not('.csc-header').slideUp("fast");
                //$('.accordion .csc-header h3').removeClass('outfolded');
            }
        }
    );

});

// apply same height to all blocks (co-block) of the same block row (co-block-row)
function align_block_heights (heightFix) {
   return; // FIXME logic does not work. discuss with SB
   $('.equal-height').parents().each(function(){
      var children = $(this).find(heightFix);

      // skip rows which only contain a single block
      if (children.length == 1) {
         return true; // this is in each() like a continue
      }

      // determine height of highest block in current row
      var maxHeight = false;
      var highestBlock = false;
      children.each(function(){
         var currentHeight = $(this).height();
     if ((maxHeight === false) || (currentHeight > maxHeight))
     {
        maxHeight = currentHeight;
        highestBlock = this;
     }
      });

      // set max height for each block in current row (except for the highest block, small optimization)
      children.each(function(){
         if (this === highestBlock) {
        return true; // this is in each() like a continue
     }
     $(this).height(maxHeight);
      });
   });
}

$(window).bind('load', function(){
   align_block_heights('.equal-height');
   align_block_heights('.news-list-item');
});
