While the first mosque in Egypt was the Mosque of Amr ibn al-As in Fustat, the Mosque of Ibn Tulun is the oldest mosque to retain its original form and is a rare example of Abbasid architecture, from the classical period of Islamic civilization. It was built in 876–879 AD in a style inspired by the Abbasid capital of Samarra in Iraq.[5] It is one of the largest mosques in Cairo and is often cited as one of the most beautiful.[6][7] After Cairo was founded to the northeast of Fustat in 959 AD by the victorious Fatimid army, the Fatimids built a separate palatial city which contained their palaces and institutions of government. It was enclosed by a circuit of walls, which were rebuilt in stone in the late 11th century AD by the vizir Badr al-Gamali,[8] parts of which survive today at Bab Zuwayla in the south and Bab al-Futuh and Bab al-Nasr in the north. One of the most important and lasting institutions founded in the Fatimid period was the Mosque of al-Azhar, founded in 970 AD, which competes with the Qarawiyyin in Fes for the title of oldest university in the world.[9] Today, al-Azhar University is the foremost center of Islamic learning in the world and one of Egypt's largest universities with campuses across the country.[9] The mosque itself retains significant Fatimid elements but has been added to and expanded in subsequent centuries, notably by the Mamluk sultans Qaitbay and al-Ghuri and by Abd al-Rahman Katkhuda in the 18th century. Other extant monuments from the Fatimid era include the large Mosque of al-Hakim, the al-Aqmar mosque, Juyushi Mosque, Lulua Mosque, and the Mosque of Salih Tala'i. The most prominent architectural heritage of medieval Cairo, however, dates from the Mamluk period, from 1250 to 1517 AD. The Mamluk sultans and elites were eager patrons of religious and scholarly life, commonly building religious or funerary complexes whose functions could include a mosque, madrasa, khanqah (for Sufis), water distribution centers (sabils), and mausoleum for themselves and their families.[10] Among the best-known examples of Mamluk monuments in Cairo are the huge Mosque-Madrasa of Sultan Hasan, the Mosque of Amir al-Maridani, the Mosque of Sultan al-Mu'ayyad (whose twin minarets were built above the gate of Bab Zuwayla), the Sultan Al-Ghuri complex, the funerary complex of Sultan Qaytbay in the Northern Cemetery, and the trio of monuments in the Bayn al-Qasrayn area comprising the complex of Sultan al-Mansur Qalawun, the Madrasa of al-Nasir Muhammad, and the Madrasa of Sultan Barquq. It is said that a lot of the columns found in mosques were taken from the Coptic churches because of their beautiful artistic carvings and placed in mosques. Khan el-Khalili, a major souk in Islamic Cairo. The Mamluks, and the later Ottomans, also built wikalas or caravanserais to house merchants and goods due to the important role of trade and commerce in Cairo's economy.[11] The most famous example still intact today is the Wikala al-Ghuri, which nowadays also hosts regular performances by the Al-Tannoura Egyptian Heritage Dance Troupe.[12] The famous Khan al-Khalili (see below) is a commercial hub which also integrated caravanserais (also known as khans). Islamic Cairo is also the location of several important religious shrines such as the al-Hussein Mosque (whose shrine is believed to hold the head of Husayn ibn Ali), the Mausoleum of Imam al-Shafi'i (founder of the Shafi'i madhhab, one of the primary schools of thought in Sunni Islamic jurisprudence), the Tomb of Sayyida Ruqayya, the Mosque of Sayyida Nafisa, and others.[13]