$(document).ready(function () {
  $('html').removeClass('no-js');
  var subnavHeight = $('#subnavigation').height();
  $('#main .content').css('min-height', (subnavHeight-33));
  $('.AxCaptchaImg').parent('div').addClass('AxCaptcha');
  $('.ie7 .widget').prepend('<div class="before"></div>');
  $('.ie7 .widget').append('<div class="after"></div>');

  $('.carousel').each(function () {
    var currentPosition = 0;
    var slideWidth = '130';
    var slides = $(this).find('.item');
    var numberOfSlides = slides.length;
    slides.wrapAll('<div class="slideInner"></div>').css({ 'float': 'left', 'width': slideWidth });
    $('.slideInner').width(numberOfSlides * slideWidth);


    $('.contactlist li:first').addClass('active');
    $('.carousel .item').fadeTo(1, 0.5);
    $('.carousel .item:first').fadeTo(1, 1);
    $('.carousel .item:nth-child(1) img').css({ 'height': '290px', 'margin': '0px' });
    $('.carousel .item:nth-child(2) img').css({ 'height': '280px', 'margin': '5px 0px' });
    $('.carousel .item:nth-child(3) img').css({ 'height': '270px', 'margin': '10px 0px' });
    $('.carousel .item:nth-child(4) img').css({ 'height': '260px', 'margin': '15px 0px' });

    $('.contactlist li').each(function () {
      var index = $(this).index('.contactlist li');
      $(this).attr('position', index);
    });
    $('.carousel .item').each(function () {
      var index = $(this).index('.carousel .item');
      $(this).attr('position', index);
    });

    $(this).before('<span class="carouselControl leftControl" rel="leftControl">Slide to the left</span>').after('<span class="carouselControl rightControl" rel="rightControl">Slide to the right</span>');

    $('.carouselControl').live('click', function () {
      currentPosition = ($(this).attr('rel') == 'rightControl') ? currentPosition + 1 : currentPosition - 1;

      $('.carousel .item:first').fadeTo(1, 0.5);
      var direction = $(this).attr('rel');
      if (direction == 'rightControl') {
        $('.carousel .item:last').after($('.carousel .item:first'));
      } else {
        $('.carousel .item:first').before($('.carousel .item:last'));
      }

      $('.carousel .item:nth-child(1) img').css({ 'height': '290px', 'margin': '0px' });
      $('.carousel .item:nth-child(2) img').css({ 'height': '280px', 'margin': '5px 0px' });
      $('.carousel .item:nth-child(3) img').css({ 'height': '270px', 'margin': '10px 0px' });
      $('.carousel .item:nth-child(4) img').css({ 'height': '260px', 'margin': '15px 0px' });

      $('.carousel .item:first').fadeTo(1, 1);
      var firstPosition = $('.carousel .item:first').attr('position');
      $('.contactlist li').removeClass('active');
      $('.contactlist li[position=' + firstPosition + ']').addClass('active');

      return false;
    });

  });


});


$(function () {
  $(".accordion").accordion({autoHeight: false});
});
