You can't really detect whether a person is logged in or not. If you want to automatically log them out, then you need to use some sort of timeout. For example, if they haven't loaded a page in the last 10 minutes, then they have to log in again. If they leave your site and come back within that time frame, they are still logged in. However, if a user is logged in, gets up to make a sandwich, then comes back, navigates to another page and discovers that he's been logged out, he could get a little peeved. You have to find a timeout value that fits.
As far as closing the browser goes -- if you use a cookie that expires when the the browser is closed, that will solve that issue for you.
You cannot use the unload event, however. Otherwise, every time the user opened a new page within your site, they'd have to log in. That would not be acceptable at any level, obviously.
Something I just thought of, however. You could check to see what domain the user is coming from. If they are coming from your own domain, then they are just loading another page on your site. If they came from somewhere else, force them to log in again. It's not technically a forced logout, and you aren't detecting that they are not on your site. You are detecting that that came FROM somewhere else.