I've seen something similar in a different thread. You might find some parts of that post helpful, not everything obviously, but I still think it's worth checking out.
http://stevenrgerst.com/k14-yv/21/articles-nydpoFU-4778/page/function.session-start