Here's an interesting thread that may provide useful input to, or even solve, part of the problem you're looking at :

http://www.mycncuk.com/threads/12534...-and-reference