You should take a look at this post:
It’s not quite what you asked for, but should provide a starting point.