First, for future reference please use the code tags. Second, you've posted a huge amount of code that many users may not want to wade through. I recommend trying to boil it down to an SSCCE.