The attacks in Istanbul on Tuesday night came as a shock to many around the world but for a country that once prided itself as the Middle Easts pro-western, outward-looking beacon of stability, conflict and bombings are starting to become the norm.
These were Turkeys fifth major terrorist attacks in less than a year, and came amid a series of catastrophic policy failures at both home and abroad.
Turkeys government and its president, Recep Tayyip Erdo?an, the head of the ruling Justice and Development party (AKP), have invested heavily in the continuing conflict in Syria, devoting considerable resources to the toppling of the Bashar al-Assad regime even when in recent years the international community has opted for a political rather than military settlement to the conflict. Once Syrias rebellion against the Assad regime became dominated by Islamic fundamentalists, these groups became central to Turkeys foreign policy objectives. Ankara acquiesced to jihadi groups entering Syria across its borders and enabled them to establish a presence in Turkey to arm and fund their campaign.
Much of the focus in the international media has been on jihadis leaving Europe for Syria via Turkey, and vice versa. But for several years, Islamic State has established deep roots in Turkish society, with the city of Gaziantepfunctioning as a key hub for explosives and an important launchpad for jihadi groups.
As the Turkey expert Aaron Stein notes, Isis and its supporters have grafted on to older, well-established al-Qaida-linked networks in Turkey and have functioned with little interference from the government.
To compound Turkeys security challenges the government restarted its conflict with the Kurdistan Workers party (PKK) last year after a two-year ceasefire.
The PKK has fought the state for the past 40 years for a combination of political and human rights for the countrys beleaguered Kurds. Its sister group and major western ally, the Democratic Union party (PYD), has risen to international acclaim during the course of the Syria war and has established an autonomous Kurdish region in northern Syria.
In recent months the PYD has secured areas alongside the borders with Turkey that have hampered efforts to smuggle fighters and resources into Syria. The ascent of the Kurds in Syria, together with renewed conflict with the PKK, has led to divisive rhetoric from Erdo?an that has polarised the country and inflamed ethnic and sectarian tensions, conditions that many believe propelled Erdo?an and the AKP to electoral success after last years parliamentary elections.
Turkey has also become increasingly disconnected from its friends and allies in the international community, which has undermined coordination with Europe on matters of intelligence and security. Ankara has rejected western alignments. It did not support western sanctions on Russia, voted against US-backed security council sanctions on Iran and before the Arab uprisings forged strong ties with Iran and Syria, whose governments at the time were facilitating and sponsoring terrorist attacks in Iraq against US personnel and Iraqi civilians.
Erdo?an also strained relations with Israel and courted Sudans President Omar al-Bashir, who is wanted by the international criminal court for genocide and war crimes in Darfur.
Turkey has options if it wants to move forward. It has betrayed its friends and allies but has not lost them completely. Turkey is becoming increasingly inclined to support a political settlement to the conflict in Syria. In recent weeks, it has soughtrapprochement with Israel following the severing of ties in 2010 after the Gaza flotilla raid, and with Russia after Turkey downed one of its jets last November.
These tentative steps to repair relations could help rebuild alliances and bring stability, but questions remain as to whether Turkey has accepted the realities of a dramatically reconfigured region.
Turkey may yet refuse to provide its full and active support to a political settlement in Syria. As a result, it may struggle to contain the jihadi cells that have flourished for so long, the individuals and groups that cause immense destruction in Turkey but which still constitute the forces equipped and dedicated to toppling the Assad regime.
Further, major allies such as the US and other powers, among them Russia and Iran, no longer view Syria and the region in the way Turkey still does. They have, in many respects, moved on. They may now see Syrias future as a loose federation of different regions.
Will Turkey accept and work with the PYD and Syrias autonomous Kurdish region? As it stands, that would be unlikely, at least until it resolves its conflict with the PKK. It may see endorsement of Syrian Kurdistan as something that could empower the PKK further.
But Turkey has been here before. After initial reluctance, it chose to work with Iraqs Kurds and their autonomous region in the 1990s. It has also negotiated with the PKK on previous occasions and knows that the PKK, unlike Isis and other Islamic fundamentalist groups, has negotiable objectives.
Turkeys problems, while tied to the Syria conflict to a significant extent, are largely of its own making. In other words, Turkeys government can resolve the conflicts it finds itself embroiled in. That requires clamping down on the Islamic fundamentalist groups Turkey has allowed to flourish. It also requires returning to negotiations with the PKK and adopting a conciliatory outlook and tone that remedies ethnic polarisation and restores the friendships Turkey once enjoyed with its neighbours and the international community.