ISSUE
It seems like the problem arises when your script is unable to locate the DOM element. The element needs to be present in the DOM before it can be used by JavaScript.
TROUBLESHOOTING
Instead of the line
var topoffooter=$('#myfooter').offset().top;
, try to alert the length of the jQuery object
alert($('#myfooter').length);
The length must be greater than zero for it to function properly. If not, we are on the right track to resolving the issue.
RESOLUTION
1) To resolve this, you can place the scripts just before the closing of the body tag - </body>
- RECOMMENDED
2) Alternatively, execute your scripts on the document (DOM) ready event using jQuery's
$(document).ready()
http://api.jquery.com/ready/