diff --git a/js/bestpic.js b/js/bestpic.js index 29ceb41..2a1d70e 100644 --- a/js/bestpic.js +++ b/js/bestpic.js @@ -246,18 +246,36 @@ function onLoad() { function toggle() { - if (!document.getElementById('betoven').muted) { - document.getElementById('betoven').muted = true; + var audio = document.getElementById('betoven'); + var gallery = window.dreamgirlGallery; + var isRunning = gallery + ? !!gallery.isSlideshowRunning + : !!(audio && !audio.muted); + + if (isRunning) { + if (audio) { + audio.muted = true; + try { audio.pause(); } catch (e) {} + } + if (gallery && typeof gallery.pause === 'function') { + gallery.pause(); + } clearInterval(refreshIntervalId); + refreshIntervalId = null; $("#toggle").html("start"); } else { - document.getElementById('betoven').muted = false; - /* - refreshIntervalId = setInterval(function() { - var index = Math.floor(Math.random()*278) + 1; - $("#thumbs").html(""); - }, 3000); - */ + if (audio) { + audio.muted = false; + try { + var playPromise = audio.play(); + if (playPromise && typeof playPromise.catch === 'function') { + playPromise.catch(function () {}); + } + } catch (e) {} + } + if (gallery && typeof gallery.play === 'function') { + gallery.play(); + } $("#toggle").html("stop"); } }