// time before we unhideDiv the first image (give time to get hands ready on keyboard) function pauseGame(seconds, end) { var popUpCounter = 0 var popUpTimer = setTimeout(loadPopupBox, 1) $('#popupBoxClose').click(function () { unloadPopupBox(); }); $('#container').click(function () { unloadPopupBox(); }); function loadPopupBox() { // To Load the Popupbox popUpCounter += 1; var counter = seconds - end var id; $('#popup_box').fadeIn("slow"); $("#container").css({ // this is just for style "opacity": "0.3" }); id = setInterval(function () { counter -= 1; if (counter < 0) { clearInterval(id); unloadPopupBox(); } else { $("#countDown").text("Paused for " + counter.toString() + " seconds."); } }, 1000); if (popUpCounter < 4) { popUpTimer = setTimeout(loadPopupBox, 1 * (popUpCounter + 1)); } else { clearTimeout(popUpTimer); } } }; function unloadPopupBox() { // TO Unload the Popupbox $('#popup_box').fadeOut("slow"); $("#container").css({ // this is just for style "opacity": "1" }); }