When Sunni rebels rose up against Syria's Bashar al-Assad in 2011, Turkey reclassified its protégé as a pariah, expecting him to lose power within months and join the autocrats of Egypt, Libya, Tunisia and Yemen on the scrap heap of the "Arab Spring".
Assad, in contrast, shielded diplomatically by Russia and with military and financial support from Iran and its Shi’ite allies in Lebanon's Hezbollah, warned that the fires of Syria’s sectarian war would burn its neighbors.
For Turkey, despite the confidence of Tayyip Erdogan, elected this summer to the presidency after 11 years as prime minister and three straight general election victories, Assad’s warning is starting to ring uncomfortably true.
Turkey’s foreign policy is in ruins. Its once shining image as a Muslim democracy and regional power in the NATO alliance and at the doors of the European Union is badly tarnished.
Amid a backlash against political Islam across the region Erdogan is still irritating his Arab neighbors by offering himself as a Sunni Islamist champion.
The world, meanwhile, is transfixed by the desperate siege of Kobani, the Syrian Kurdish town just over Turkey’s border, under attack by extremist Sunni fighters of the Islamic State (IS) who are threatening to massacre its defenders.
Erdogan has enraged Turkey’s own Kurdish minority – about a fifth of the population and half of all Kurds across the region – by seeming to prefer that IS jihadis extend their territorial gains in Syria and Iraq rather than that Kurdish insurgents consolidate local power.
Kurdish refugees from Kobani watch as thick smoke covers the Syrian town of Kobani during fighting between Islamic State and Kurdish Peshmerga forces, as seen from the Mursitpinar crossing on the Turkish-Syrian border in Sanliurfa province October October 26, 2014.
The forces holding on in Kobani are part of the Democratic Union Party (PYD), closely allied to the Kurdistan Workers Party (PKK), which has fought a 30-year war against the Turkish state and is now holding peace talks with Ankara.
Meanwhile, Turkish tanks stood idly by as the unequal fight raged between the PYD and IS, while Erdogan said both groups were "terrorists" and Kobani would soon fall. It was a public relations disaster.
It drew criticism from NATO allies in the US-led coalition, which has bombed jihadi positions around the town in coordination with the PYD. It also prompted Kurdish riots across south-east Turkey resulting in more than 40 dead.
At the same time, Turkey's air force bombed PKK positions near the Iraqi border for the first time in two years, calling into question the 2013 ceasefire declared by Abdullah Ocalan, the jailed PKK leader. PKK commanders warned that if Turkey let Kobani fall, they would go back to war.
Yet now that the United States has dropped arms to Kobani’s defenders, Erdogan has been forced to relent and open a Turkish corridor for Peshmerga fighters from Iraq to reinforce Kobani.
Turkish officials fear this will provoke reprisals in Turkey by IS, activating networks it built during the two years the Erdogan government allowed jihadi volunteers to cross its territory to fight in Syria. Almost anything Turkey does now comes with big risks.
The polarization within Turkey along sectarian and ethnic lines - which analysts say Erdogan has courted with his stridently Sunni tone as communal conflict between Sunni and Shi'ite rages to Turkey’s south - is easy to detect in the poor and deeply conservative district of Fatih in Istanbul.
“I prefer to have IS than PKK in control of Kobani,” says Sitki, a shopkeeper. “They are Muslims and we are Muslims. (But) we as Muslims should be ruled by the Koran under Sharia law."
Another local shopkeeper, Nurullah, 35, broadly agreed:
“The only mistake the government has made is to open the door to Kurdish refugees. PYD and PKK are the same, both terrorists. How do (the Americans) have the nerve to ask us to help PYD?”
“Of course Islamic State has sympathizers here because they are wiping out the PKK,” Nurullah continued.
Nearby, a bearded Arabic-speaking man who declined to be named said it made sense that “Turkey as a Sunni nation supports IS over the crusaders”, a hostile reference to the US-led coalition against IS of which Turkey looks an unwilling party.
The increasingly overt Sunni alignment of Erdogan’s Turkey is, paradoxically, contributing to its isolation, at a time when the United States has won the support of the Sunni Arab powers, led by Saudi Arabia, in the campaign against IS.
Partly, that is because Erdogan and his new prime minister Ahmet Davutoglu, who as foreign minister was the architect of Turkey’s eastward turn away from the EU, continue to champion the pan-Islamic Muslim Brotherhood, ousted in Egypt last year and banned across the Gulf.
Turkey's President Tayyip Erdogan waves as he attends a debate marking the reconvene of the parliament after a summer recess at the Turkish Parliament in Ankara October 1, 2014.
But it is also because of Ankara’s ambivalence towards IS, which some in Turkey’s government saw as a bulwark against its three main regional adversaries: the Assad regime, the Shi'ite-led government in Iraq, and the Kurds.
“Their policy is making Turkey look completely isolated”, says Hugh Pope of the International Crisis Group.
Yet there is a wide consensus that Erdogan and his Islamist Justice and Development Party (AKP) tried and failed to take a leadership role as the turmoil of the Arab Spring swept across the region and have ended up by infecting Turkey’s secular republic with the sectarianism plaguing the Levant.
"From a zero problems policy (with neighbors) to zero neighbors,” said a headline in the leftist Evrensel newspaper in reference to the AKP policy of entente with neighboring states.
IS fighting Turkey's enemies
Behlul Ozkan, a political scientist at Istanbul’s Marmara University, says the Erdogan government has supported Islamist movements in the Middle East to establish a sphere of influence and play a leadership role.
“When the Arab Spring started, Davutoglu saw it as an opportunity for his imperial fantasy of establishing the Ikhwan (Muslim Brotherhood) belt from Tunisia to Gaza.
"They are obsessed with destroying the Assad regime. They see IS as an opportunity for Turkey since it is fighting its enemies on three fronts: against Baghdad’s Shi’ite-dominated leadership, against Assad, and the PYD, which is an affiliate of the PKK.”
Soli Ozel, a prominent academic and commentator, said the Erdogan government's initial expectation was that the Muslim Brotherhood would come to power in Syria.
“Turkish officials believed a year and a half ago they could control the jihadis but they played with fire. This was a policy of sectarianism and they got into something ... they couldn’t control, and that is why we are here”.
Other commentators and Turkish officials say Western and Arab powers that called for Assad to be toppled but refused to give mainstream Syrian rebels the weapons to do it are to blame for the rise of Jihadis in the resulting vacuum.
“They (Turkish officials) bet on Assad to fall and when they lost, instead of backing off they are doubling down,” says Hakan Altinay of the Brookings Institution. “They are not the only culprits. The international community is also a culprit in this affair”.
Caught between two fires
But uppermost among Ankara’s fears is the prospect that Syrian Kurds led by the PYD -- newly legitimized by their alliance with the United States -- will establish a new Kurdish entity on Turkey’s frontiers, which will incite Turkey's Kurds to seek self government.
“In the realpolitik of all this, IS is fighting all the enemies of Turkey -- the Assad regime, Iraqi Shi'ites and the Kurds -- but the spillover effect is that it is now paying the price in terms of its vulnerability on the Kurdish question,” says Kadri Gursel, a prominent liberal columnist.
Cengiz Candar, veteran columnist and expert on the Kurdish issue adds: “If Syrian Kurds are successful and establish self-rule they will set a precedent and a model for Turkey’s Kurds, and more than 50 percent of Kurds in the world live here”.
Turkey is thus caught between two fires: the possibility of the PKK-led Kurdish insurgency inside Turkey reviving because of Ankara’s policy towards the Syrian Kurds; and the risk that a more robust policy against IS will provoke reprisal attacks that could be damage its economy and the tourist industry that provides Turkey with around a tenth of its income.
Internationally, one veteran Turkish diplomat fears, IS “is acting as a catalyst legitimizing support for an independent Kurdish state not just in Syria but in Turkey” at a time when leading powers have started to question Turkey’s ideological and security affiliations with the West.