/* ── 1. GAME DEMO MODAL ─────────────────────────────────────────── */
function initGameDemo() {
var modal = document.querySelector('.casino-demo-modal');
if (!modal) return;
var frame = modal.querySelector('.casino-demo-modal__frame');
var title = modal.querySelector('.casino-demo-modal__title');
var dialog = modal.querySelector('.casino-demo-modal__dialog');
var playReal = modal.querySelector('.casino-demo-modal__play-real');
var closeBtn = modal.querySelector('.casino-demo-modal__close');
var fsBtn = modal.querySelector('.casino-demo-modal__fullscreen');
var lastTrigger = null;
/* ── fullscreen helpers ── */
function getFullscreenEl() {
return document.fullscreenElement
|| document.webkitFullscreenElement
|| document.msFullscreenElement
|| null;
}
function exitFullscreen() {
if (document.exitFullscreen) return document.exitFullscreen();
if (document.webkitExitFullscreen) return document.webkitExitFullscreen();
if (document.msExitFullscreen) return document.msExitFullscreen();
}
function enterFullscreen() {
if (!dialog) return;
if (dialog.requestFullscreen) dialog.requestFullscreen();
else if (dialog.webkitRequestFullscreen) dialog.webkitRequestFullscreen();
else if (dialog.msRequestFullscreen) dialog.msRequestFullscreen();
}
function toggleFullscreen() {
if (getFullscreenEl()) {
exitFullscreen();
} else {
enterFullscreen();
}
}
/* sync button label when user exits fullscreen via Escape / browser UI */
function onFullscreenChange() {
var isFs = !!getFullscreenEl();
if (fsBtn) {
fsBtn.textContent = isFs ? '⛶' : '⛶';
fsBtn.setAttribute('aria-label', isFs ? 'Exit fullscreen' : 'Fullscreen');
}
if (dialog) dialog.classList.toggle('is-fullscreen', isFs);
}
document.addEventListener('fullscreenchange', onFullscreenChange);
document.addEventListener('webkitfullscreenchange', onFullscreenChange);
/* ── close demo ── */
function closeDemo() {
/* exit fullscreen first if active */
if (getFullscreenEl()) {
var p = exitFullscreen();
if (p && typeof p.then === 'function') {
p.then(doClose).catch(doClose);
} else {
setTimeout(doClose, 100);
}
return;
}
doClose();
}
function doClose() {
modal.classList.remove('is-open');
modal.setAttribute('aria-hidden', 'true');
document.body.classList.remove('demo-modal-open');
if (frame) frame.removeAttribute('src');
if (playReal) playReal.setAttribute('href', '#');
if (lastTrigger) { lastTrigger.focus(); lastTrigger = null; }
}
/* ── open demo ── */
function openDemo(trigger) {
if (!frame) return;
var src = trigger.getAttribute('data-demo-frame');
if (!src) return;
lastTrigger = trigger;
frame.setAttribute('src', src);
if (playReal) playReal.setAttribute('href', trigger.getAttribute('data-play-url') || '#');
if (title) title.textContent = trigger.getAttribute('data-demo-title') || 'Demo';
modal.classList.add('is-open');
modal.setAttribute('aria-hidden', 'false');
document.body.classList.add('demo-modal-open');
if (closeBtn) closeBtn.focus();
}
/* ── delegated click handler ── */
document.addEventListener('click', function (e) {
var openBtn = e.target.closest('.js-demo-open');
if (openBtn) { e.preventDefault(); openDemo(openBtn); return; }
var cls = e.target.closest('.js-demo-close');
if (cls) { e.preventDefault(); closeDemo(); return; }
var fs = e.target.closest('.js-demo-fullscreen');
if (fs) { e.preventDefault(); toggleFullscreen(); return; }
});
/* ── keyboard ── */
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && modal.classList.contains('is-open')) {
/* if in fullscreen, let the browser exit fullscreen first; don't close the modal */
if (getFullscreenEl()) return;
e.preventDefault();
closeDemo();
}
});
/* ── backdrop click (only backdrop, not .js-demo-close which is handled above) ── */
modal.querySelector('.casino-demo-modal__backdrop').addEventListener('click', function (e) {
e.stopPropagation(); // prevent double-fire from document handler
closeDemo();
});
}
/* ── 2. RANDOM GAMES (refresh button) ──────────────────────────── */
function initRandomGames() {
var wrap = document.querySelector('.random-games');
if (!wrap) return;
var pool = window.__randomGamesPool || [];
if (!Array.isArray(pool) || pool.length === 0) return;
var count = parseInt(wrap.getAttribute('data-count'), 10) || 4;
var playUrl = wrap.getAttribute('data-play') || '#';
var demoLabel = wrap.getAttribute('data-demo-label') || 'Demo';
var list = wrap.querySelector('.random-games__list');
var btn = wrap.querySelector('.random-games__refresh');
if (!list || !btn) return;
function shuffle(arr) {
for (var i = arr.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp;
}
return arr;
}
function escAttr(s) {
var d = document.createElement('div');
d.appendChild(document.createTextNode(s));
return d.innerHTML;
}
function buildCard(g, idx) {
var url = g.u || playUrl;
var html = '
';
html += '
';
if (g.i) html += '';
html += '
';
html += '';
if (g.d) {
html += '';
} else {
html += '';
}
html += '
';
html += '
';
if (g.t) html += '
' + escAttr(g.t) + '
';
html += '
';
return html;
}
list.style.transition = 'opacity .25s ease, transform .25s ease';
btn.addEventListener('click', function () {
btn.classList.add('is-spinning');
setTimeout(function () { btn.classList.remove('is-spinning'); }, 600);
var picks = shuffle(pool.slice()).slice(0, Math.min(count, pool.length));
list.style.opacity = '0';
list.style.transform = 'translateY(8px)';
setTimeout(function () {
var html = '';
for (var i = 0; i < picks.length; i++) html += buildCard(picks[i], i);
list.innerHTML = html;
list.style.opacity = '1';
list.style.transform = 'translateY(0)';
}, 250);
});
}
/* ── 3. FAQ ACCORDION ───────────────────────────────────────────── */
function initFaq() {
function openItem(item) {
var panel = item.querySelector('.faq-answer');
if (!panel) return;
item.classList.add('open');
panel.style.height = 'auto';
var target = panel.scrollHeight;
panel.style.height = '0px';
panel.offsetHeight; // reflow
panel.style.height = target + 'px';
panel.style.opacity = '1';
panel.addEventListener('transitionend', function te(e) {
if (e.propertyName !== 'height') return;
panel.removeEventListener('transitionend', te);
if (item.classList.contains('open')) panel.style.height = 'auto';
});
}
function closeItem(item) {
var panel = item.querySelector('.faq-answer');
if (!panel) return;
panel.style.height = panel.scrollHeight + 'px';
panel.offsetHeight;
panel.style.height = '0px';
panel.style.opacity = '0';
item.classList.remove('open');
}
document.addEventListener('click', function (e) {
var btn = e.target.closest('.faq-question');
if (!btn) return;
var item = btn.closest('.faq-item');
var expanded = item.classList.contains('open');
var icon = btn.querySelector('.faq-icon');
if (expanded) {
closeItem(item);
btn.setAttribute('aria-expanded', 'false');
if (icon) { icon.classList.remove('fa-minus'); icon.classList.add('fa-plus'); }
} else {
openItem(item);
btn.setAttribute('aria-expanded', 'true');
if (icon) { icon.classList.remove('fa-plus'); icon.classList.add('fa-minus'); }
}
});
var section = document.querySelector('#homepage-faq');
if (section && section.getAttribute('data-expanded-default') === '1') {
section.querySelectorAll('.faq-item').forEach(function (item) {
if (!item.classList.contains('open')) {
openItem(item);
var btn = item.querySelector('.faq-question');
if (btn) {
btn.setAttribute('aria-expanded', 'true');
var icon = btn.querySelector('.faq-icon');
if (icon) { icon.classList.remove('fa-plus'); icon.classList.add('fa-minus'); }
}
}
});
}
}
function initHeroVideo() {
var heroVideo = document.querySelector('.hero-bg-video');
if (!heroVideo) return;
function markReady(video) {
video.classList.add('visible');
}
heroVideo.loop = true;
heroVideo.muted = true;
if (heroVideo.readyState >= 2) {
markReady(heroVideo);
}
heroVideo.addEventListener('loadeddata', function () {
markReady(heroVideo);
}, { once: true });
heroVideo.addEventListener('canplay', function () {
markReady(heroVideo);
}, { once: true });
}
function initGoldDust() {
var hero = document.querySelector('.casino-hero');
if (!hero) return;
var canvas = document.createElement('canvas');
canvas.className = 'casino-hero-dust';
canvas.style.cssText = 'position:absolute;top:0;left:0;right:0;width:100%;height:100%;max-width:1280px;margin:0 auto;pointer-events:none;z-index:4;';
hero.appendChild(canvas);
var ctx = canvas.getContext('2d');
if (!ctx) return;
var W;
var H;
var raf = null;
var observer = null;
var COUNT = window.innerWidth < 780 ? 35 : 70;
var particles = [];
function resize() {
COUNT = window.innerWidth < 780 ? 35 : 70;
W = canvas.width = hero.offsetWidth;
H = canvas.height = hero.offsetHeight;
}
function makeParticle(randomY) {
var maxOp = Math.random() * 0.45 + 0.15;
return {
x: Math.random() * (W || 800),
y: randomY ? Math.random() * (H || 380) : (H || 380) + 10,
r: Math.random() * 2.2 + 0.4,
vy: Math.random() * 0.7 + 0.25,
vx: (Math.random() - 0.5) * 0.35,
opacity: randomY ? Math.random() * maxOp : 0,
maxOp: maxOp,
fadeIn: !randomY,
h: Math.random() * 16 + 42,
s: Math.random() * 18 + 72,
l: Math.random() * 22 + 58,
sparkle: Math.random() < 0.18,
sparkT: Math.random() * 200
};
}
function initParticles() {
particles = [];
for (var i = 0; i < COUNT; i++) {
particles.push(makeParticle(true));
}
}
function tick(p) {
p.y -= p.vy;
p.x += p.vx;
p.sparkT++;
if (p.fadeIn) {
p.opacity += 0.012;
if (p.opacity >= p.maxOp) p.fadeIn = false;
} else {
p.opacity -= 0.004;
}
if (p.opacity <= 0 || p.y < -8) return makeParticle(false);
return p;
}
function drawParticle(p) {
var op = p.opacity;
var grd;
if (p.sparkle) {
op *= 0.6 + 0.4 * Math.abs(Math.sin(p.sparkT * 0.07));
}
ctx.globalAlpha = op * 0.25;
grd = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, p.r * 4);
grd.addColorStop(0, 'hsl(' + p.h + ',' + p.s + '%,90%)');
grd.addColorStop(1, 'transparent');
ctx.fillStyle = grd;
ctx.beginPath();
ctx.arc(p.x, p.y, p.r * 4, 0, Math.PI * 2);
ctx.fill();
ctx.globalAlpha = op;
ctx.fillStyle = 'hsl(' + p.h + ',' + p.s + '%,' + p.l + '%)';
ctx.beginPath();
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2);
ctx.fill();
}
function loop() {
ctx.clearRect(0, 0, W, H);
for (var i = 0; i < particles.length; i++) {
particles[i] = tick(particles[i]);
drawParticle(particles[i]);
}
ctx.globalAlpha = 1;
raf = requestAnimationFrame(loop);
}
function start() {
if (!raf) loop();
}
function stop() {
if (raf) {
cancelAnimationFrame(raf);
raf = null;
}
}
if ('IntersectionObserver' in window) {
observer = new IntersectionObserver(function (entries) {
if (entries[0] && entries[0].isIntersecting) start();
else stop();
}, { threshold: 0.05 });
observer.observe(hero);
}
window.addEventListener('resize', function () {
resize();
particles.forEach(function (p) {
if (p.x > W) p.x = Math.random() * W;
});
});
resize();
initParticles();
start();
}
/* ── 4. MOBILE MENU TOGGLE ──────────────────────────────────────── */
function initMobileMenu() {
var toggle = document.querySelector('.menu-toggle');
var menu = document.getElementById('main-menu');
if (!toggle || !menu) return;
var headerRight = document.querySelector('.header-right');
var closeMenu = function () {
toggle.classList.remove('open');
menu.classList.remove('menu-open');
toggle.setAttribute('aria-expanded', 'false');
if (headerRight) headerRight.classList.remove('menu-open-active');
};
var openMenu = function () {
toggle.classList.add('open');
menu.classList.add('menu-open');
toggle.setAttribute('aria-expanded', 'true');
if (headerRight) headerRight.classList.add('menu-open-active');
};
if (window.innerWidth <= 1024) closeMenu();
toggle.addEventListener('click', function () {
toggle.classList.contains('open') ? closeMenu() : openMenu();
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') closeMenu();
});
document.addEventListener('click', function (e) {
if (!menu.classList.contains('menu-open')) return;
var within =
e.target.closest('#site-navigation') ||
e.target.closest('.menu-toggle') ||
e.target.closest('.submenu-toggle') ||
e.target.closest('.sub-menu');
if (!within) closeMenu();
});
window.addEventListener('resize', function () {
if (window.innerWidth > 1024) closeMenu();
});
}
/* ── 5. FOOTER ACCORDION (mobile) ──────────────────────────────── */
function initFooterAccordion() {
var bp = '(max-width: 770px)';
function setMaxHeight(listEl, expand) {
if (!listEl) return;
listEl.style.maxHeight = expand ? listEl.scrollHeight + 'px' : '0px';
}
function initOrReset() {
var mq = window.matchMedia(bp);
var cols = document.querySelectorAll('.site-footer .footer-col');
var headings = document.querySelectorAll('.site-footer .footer-heading');
headings.forEach(function (h) {
var list = h.parentElement.querySelector('.footer-links-list, .footer-contact-list');
if (!mq.matches) {
h.removeAttribute('role');
h.removeAttribute('tabindex');
h.removeAttribute('aria-expanded');
if (list) list.style.removeProperty('max-height');
h.parentElement.classList.remove('is-open');
return;
}
h.setAttribute('role', 'button');
h.setAttribute('tabindex', '0');
h.setAttribute('aria-expanded', 'false');
setMaxHeight(list, false);
if (h.dataset.bound === '1') return;
h.dataset.bound = '1';
var toggle = function () {
if (!mq.matches) return;
var col = h.parentElement;
var isNowOpen = !col.classList.contains('is-open');
cols.forEach(function (c) {
c.classList.remove('is-open');
var head = c.querySelector('.footer-heading');
var l = c.querySelector('.footer-links-list, .footer-contact-list');
if (head) head.setAttribute('aria-expanded', 'false');
setMaxHeight(l, false);
});
if (isNowOpen) {
col.classList.add('is-open');
h.setAttribute('aria-expanded', 'true');
setMaxHeight(list, true);
}
};
h.addEventListener('click', toggle);
h.addEventListener('keydown', function (e) {
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); toggle(); }
});
window.addEventListener('resize', function () {
if (mq.matches && h.parentElement.classList.contains('is-open')) setMaxHeight(list, true);
});
});
}
initOrReset();
window.addEventListener('resize', initOrReset);
window.matchMedia(bp).addEventListener('change', initOrReset);
}
/* ── 6. MOBILE SUBMENU TOGGLE ───────────────────────────────────── */
function initMobileSubmenu() {
var BP = 1024;
var menu = document.getElementById('main-menu');
if (!menu) return;
var getItems = function () { return menu.querySelectorAll('.menu-item-has-children'); };
var resetAll = function () {
getItems().forEach(function (li) {
li.classList.remove('submenu-open');
var btn = li.querySelector(':scope > a > .submenu-toggle');
var sub = li.querySelector(':scope > .sub-menu');
if (btn) btn.setAttribute('aria-expanded', 'false');
if (sub) sub.style.maxHeight = '0px';
});
};
var bindItem = function (li) {
if (!li || li.dataset.subBound === '1') return;
var link = li.querySelector(':scope > a');
var sub = li.querySelector(':scope > .sub-menu');
if (!link || !sub) return;
li.dataset.subBound = '1';
link.setAttribute('aria-haspopup', 'true');
var btn = document.createElement('button');
btn.type = 'button';
btn.className = 'submenu-toggle';
btn.setAttribute('aria-expanded', 'false');
btn.setAttribute('aria-label', (link.textContent || 'Submenu') + ' submenu');
btn.innerHTML = '';
link.appendChild(btn);
var open = function () {
li.classList.add('submenu-open');
btn.setAttribute('aria-expanded', 'true');
sub.style.maxHeight = sub.scrollHeight + 'px';
};
var close = function () {
li.classList.remove('submenu-open');
btn.setAttribute('aria-expanded', 'false');
sub.style.maxHeight = '0px';
};
var toggle = function (evt) {
if (window.innerWidth > BP) return;
evt.preventDefault();
if (li.classList.contains('submenu-open')) {
close();
} else {
Array.from(li.parentElement.children || []).forEach(function (sib) {
if (sib !== li && sib.classList && sib.classList.contains('submenu-open')) {
var sBtn = sib.querySelector(':scope > a > .submenu-toggle');
var sSub = sib.querySelector(':scope > .sub-menu');
sib.classList.remove('submenu-open');
if (sBtn) sBtn.setAttribute('aria-expanded', 'false');
if (sSub) sSub.style.maxHeight = '0px';
}
});
open();
}
};
btn.addEventListener('click', function (e) {
if (window.innerWidth > BP) return;
e.stopPropagation();
toggle(e);
});
btn.addEventListener('touchstart', function (e) {
if (window.innerWidth > BP) return;
e.preventDefault();
e.stopPropagation();
toggle(e);
}, { passive: false });
btn.addEventListener('keydown', function (e) {
if (window.innerWidth > BP) return;
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); e.stopPropagation(); toggle(e); }
});
window.addEventListener('resize', function () {
if (window.innerWidth > BP) {
sub.style.maxHeight = '';
li.classList.remove('submenu-open');
btn.setAttribute('aria-expanded', 'false');
} else if (li.classList.contains('submenu-open')) {
sub.style.maxHeight = sub.scrollHeight + 'px';
}
});
};
getItems().forEach(bindItem);
document.addEventListener('click', function (e) {
if (window.innerWidth > BP) return;
if (!e.target.closest('#site-navigation')) resetAll();
});
var burger = document.querySelector('.menu-toggle');
if (burger) {
burger.addEventListener('click', function () {
setTimeout(function () {
if (!menu.classList.contains('menu-open')) resetAll();
}, 0);
});
}
}
/* ── 7. WINNERS WIDGET (sidebar) ───────────────────────────────── */
function initWinnersWidget() {
var list = document.querySelector('.js-winners-sidebar');
if (!list) return;
var playUrl = (list.getAttribute('data-playurl') || '#').trim();
var currency = (list.getAttribute('data-currency') || '$').trim();
function toInt(v, d) { v = parseInt(v, 10); return isFinite(v) ? v : d; }
var minA = toInt(list.getAttribute('data-min'), 20);
var maxA = toInt(list.getAttribute('data-max'), 3000);
var rows = Math.max(1, Math.min(12, toInt(list.getAttribute('data-rows'), 7)));
var interval = Math.max(2, Math.min(60, toInt(list.getAttribute('data-interval'), 6)));
var noImage = list.getAttribute('data-noimage') || '';
var providers = [];
try {
providers = JSON.parse(list.getAttribute('data-providers') || '[]');
} catch (e) { providers = []; }
if (!Array.isArray(providers) || providers.length === 0) {
providers = noImage ? [noImage] : [];
}
function rand(n, m) { return Math.floor(Math.random() * (m - n + 1)) + n; }
var firstNames = ['Mia', 'Noah', 'Henry', 'Lucas', 'Isla', 'Olivia', 'Jack', 'Leo', 'Liam', 'Ava', 'Ethan', 'Sofia', 'Emma', 'Noa', 'Zoe', 'Ivy', 'Nina', 'Alex', 'Ben', 'Chloe', 'Hugo', 'Luca', 'Mila', 'Aria', 'Ella', 'Max', 'Owen', 'Ryan', 'Amy', 'Lily'];
var lastInitials = ['K', 'F', 'B', 'J', 'M', 'S', 'T', 'D', 'H', 'L', 'R', 'P', 'V', 'G', 'C', 'N'];
function fakeName() { return firstNames[rand(0, firstNames.length - 1)] + ' ' + lastInitials[rand(0, lastInitials.length - 1)] + '***'; }
function fakeAmount() { var v = rand(minA, maxA); try { return currency + ' ' + v.toLocaleString(); } catch (e) { return currency + ' ' + v; } }
function fakeAvatar() { return providers[rand(0, providers.length - 1)]; }
function createItem() {
var li = document.createElement('li');
li.className = 'winner-item';
li.tabIndex = 0;
li.setAttribute('role', 'link');
li.setAttribute('aria-label', 'Play now');
var img = document.createElement('img');
img.className = 'winner-avatar';
img.src = fakeAvatar();
img.alt = 'Winner avatar';
img.loading = 'lazy';
img.decoding = 'async';
var meta = document.createElement('div');
meta.className = 'winner-meta';
var name = document.createElement('div');
name.className = 'winner-name';
name.textContent = fakeName();
var amt = document.createElement('div');
amt.className = 'winner-amount';
amt.textContent = fakeAmount();
meta.appendChild(name);
meta.appendChild(amt);
li.appendChild(img);
li.appendChild(meta);
var openPlay = function () {
try { if (playUrl) window.open(playUrl, '_blank'); }
catch (e) { try { window.location.href = playUrl; } catch (_) { } }
};
li.addEventListener('click', openPlay);
li.addEventListener('keydown', function (e) {
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); openPlay(); }
});
requestAnimationFrame(function () { li.classList.add('is-in'); });
return li;
}
function seed() {
list.innerHTML = '';
for (var i = 0; i < rows; i++) {
var li = createItem();
li.style.transitionDelay = (i * 40) + 'ms';
list.appendChild(li);
}
}
seed();
setInterval(function () {
var li = createItem();
list.insertBefore(li, list.firstChild);
var items = list.querySelectorAll('.winner-item');
if (items.length > rows) items[items.length - 1].remove();
}, interval * 1000);
}
/* ── 8. SIDEBAR FREEZE ──────────────────────────────────────────── */
function initSidebarFreeze() {
function getAnchor() {
return document.querySelector('.latest-guides')
|| document.querySelector('footer.site-footer')
|| document.querySelector('.site-footer');
}
function freezeSidebar() {
var sb = document.querySelector('.site-sidebar');
var inner = sb ? sb.querySelector('.sidebar-inner') : null;
var anchor = getAnchor();
if (!sb || !inner || !anchor) return;
var mq = window.matchMedia('(min-width: 1025px)');
if (!mq.matches) {
inner.classList.remove('is-freeze');
inner.style.cssText = '';
sb.style.height = '';
sb.classList.remove('stop-sticky');
return;
}
var gap = 12;
var stickyTop = 16;
var innerH = inner.getBoundingClientRect().height;
var anchorDocTop = anchor.getBoundingClientRect().top + window.scrollY;
var shouldStop = (window.scrollY + stickyTop + innerH + gap) >= anchorDocTop;
if (shouldStop) {
sb.classList.add('stop-sticky');
} else {
sb.classList.remove('stop-sticky');
}
inner.classList.remove('is-freeze');
inner.style.position = '';
inner.style.top = '';
inner.style.left = '';
inner.style.width = '';
sb.style.height = '';
sb.style.position = '';
}
freezeSidebar();
window.addEventListener('load', freezeSidebar);
window.addEventListener('scroll', freezeSidebar, { passive: true });
window.addEventListener('resize', freezeSidebar);
}
/* ── 9. GAMES BLOCK SCROLLER ────────────────────────────────────── */
function initGamesScroller() {
document.querySelectorAll('.games-block').forEach(function (block) {
if (block.dataset.gamesScrollInit === '1') return;
block.dataset.gamesScrollInit = '1';
var list = block.querySelector('.games-list');
var prev = block.querySelector('.games-prev');
var next = block.querySelector('.games-next');
if (!list) return;
var step = 0;
var resizeTimer = null;
function getGap() {
var style = getComputedStyle(list);
return parseFloat(style.gap || style.columnGap || 0) || 0;
}
function calcStep() {
var card = list.querySelector('.game-card');
if (!card) return;
step = card.getBoundingClientRect().width + getGap();
}
function scroll(dir) {
if (!step) return;
list.scrollBy({ left: dir * step, behavior: 'smooth' });
}
function syncThumbHeight() {
var thumb = list.querySelector('.game-thumb');
var slider = block.querySelector('.games-slider');
if (thumb && slider) slider.style.setProperty('--thumb-h', thumb.offsetHeight + 'px');
}
function init() { calcStep(); syncThumbHeight(); }
if (prev) prev.addEventListener('click', function () { scroll(-1); });
if (next) next.addEventListener('click', function () { scroll(1); });
window.addEventListener('resize', function () {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(init, 200);
});
init();
});
}
/* ── 10. GET BONUS (floating trigger + modal) ───────────────────── */
function initGetBonus() {
var root = document.querySelector('.get-bonus');
if (!root) return;
var STORAGE_KEY = 'casino_gb_trigger_hidden_until';
var HIDE_FOR_MS = 30 * 60 * 1000;
var trigger = root.querySelector('.gb-trigger');
var dismissBtn = root.querySelector('.gb-trigger-dismiss');
var overlay = root.querySelector('.gb-overlay');
var closeBtn = root.querySelector('.gb-close');
var isDismissed = false;
function getHiddenUntil() {
try {
var raw = window.localStorage.getItem(STORAGE_KEY);
var value = raw ? parseInt(raw, 10) : 0;
return Number.isFinite(value) ? value : 0;
} catch (err) {
return 0;
}
}
function isHiddenByStorage() {
var hiddenUntil = getHiddenUntil();
if (hiddenUntil > Date.now()) return true;
if (hiddenUntil) {
try {
window.localStorage.removeItem(STORAGE_KEY);
} catch (err) { }
}
return false;
}
function dismissTrigger() {
isDismissed = true;
root.classList.remove('is-active');
root.classList.add('is-dismissed');
closeModal();
try {
window.localStorage.setItem(STORAGE_KEY, String(Date.now() + HIDE_FOR_MS));
} catch (err) { }
}
if (isHiddenByStorage()) {
isDismissed = true;
root.classList.remove('is-active');
root.classList.add('is-dismissed');
}
var hero = document.querySelector('.casino-hero');
if (hero) {
new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (isDismissed) {
root.classList.remove('is-active');
return;
}
root.classList.toggle('is-active', !entry.isIntersecting);
});
}, { threshold: 0 }).observe(hero);
} else {
setTimeout(function () {
if (!isDismissed) root.classList.add('is-active');
}, 1200);
}
function openModal() {
if (!overlay || isDismissed) return;
overlay.removeAttribute('hidden');
void overlay.offsetWidth;
overlay.classList.add('is-in');
document.body.style.overflow = 'hidden';
}
function closeModal() {
if (!overlay) return;
overlay.classList.remove('is-in');
document.body.style.overflow = '';
setTimeout(function () { overlay.setAttribute('hidden', ''); }, 320);
}
if (trigger) {
trigger.addEventListener('click', function (e) { e.preventDefault(); openModal(); });
trigger.addEventListener('touchend', function (e) { e.preventDefault(); openModal(); });
}
if (dismissBtn) {
dismissBtn.addEventListener('click', function (e) {
e.preventDefault();
e.stopPropagation();
dismissTrigger();
});
}
if (closeBtn) {
closeBtn.addEventListener('click', function (e) { e.preventDefault(); closeModal(); });
}
if (overlay) {
overlay.addEventListener('click', function (e) { if (e.target === overlay) closeModal(); });
}
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && overlay && overlay.classList.contains('is-in')) closeModal();
});
}
/* ── 11. Mobile bottom auth button ───────────────────── */
function initMobileAuthButton() {
const heroBtn = document.querySelector(".casino-hero-btn");
const mobileBar = document.querySelector(".auth-bottom-mobile");
if (!heroBtn || !mobileBar) return;
let activated = false;
const toggleVisibility = () => {
const rect = heroBtn.getBoundingClientRect();
if (activated && rect.top < 0) {
mobileBar.classList.add("is-visible");
} else {
mobileBar.classList.remove("is-visible");
}
};
const onScroll = () => {
if (window.scrollY > 5) activated = true;
toggleVisibility();
};
window.addEventListener("scroll", onScroll, { passive: true });
// run once on init (important for refresh mid-page)
toggleVisibility();
}
/* ── 12. Affiliate tracking ───────────────────── */
function initAffiliateTracking() {
const currentPage = location.href;
const title = document.title || '';
let currentPath = 'Homepage';
if (location.pathname && location.pathname !== '/') {
currentPath = location.pathname + location.search + location.hash;
}
document.addEventListener('click', function (e) {
const el = e.target.closest('a[href*="/go/"], button[onclick*="/go/"]');
if (!el) return;
let urlStr = '';
if (el.tagName === 'A') {
urlStr = el.href;
}
if (el.tagName === 'BUTTON') {
const match = el.getAttribute('onclick')?.match(/location\.href=['"]([^'"]+)['"]/);
if (match) urlStr = match[1];
}
if (!urlStr || !urlStr.includes('/go/')) return;
try {
let cta = (el.textContent || '')
.replace(/\s+/g, ' ')
.trim()
.slice(0, 50);
if (!cta) cta = 'cta';
const url = new URL(urlStr, location.origin);
url.searchParams.set('sub_id5', cta);
url.searchParams.set('sub_id6', currentPath);
url.searchParams.set('se_referrer', currentPage);
url.searchParams.set('default_keyword', title);
e.preventDefault();
window.location.href = url.toString();
} catch (err) { }
});
}
/* 13. MAIN ARTICLE EXPAND/COLLAPSE */
function initExpandableContent() {
var blocks = document.querySelectorAll('.js-expandable-content');
if (!blocks.length) return;
blocks.forEach(function (content) {
var toggle = content.parentElement ? content.parentElement.querySelector('.js-expandable-toggle') : null;
if (!toggle) return;
var collapsedHeight = parseInt(content.getAttribute('data-collapsed-height'), 10) || 250;
var reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
function setExpandedState(expanded) {
content.classList.toggle('is-expanded', expanded);
toggle.classList.toggle('is-expanded', expanded);
toggle.setAttribute('aria-expanded', expanded ? 'true' : 'false');
if (expanded) {
content.style.maxHeight = content.scrollHeight + 'px';
if (!reducedMotion) {
window.setTimeout(function () {
if (content.classList.contains('is-expanded')) {
content.style.maxHeight = 'none';
}
}, 360);
} else {
content.style.maxHeight = 'none';
}
} else {
if (content.style.maxHeight === 'none') {
content.style.maxHeight = content.scrollHeight + 'px';
content.offsetHeight;
}
content.style.maxHeight = collapsedHeight + 'px';
}
}
function measure() {
content.classList.remove('is-expanded');
toggle.classList.remove('is-expanded');
content.style.maxHeight = 'none';
var needsToggle = content.scrollHeight > (collapsedHeight + 24);
toggle.hidden = !needsToggle;
if (needsToggle) {
content.style.maxHeight = collapsedHeight + 'px';
toggle.setAttribute('aria-expanded', 'false');
} else {
content.style.maxHeight = 'none';
toggle.setAttribute('aria-expanded', 'false');
}
}
toggle.addEventListener('click', function () {
setExpandedState(!content.classList.contains('is-expanded'));
});
measure();
window.addEventListener('resize', measure);
});
}
/* ── SITEMAP ────────────────────────────────────────────────────── */
function initSitemap() {
var toggles = document.querySelectorAll('.sitemap-toggle');
if (!toggles.length) return;
toggles.forEach(function (btn) {
btn.addEventListener('click', function () {
var group = btn.closest('.sitemap-group');
var isExpanded = group.classList.contains('expanded');
// Close all open groups (accordion)
document.querySelectorAll('.sitemap-group.expanded').forEach(function (g) {
g.classList.remove('expanded');
var t = g.querySelector('.sitemap-toggle');
if (t) t.textContent = t.dataset.more;
});
// Open clicked group (if it wasn't already open)
if (!isExpanded) {
group.classList.add('expanded');
btn.textContent = btn.dataset.less;
}
});
});
}
/* ── INIT ───────────────────────────────────────────────────────── */
document.addEventListener('DOMContentLoaded', function () {
initHeroVideo();
initGoldDust();
initGameDemo();
initRandomGames();
initFaq();
initMobileMenu();
initFooterAccordion();
initMobileSubmenu();
initWinnersWidget();
initSidebarFreeze();
initGamesScroller();
initGetBonus();
initMobileAuthButton();
initAffiliateTracking();
initExpandableContent();
initSitemap();
});