intro = new Array('#a', '#b', '#c');
i = 0;
timeoutId = null;

right = function() {
  clearTimeout(timeoutId);
  
  j = i - 1;
  if(j < 0) {
    j = intro.length - 1;
  }
  
  $(intro[i]).animate({'left' : 800}, 600);
    
  $(intro[j]).css('left', -800);
  $(intro[j]).animate({
      'left' : 0
    }, 600);
    
  i = j;
  
  timeoutId = setTimeout(left, 10000);
}

left = function() {
  clearTimeout(timeoutId);
  
  j = i + 1;
  if(j > 2) {
    j = 0;
  }
  
  $(intro[i]).animate({
      'left' : -800
    }, 600);
    
  $(intro[j]).css('left', 800);
  $(intro[j]).animate({
      'left' : 0
    }, 600);
    
  i = j;
  
  timeoutId = setTimeout(left, 10000);
}

rightEv = function(event) {
  right();
  event.preventDefault();
}

leftEv = function(event) {
  left();
  event.preventDefault();
}

$(window).load(function() {
  $(".pulse, .partner img").each(function(index) {
    $(this).hover(
      function(e) {
        $(this).animate({
          'padding-top' : '0',
          'padding-bottom' : '7px'
        }, 200);
      },
      function(e) {
        $(this).animate({
          'padding-top' : '7px',
          'padding-bottom' : '0px'
        }, 200);
      });
  });
  
  for(j = 0; j < 3; ++j) {
    $(intro[j]).css({
        'position': 'relative',
        'top': -270 * j,
        'left': 800 * j
      });
      
    divtext = $(intro[j] + ' div.text');
    divtext.css('padding-top', ($(intro[j]).height() - divtext.height())/2);
  }
  
  $('#intro').css({
    'position': 'relative',
    'overflow': 'hidden',
    'height': 270
  });
  
  $('#intro').after('<div id="intro-arrows"><a id="intro-back" href="#">&lt;</a> <a id="intro-forward" href="#">&gt;</a></div>');
  
  t = $('#intro').offset();
  $('#intro-arrows').css({
    'font-size': '1.5em',
    'position': 'absolute',
    'top': t.top + 230,
    'left': t.left + 730,
    'width': 50
  });
  
  $('#intro-forward').click(leftEv);
  $('#intro-back').click(rightEv);
  timeoutId = setTimeout(left, 10000);
});

