$(function() {
  
  $('#header.home #next').click(function() {
    $curr = $('#header.home .brands').find('> :first')
    $next = $curr.next();
    $curr.hide().appendTo('#header.home .brands').find('a').css('bottom', '-400px');
    $next.show().find('a').animate({'bottom': 0}, 100).effect('bounce', {distance: 10, times: 1.5}, 150);
    return false;
  });

  $('#header.home #prev').click(function() {
    $curr = $('#header.home .brands').find('> :first')
    $prev = $('#header.home .brands').find('> :last')
    $curr.hide().find('a').css('bottom', '-400px');
    $prev.prependTo('#header.home .brands').show().find('a').animate({'bottom': 0}, 100).effect('bounce', {distance: 10, times: 1.5}, 150);
    return false;
  });
  
  $('#header.home .brands > :first').find('a').animate({'bottom': 0}, 100).effect('bounce', {distance: 10, times: 1.5}, 150);
  
  if ($('#header').hasClass('home')) {
    position_brands();
    $(window).bind('resize', function() {
      position_brands();
    });
  }
  
});

function position_brands () {
  body_width = $('body').width();
  if (body_width < 1280) {
    left = (body_width-1280)/2;
    $('#header .brands > div').each(function(index) {
      $(this).css('margin-left', left);
    });
  } else {
    $('#header .brands > div').each(function(index) {
      $(this).css('margin', '0 auto');
    });
  }
}
