function resizeWindow()
{
  $('#content-area').css('min-height', null);

  var diff = $(window).height() - $('body').innerHeight();

  if (diff > 0)
    $('#content-area').css('min-height', ($('#content-area').innerHeight() + diff) + 'px');
}

$(
  function()
  {
    $('#mainmenu').superfish(
      {
        animation:    {opacity: 'show', height: 'show'},
        autoArrows:   false,
        delay:        0,
        dropShadows:  true,
        hoverClass:   'sfHover',
        speed:        'fast'
      }
    );
    resizeWindow();

    if ($('#content-body').length) {
      $('#content-intro p:last')
        .append('<a class="forward-inline" href="#">' + static.more + '</a>')
        .find('a.forward-inline')
        .click(
          function()
          {
            $('#content-body').show();
            $(this).hide();
            return false;
          }
        );
      $('#content-body')
        .hide()
        .find('p:last')
        .append('<a class="forward-inline" href="#">' + static.close + '</a>')
        .find('a.forward-inline')
        .click(
          function()
          {
            $('#content-body').hide();
            $('#content-intro a.forward-inline').show();
            return false;
          }
        );

    }

    $('dl.accordeon dd').hide();
    $('dl.accordeon dt')
      .click(
        function()
        {
          $(this)
            .toggleClass('opened')
            .toggleClass('closed')
            .next()
            .toggle()
            .blur();
        }
      )
      .each(
        function()
        {
          $(this).html('<span class="heading">' + $(this).html() + '</span>');
        }
      )
      .prepend('<span class="toggler"></span>')
      .attr('class', 'closed')

    $('table.tip-items a')
      .each(
        function()
        {
          if (m = this.href.match(/~(\d+)\.html/)) {
            this.rel = this.href;
            this.href = self.location + '#tip-' + m[1];
          }
        }
      )
      .click(
        function()
        {
          $(this).addClass('visited');
          $('#tip-detail-wrapper').load(
            this.rel + ' #tip-detail',
            function()
            {
              $('#tip-items-wrapper').hide();
              $(this).expose({closeOnClick: false,closeOnEsc: false}).show()[0].scrollIntoView(true);
              $('#exposeMask').css('z-index', 10);
              $(this).css('z-index', 1000);
              $('#tip-detail-closer a').click(
                function()
                {
                  $.mask.close();
                  $('#tip-detail-wrapper').hide();
                  $('#tip-items-wrapper').show();
                  return false;
                }
              );
            }
          );
          return false;
        }
      );

//    $('table.tip2-items a').click(
//      function()
//      {
//        $('#tip2-detail-wrapper').load(
//          this.href + ' #tip2-detail',
//          function()
//          {
//            $('#tip2-items-wrapper').hide();
//            $(this).expose({closeOnClick: false,closeOnEsc: false}).show()[0].scrollIntoView(true);
//            $('#tip2-detail-closer a').click(
//              function()
//              {
//                $.mask.close();
//                $('#tip2-detail-wrapper').hide();
//                $('#tip2-items-wrapper').show();
//                return false;
//              }
//            );
//          }
//        );
//        return false;
//      }
//    );

    $('table.tip2-items td')
      .addClass('tip2-item')
      .click(
        function()
        {
          $(this).addClass('visited');
          $('#tip2-detail-wrapper').load(
            $(this).find('A').attr('href') + ' #tip2-detail',
            function()
            {
              $('#tip2-items-wrapper').hide();
              $(this).expose({closeOnClick: false,closeOnEsc: false}).show()[0].scrollIntoView(true);
              $('#tip2-detail-closer a').click(
                function()
                {
                  $.mask.close();
                  $('#tip2-detail-wrapper').hide();
                  $('#tip2-items-wrapper').show();
                  return false;
                }
              );
            }
          );
          return false;
        }
      );

    $('ol.faq').addClass('toggle-list').find('H3, DIV').each(
      function()
      {
        switch (this.tagName) {
          case 'H3':
            $(this)
              .addClass('faq-link')
              .click(
                function()
                {
                  $(this).toggleClass('open').next('div.faq-answer').toggle();
                }
              );
            break;

          case 'DIV':
            $(this).hide();
            break;
        }
      }
    );
  }
);
$(window).resize(function() {resizeWindow();});
