See my post here:
http://www.codeguru.com/forum/showpost.php?p=1934569&postcount=15
for an example of how a similar problem could be solved very cleanly.