function switchImage(element) {
  index = $(element).index('#bannerSwitch>#buttons>a');
  $('#bannerSwitch>#buttons>a').removeClass('active').filter($(element)).addClass('active');
  $('#bannerSwitch>img:not(:hidden)').fadeOut(500,function() {
    $('#bannerSwitch>img:eq('+index+')').fadeIn(500);
  });

  return false;
}

$(document).ready(function() {
  (function(elem) {
    $(elem).children('img').hide().filter($(elem+ ' img:first')).show();

    fadeTimer = function() {
      setTimeout(function() {
        if($('#bannerSwitch>#buttons>a.active').next('a').length > 0) {
          switchImage($('#bannerSwitch>#buttons>a.active').next('a'));
        } else {
          switchImage($('#bannerSwitch>#buttons>a:first'));
        }
        fadeTimer();
      }, 5000);
    };

    fadeTimer();

  })('#bannerSwitch');

  $('#bannerSwitch>#buttons>a').click(function() {
    return switchImage(this);
  });

  $('#bannerSwitch>#buttons>a:first').addClass('active');
});

