The best way I've found to fix a problem like that is to remove half of the relevant code again and again until you find a section where taking it away fixes the bug. After you've found the broken section, keep splitting it until the problem goes away again. Split that section etc until you find the exact location of the bug. Once you've found the exact location, slowly put things back together.
Some of those bugs for me have been caused by an invisible whitespace character or Internet Explorer's bad rendering rules.