It is not clear what code you have in the lightbox code and what code you have in the main page (or masterPage?).
Please separate the codes (and put each of them in a code block).
And a few comments:
- Make sure to have all the $w inside $w.onReady
- Use String and not Boolean as the value for the session method.