First thing is to use [code] tags. This formats source code in a nice and readable format. I've modified your post for you.

A few comments about the actual code:

1. Parts of your code aren't...