My simple solution:

http://pastie.caboo.se/207066

- donald