var currentPos = 0;
var autoRotate = true;
var intervalId = 0;

var links = [
  { link: 'about-intro-link', x: 0 },
  { link: 'entrepreneur-intro-link', x: 492 },
  { link: 'investor-intro-link', x: 984 },
  { link: 'mentor-intro-link', x: 1476 }
];

function selectIntroBox(newObjIndex) {
  autoRotate = false;
  moveIntroBox(newObjIndex);
}

function moveIntroBox(newObjIndex) {
  obj = links[newObjIndex];
  oldObj = links[currentPos];
  new Effect.Move('carousel-inner', { x:-obj.x, y:0, mode: 'absolute'});
  $(oldObj.link).removeClassName('selected');
  $(obj.link).addClassName('selected');
  currentPos = newObjIndex;
}

function startAutoRotate() {
  if (!autoRotate) {
    clearInterval(intervalId);
    return;
  }

  if (currentPos == links.length-1) moveIntroBox(0);
  else moveIntroBox(currentPos+1);
}

document.observe("dom:loaded", function() {
  intervalId = setInterval("startAutoRotate()", 8000);
  Shadowbox.init();
  
  links.each(function(linkObj,index) {
    $(linkObj.link).observe('click',function(event) {
      selectIntroBox(index);
      event.stop();
    });
  });
});


