The code you posted practically crashes my browser. You’re going to have a hard time getting anyone to crawl through all that code on this forum since it is mostly other users that are answering questions.
If you can narrow this down to a much simpler example that causes the same issue you might have better luck getting help.