Well, this is certainly not my area of expertise. I'd have to muck around with it for a while.
I guess what you could do is register an onclick handler for the entire document.body and then any click not "caught" by some other handler would trigger the close.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.