Wrapped all JS function in jQuery.ready(). It is ugly, but it will do till I have time to rewrite it.