It's probably best if you try to solve this yourself first as you'll gain much more by doing it this way. All that you need to know is present in the example code, you just have to modify it to your own ends.