var starttime; var timeoutsec = 300; function cam1() { var url = "cam.php?RWY=09&i=60753645&t=" + Math.random(); $("#camgroot1").attr("src", url); ga('send', 'event', 'Webcams', 'load', 'CAM1'); if(Math.round(+new Date()/1000) < starttime+timeoutsec){ setTimeout(cam1,1000); }else{ openPopup(); } } function cam2() { var url = "cam.php?RWY=27&i=60753645&t=" + Math.random(); $("#camgroot2").attr("src", url); ga('send', 'event', 'Webcams', 'load', 'CAM2'); if(Math.round(+new Date()/1000) < starttime+timeoutsec){ setTimeout(cam2,1000); } } function startCameras(restart){ closePopup(); starttime = Math.round(+new Date()/1000); setTimeout(cam1,500); setTimeout(cam2,1000); if(restart==1){ga('send', 'event', 'Webcams', 'restart', 'CAM');} } function openPopup(){ $('#camTimeout').show(); $('#camTimeoutBG').show(); } function closePopup(){ $('#camTimeout').hide(); $('#camTimeoutBG').hide(); }