put the heading recognition into the scroll function

This way - when the layout changes e.g. because of loading images that
take time - the headings are up to date. Please recheck that I did it
well. I am not a javascript master.