replace the call to autocheck()
with the following.
$('#ID-of-button').on('click', checkNotifications());
Of course you must replace ID-of-button
with the ID of the toggle button for the notification bar. This will run the ajax call when the button is clicked, open or close.