
function carousel() {
  
  var arrows = $('#carousel .arrow'); var obj = $('#carousel'); 
  if (obj.find('li').length <= 1) { arrows.hide(); return false; }
  
  arrows.click(function() {
    carousel_run(obj.find('ul'), $(this).attr('id')); return false;
  });
}

function carousel_run(obj, arrow) {

  var state = parseInt(obj.css('margin-left').replace('px'));
  var step = 520;
  var max = (obj.width() - step) * -1;

  switch (arrow) {
    case 'carousel_left':
      
      if (state >= 0) { carousel_move(obj, max); return false; }
      carousel_move(obj, '+='+ step);
      
      break;
      
    case 'carousel_right':

      if (state <= max) { carousel_move(obj, 0); return false; }
      carousel_move(obj, '-='+ step);
      
      break;
  }
}

function carousel_move(obj, move) { obj.animate({'margin-left': move}); }
