one time events: replace hack with propper JS

seen on http://www.sitepoint.com/create-one-time-events-javascript/