Khaqani in his youth decided to embark on a pilgrimage to Mecca, against the wishes of his ruler and patron. In his first attempt to depart Shirvan, he was captured by Manuchihr's henchmen in the nearby Beylagan. Charged with being insubordinate, he was imprisoned for a period of 5 or 7 months in an ancient fortress in Shabaran, near Darband. Khaqani was condemned to a number of subsequent imprisonments, until in 1156-7 he succeeded in escaping and setting out on a lengthy expedition through the Middle East. His travels gave him material for his famous work "Tohfat al-ʿErāqayn" ("A Gift from the Two Iraqs"; in reference to western Iran ('Persian Iraq') and Mesopotamia ('Arabic Iraq'). He also composed his famous qasida "The Portals at Madāʾen", in which the contemplation of Taq-i Kisra (the ruins of the Sassanid Palace near Ctesiphon), according to Beelaert (2010) "elicits a warning about the transience of royal courts."