In the beginning of the 12th century Shirvan attracted the attention of its expanding Georgian neighbours who on several occasions raided its territory. Shirvanshahs were in position of power shifting between Georgia and Seljuqid states. In 1112 David IV of Georgia gave his daughter Tamar in marriage to son of Shirvanshah Afridun I, Manuchihr III. Afridun lost many castles, including Qabala to David IV of Georgia in 1117 and 1120. After the death of Afridun I, who was murdered in the battle for Derbent, the throne in Shirvan passed to his son, Manuchir III (1120-1160). Manuchir III was under the influence of his wife, Georgian princess Tamar and maintained pro-Georgian orientation. After decisive victory of Battle of Didgori Manuchir rejected to pay tribute to Eldiguzids. Depriving from the tributes in the amount of 40 thousand "dinars", the Seljuqid Sultan Mahmud directed to Shirvan at the beginning of 1123, captured Shamakhi and took Shah as hostage contrary to Manuchehr's betrayal.