Didn't exactly set off a debate over best practices. Oh well.
I realized today that the if statement should be:
if (typeof ntWindowShowing=="undefined")
otherwise the script throws an error after a restart of the application. Seems to have something to do with the difference between an undeclared variable and an undefined one.