' + esc(camp.brand) + '
' +
'
' + esc(BASE.badge) + '' + esc(camp.zlava) + '
' +
'
' + esc(camp.sub) + '
' +
(camp.foto.length ? '
' + imgs + '
' : '') +
'
' + camp.untilHtml + '
' +
'
' + esc(camp.left) + '
' +
'
' + esc(BASE.cta) + ' → ' + dd;
a.__camp = camp;
a.addEventListener('click', function (e) {
if (e.target.closest('.k-x')) {
e.preventDefault(); e.stopPropagation();
if (a.classList.contains('pop')) { closePop(); return; }
ssSet(KEY_MIN, '1'); track('ags_sky_close', camp, { ags_sky_velkost: size }); layout(true);
return;
}
track('ags_sky_click', camp, { ags_sky_velkost: a.classList.contains('pop') ? 'tab' : size });
});
a.addEventListener('mouseenter', function () { hover = true; });
a.addEventListener('mouseleave', function () { hover = false; });
[].forEach.call(a.querySelectorAll('.k-ph img'), function (im) {
im.addEventListener('error', function () { im.parentNode && im.parentNode.removeChild(im); if (!a.querySelector('.k-ph img')) { var ph = a.querySelector('.k-ph'); if (ph) ph.style.display = 'none'; } else showPhoto(a, a.__photo || 0); });
});
if (!camp.foto.length) { var ph0 = a.querySelector('.k-ph'); if (ph0) ph0.style.display = 'none'; }
showPhoto(a, start || 0);
return a;
}
// ---------- rozloženie ----------
var els = { L: null, R: null, pop: null }, tabs = [], mode = '', viewed = {}, pair = 0, hover = false;
var reduce = window.matchMedia && matchMedia('(prefers-reduced-motion: reduce)').matches;
function rm(el) { if (el && el.parentNode) el.parentNode.removeChild(el); }
function contW() {
var c = document.querySelector('main > .container') || document.querySelector('.container');
return c ? c.getBoundingClientRect().width : 1170;
}
function topMin() {
var nb = document.querySelector('.navbar-fixed-top'); // admin lišta BUXUS
return (nb && nb.offsetHeight ? nb.getBoundingClientRect().bottom : 0) + 16;
}
function pickMode() {
var w = document.documentElement.clientWidth || innerWidth;
if (w < 768) return 'none';
if (ssGet(KEY_MIN)) return 'tab';
var g = (w - contW()) / 2;
if (g >= 316) return 'w300';
if (g >= 172) return 'w160';
return 'tab';
}
function scaleFor(h) { return Math.max(0.55, Math.min(1, (innerHeight - topMin() - 16) / h)); }
function seen(camp, size) { var k = camp.id + '|' + size; if (!viewed[k]) { viewed[k] = 1; track('ags_sky_view', camp, { ags_sky_velkost: size }); } }
function slotCamps() {
var n = CAMPS.length;
if (n === 1) return [CAMPS[0], CAMPS[0]];
return [CAMPS[pair % n], CAMPS[(pair + 1) % n]];
}
function dotsFor(camp) { return CAMPS.length > 2 ? { n: CAMPS.length, k: CAMPS.indexOf(camp) } : null; }
function placeSides() {
if (mode !== 'w300' && mode !== 'w160') return;
var W = mode === 'w300' ? 300 : 160, w = document.documentElement.clientWidth, cw = contW();
var g = (w - cw) / 2, s = scaleFor(600), H = 600 * s;
var main = document.querySelector('main') || document.body;
var ft = document.querySelector('footer');
var y = Math.max(topMin(), main.getBoundingClientRect().top);
if (ft) y = Math.min(y, ft.getBoundingClientRect().top - H - 16);
var x = Math.round((g - W) / 2);
[['L', x], ['R', w - x - W]].forEach(function (p) {
var el = els[p[0]]; if (!el) return;
el.style.left = p[1] + 'px'; el.style.top = Math.round(y) + 'px';
el.style.transform = s < 1 ? 'scale(' + s.toFixed(3) + ')' : '';
});
}
function buildSides(fadeIn) {
var cs = slotCamps(), size = mode;
['L', 'R'].forEach(function (k, i) {
var old = els[k];
var nu = card(cs[i], size, cs[0] === cs[1] ? i : 0, dotsFor(cs[i]));
if (fadeIn) nu.classList.add('fade');
els[k] = nu; document.body.appendChild(nu);
seen(cs[i], size);
if (old) { old.classList.add('fade'); setTimeout(function () { rm(old); }, 400); }
});
placeSides();
if (fadeIn) setTimeout(function () { ['L', 'R'].forEach(function (k) { if (els[k]) els[k].classList.remove('fade'); }); }, 30);
}
function placeTabs() {
if (!tabs.length) return;
var tm = topMin(), gap = 8, fs = 13;
function hOf(t) { return Math.round(t.__len * fs * 0.78 + 34); }
var total = 0; tabs.forEach(function (t) { total += hOf(t) + gap; }); total -= gap;
var avail = innerHeight - tm - 16;
if (total > avail) { fs = 11; total = 0; tabs.forEach(function (t) { total += hOf(t) + gap; }); total -= gap; }
var y = Math.max(tm, Math.round((innerHeight - total) / 2));
tabs.forEach(function (t) {
var h = hOf(t);
t.style.top = y + 'px'; t.style.height = h + 'px'; t.firstChild.style.fontSize = fs + 'px';
t.__mid = y + h / 2; y += h + gap;
});
if (els.pop) {
var s = scaleFor(600), H = 600 * s, t0 = els.pop.__tab;
var py = t0 ? t0.__mid - H / 2 : (innerHeight - H) / 2;
py = Math.max(tm, Math.min(py, innerHeight - H - 16));
els.pop.style.transform = s < 1 ? 'scale(' + s.toFixed(3) + ')' : '';
els.pop.style.top = Math.round(py) + 'px';
}
}
function openPop(t) {
var same = els.pop && els.pop.__tab === t;
closePop();
if (same) return;
var p = card(t.__camp, 'w300', 0, null); p.classList.add('pop'); p.__tab = t;
els.pop = p; t.classList.add('act');
document.body.appendChild(p); placeTabs();
seen(t.__camp, 'tab');
}
function closePop() { if (els.pop) { if (els.pop.__tab) els.pop.__tab.classList.remove('act'); rm(els.pop); els.pop = null; } }
function clearAll() { rm(els.L); rm(els.R); els.L = els.R = null; closePop(); tabs.forEach(rm); tabs = []; }
function layout(force) {
var m = pickMode();
if (m === mode && !force) { placeSides(); placeTabs(); return; }
mode = m; clearAll();
if (m === 'none') return;
if (m === 'tab') {
CAMPS.forEach(function (camp) {
var b = document.createElement('button');
var label = camp.brand + ' ' + camp.zlava;
b.type = 'button'; b.className = 'agsky-tab';
b.style.setProperty('--agsky-c', camp.color);
b.setAttribute('aria-label', label);
b.innerHTML = '