The issue of Turkey's relationship to the Islamic State was raised on a recent thread. Here is a hypothesis (based mostly on informed speculation) designed to provoke discussion of the issue.
Erdogan's vision for the future of Turkey is a re-created "empire", with Turkey at its centre and himself at its head. He is realist enough to know that the form of the new empire will be quite different from the old Ottoman Empire: it will most likely be a treaty alliance of Muslim countries in the MENA area. And that it will take time to bring it into being.
The eruption of the IS to Turkey's south has speeded things up. They have brought the Sunni areas of Iraq into play, and pose a major threat to Assad of Syria, Erdogan's principal current target. They are also a counter to the Kurds in the area. Their establishment in Iraq and Syria would suit his plans. While treading carefully, he will aid them in achieving this goal. Once established, he may also be able to use them later against the Saudis and the Gulfies.
The resurrection of the Caliphate by al Baghdadi has added a new dimension to his plans and prospects. If he could some day assume this mantle, his authority and influence would extend throughout the Sunni Muslim world. An added reason for him to not only prevent the destruction of the IS, but indeed to help it succeed.
The taking over of the IS after it is established in Syria and Iraq, and possibly beyond, would be a delicate operation - a smooth change-over at the top. He is probably already planning and preparing for it by inserting Turkish agents into its top layers, and establishing clandestine relations with the former Iraqi officials already there. At an appropriate time, the Salafis leading the IS would be quietly removed, and a more cooperative head would take over. Someone who, at the appropriate time, would transfer the title of Caliph of Islam to the most powerful Muslim leader of the time ‒ Recep Tayyip Erdoğan.
It is a very difficult path that Erdogan is treading, but the prize at the end is worth the risks and problems. He has to not only fight off and defeat enemies, but has also to deceive, fend off and neutralize friends and allies. It will be interesting to see if he is clever enough to pull it off.