of Poitiers, whose power base at Poitou was in northwestern Aquitaine. At the death of Carolingian king of France Louis V in 987 the Robertian faction had its chief, Hugh Capet, elected to the French throne; This ended the Carolingian dynasty. Hugh Capet founded the Capetian dynasty, which would rule France for the next eight centuries. The counts of Toulouse extended their domain to the Mediterranean coast, but their rule was short-lived. During the 10th century civilization, the arts and education had declined; a rebirth of culture and order during the reign of Charlemagne was smothered by Viking invasions, augmented by poor weather and plagues which contributed to population loss. Large areas of western Europe returned to wilderness, and cities were depopulated. Churches were abandoned or plundered; Christianity lost much of its moral authority, although Roman culture survived in scattered monasteries. This contrasted with the flourishing emirate of Córdoba in Spain and the Byzantine Empire. Authority decentralized, falling from counts to viscounts to thousands of local feudal lords. By the end of the century, France was governed by thousands of local rulers who controlled one town or one castle and a few surrounding villages. Between 900 and 980 the counts of Toulouse gradually lost control to local dynastic rulers, and by 1000 ruled only a few scattered estates; the city was ruled by a viscount, independent of the counts. Invasions had also resumed. Emir of Córdoba Abd al-Rahman III reunited Muslim Spain and brought the emirate to its zenith, transforming it into the caliphate of Córdoba in 929. During the 920s, he launched an offensive against the Christian kingdoms in northern Spain. In 920 one of Abd al-Rahman's armies crossed the Pyrenees, reaching Toulouse without capturing the city. Four years later, the Magyars launched a westward expedition and reached Toulouse before their defeat by Count Raymond III Pons. By the end of the 10th century, the Carolingian wars and subsequent invasions had left the county in disarray. Land was left uncultivated, and many farms were abandoned. Toulouse's proximity to Muslim Spain gave it a flow of knowledge and culture from the schools and printing houses of Córdoba, and it had retained more of the Roman legacy than northern France. 11th century At the beginning of the millennium, the church was co-opted by the Toulouse administration; the Saint-Sernin church, the Daurade basilica and the Saint-Étienne cathedral were not maintained properly, and