This is an error in Firebug I keep seeing.
TypeError: $(\"#gallery-nav-button\") is null [Break On This Error] $(\'#gallery-nav-button\').addClass(\'anima
I agree with the advice given above, relating to the onload event. https://stackoverflow.com/a/18470043/2115934
A more simple solution (though not necessarily a better one) is to put your script tag just before the closing body tag of the document.
Document