I also think you haven't yet provided enough information.
I didn't think that relevant
To determine what is relevant and what isn't, remove a piece of code. If the problem remains, that piece of code wasn't relevant, if the problem goes away or changes, that piece of code probably was relevant, so keep it in. One of the important aspects of a Short, Self-Contained, Correct Example is that it runs, so that we can download and run the code ourselves to reproduce the problem on our end - you'll get help much quicker this way, and with less guessing :-)
Also, in case you're not, Use strict and warnings.