Palatini Theories of Gravity and Cosmology