Periods of integrals on algebraic manifolds, I. Construction and properties of the modular varieties