This issue will require a fair bit of instruction, so I have included a link to the source material for your information. As to the code, it is very difficult to evaluate in the format provided, so I recommend using wikisend.com to send a link to the files or to otherwise upload the file set if you want a closer look at it. If you have a look at the following link, you will find that it describes how to handle loading events, and I hope you find it helpful! Thanks!
Ah! That not working we will want to use "console.log()" if it is acceptable to have a wait for the pictures to load. Since it sounds like you know your code well, I have a link to that info for code example, etc. I know I know, a console wait and timeout is a dirty solution but it should work with little implementation and coding.
Please don't forget to rate and accept! :)