Relativistic hydrodynamics for heavy-ion collisions. I. General aspects and expansion into vacuum