table{min-width:100%}';
d.head.appendChild(st);
}catch(e){}
}
// A few tables are wider than a phone. Left alone they make the whole report slide sideways,
// which is what makes a vertical flick feel like it is fighting back. Each one gets its own
// horizontal scroller instead, so the page itself only ever moves up and down.
function wrapWide(k){
try{
var f=document.getElementById('fr-'+k), d=f.contentDocument;
if(!d||!d.body) return;
var W=d.documentElement.clientWidth;
[].slice.call(d.querySelectorAll('table')).forEach(function(t){
var p=t.parentElement;
if(p && p.className==='xscroll'){
if(t.scrollWidth<=W-24 && p.scrollWidth<=W) return; // still fine wrapped
return;
}
if(t.scrollWidth<=W-24) return;
var w=d.createElement('div'); w.className='xscroll';
t.parentNode.insertBefore(w,t); w.appendChild(t);
});
}catch(e){}
}
function load(k){
if(started[k]) return;
started[k]=true;
var f=document.getElementById('fr-'+k);
f.addEventListener('load',function(){
dress(f); wrapWide(k);
// charts and fonts settle a moment after load, so check the widths once more
setTimeout(function(){ wrapWide(k); }, 500);
});
f.srcdoc=src(k);
}
function show(k){
keys.forEach(function(x){
document.getElementById('pane-'+x).classList.toggle('on', x===k);
var b=document.querySelector('.tab[data-k="'+x+'"]');
b.classList.toggle('on', x===k);
b.setAttribute('aria-selected', x===k?'true':'false');
});
load(k);
if(history.replaceState) history.replaceState(null,'','#'+k);
}
document.querySelectorAll('.tab').forEach(function(b){
b.addEventListener('click',function(){ show(b.dataset.k); });
});
// only a width change can alter which tables need a sideways scroller
var lastW=window.innerWidth, rT;
window.addEventListener('resize',function(){
if(window.innerWidth===lastW) return;
lastW=window.innerWidth;
clearTimeout(rT); rT=setTimeout(function(){ keys.forEach(function(k){ if(started[k]) wrapWide(k); }); },200);
});
window.addEventListener('hashchange',function(){
var k=location.hash.replace('#',''); if(keys.indexOf(k)>-1) show(k);
});
// lift the two logo images out of the first report so the shell header matches the reports
var m=src('es').match(/[\s\S]*?<\/div>/);
if(m){
var imgs=m[0].match(/src="(data:image\/[^"]+)"/g)||[];
var plate=document.querySelectorAll('.plate img');
imgs.slice(0,2).forEach(function(s,i){ if(plate[i]) plate[i].src=s.slice(5,-1); });
}
var start=location.hash.replace('#','');
show(keys.indexOf(start)>-1?start:'es');
// warm the other two in the background so switching tabs is instant
setTimeout(function(){ keys.forEach(load); }, 1500);
})();