I asked the same question several months ago:http://themeforest.net/forums/thread/looking-for-plugintutorialhowto/69746
May this helps you as well.
That’s exactly what i was looking for.
I’ve made a script out of it and enhanced it a little bit. If you’re interested I can send this to you via e-mail, pastebin or similar. You tell me…
I’m using it in my work but haven’t made it completely ready for the public, altough it works pretty fine.