I have the following code:
Your code is inconsistent. You're using jQuery.ready, onload, onpageshow at the same time. Seems like a good place to start your refactoring process.
jQuery.ready
onload
onpageshow
What do you really want to achieve?