Energy-dependent electron-energy-loss spectroscopy: Application to the surface and bulk electronic structure of MgO