JS reorg and many bug fixes, bug fix of lightbox