On some nonlocal problems in the calculus of variations