Variational extension of the mean spherical approximation to arbitrary dimensions