95% of what you posted is javascript, yet you have a java main method at the end of your code? What are you trying to accomplish? What is the exact problem? And lastly, java != javascript.

Thread...