originally built in a.d. 360 , hagia sophia had served as an eastern orthodox cathedral until 1204 , when enrico dandolo and the fourth crusade conquered the city and turned it into a catholic church .