As mentioned in the FAQ, when trying to figure out the source of a problem, it's frequently useful to create a small, self-contained test page for replicating the problem in isolation. Why? Two reasons: Firstly, about 90% of the time, if you sit down and create a pared-down test case highlighting the problem, you'll figure out what's wrong yourself. Really. Instant help! Secondly, even if you don't find the answer yourself, you end up with a nice contained example other people can look at and help with.
Here's a template you can start with. Note the "TODO" markers.