The city of Trondheim was founded in 997. It was frequently used as the seat of the king, and was capital of Norway until 1217. In the Middle Ages, Trondheim was the site of several battles, including the battle between King Sverre and Erling Skakke, in 1179. The city has experienced several major fires - the most devastating in 1651 and 1681. The 1651 fire destroyed 90% of the buildings in Trondheim, and the 1681 fire led to a total reconstruction of the city.