A variational theory of the Hessian equation