Strange bug in attachEvent() method