The extension of the method of dimensionality reduction to layered elastic media