$(
  function()
  {
    $('#lang-menu').addClass('js').find('LI:not(:first-child)').hide();
    $('#lang-menu')
      .mouseleave(function(){$('#lang-menu').addClass('js').find('LI:not(:first-child)').hide('fast');})
      .find('LI:first-child')
      .mouseenter(function(){$('#lang-menu').addClass('js').find('LI:not(:first-child)').show();});


    $('a[href^=http://]').attr('target', '_blank');

    $('#footer-nav > li').each(
      function()
      {
        $(this).css('height', $(this).parent().css('height'));
      }
    );

    $('.accordeon .feature-box')
      .addClass('accordeon-box')
      .each(
        function()
        {
          $(this).find('.feature-box-heading').addClass('closed');
          $(this).find('.feature-box-content').hide();
        }
      )
/*
    $('.accordeon .feature-box:first').each(
      function()
      {
        $(this).find('.feature-box-heading').addClass('opened');
        $(this).find('.feature-box-content').show();
      }
    );
*/
    $('.accordeon .feature-box-heading').click(
      function()
      {
        if ($(this).hasClass('opened')) {
          $(this).removeClass('opened').siblings().slideUp('fast');
          return;
        }
        $('.accordeon .opened').removeClass('opened').siblings().slideUp('fast');
        $(this).addClass('opened').siblings().slideDown('fast');
      }
    );

    if ($('.gallery .gallery-item').size()) {
      var max = 0;

      $('.gallery .gallery-item img').each(
        function()
        {
          if (this.height > max)
            max = this.height;
        }
      );

      $('.gallery .gallery-item').hide();
      $('.gallery .gallery-item:first-child')
        .before('<img id="gallery-back" src="/img/gallery.back.gif" /><img id="gallery-next" src="/img/gallery.next.gif" />')
        .show();
      $('#gallery-back').css('top', Math.floor((max - 25) / 2) + 'px').click(galleryBack);
      $('#gallery-next').css('top', Math.floor((max - 25) / 2) + 'px').click(galleryNext);
    }

    $('dl').addClass('toggle-list').find('dd, dt').each(
      function()
      {
        switch (this.tagName) {
          case 'DT':
            $(this).click(
              function()
              {
                $(this).toggleClass('open').next('dd').toggle();
              }
            );
            break;

          case 'DD':
            $(this).hide();
            break;
        }
      }
    );

    $('a > img').each(
      function()
      {
        if (!this.parentNode.href.match(/\.(?:png|gif|jpe?g)$/i))
          return;

        $(this)
          .parent()
          .lightBox(
            {
              imageBlank:           '/img/lightbox-blank.gif',
              imageLoading:         '/img/lightbox-ico-loading.gif',
              imageBtnClose:        '/img/lightbox-btn-close.gif',
              imageBtnPrev:         '',
              imageBtnNext:         '',
              containerResizeSpeed: 350,
              txtImage:             '',
              txtOf:                ''
            }
          );
      }
    );
  }
);

function galleryBack()
{
  if ($('.gallery-item:visible').prev('.gallery-item').size()) {
    $('.gallery-item:visible').hide().prev('.gallery-item').show();
  } else {
    $('.gallery-item:visible').hide();
    $('.gallery-item:last').show();
  }
}

function galleryNext()
{
  if ($('.gallery-item:visible').next().size()) {
    $('.gallery-item:visible').hide().next().show();
  } else {
    $('.gallery-item:visible').hide();
    $('.gallery-item:first').show();
  }
}
