Variational methods in Lorentzian geometry