Just pasted this code up on CodeSnippets - it may be of use to some people here:

http://www.bigbold.com/snippets/posts/show/1996