(function(){ function pad(n){return (n<10?'0':'')+n;}function fmt(min){var h=Math.floor(min/60),m=Math.round(min%60);if(m===60){h++;m=0;}return h?h+' h '+pad(m)+' min':m+' min';} var est=document.querySelector('[data-estimator]'); if(est){var mode='foot',dist=est.querySelector('[name=distance]'),unit=est.querySelector('[name=unit]'),locks=est.querySelector('[name=locks]'),pace=est.querySelector('[name=pace]'),perLock=est.querySelector('[name=perlock]'),start=est.querySelector('[name=start]'),out=est.querySelector('[data-out]'); var paces={foot:[['2','Gentle stroll, 2 mph'],['2.6','Steady walk, 2.6 mph'],['3.2','Brisk, 3.2 mph']],boat:[['2','Careful cruising, 2 mph'],['2.5','Typical canal speed, 2.5 mph'],['3','Fast as the rules allow, 3 mph']]}; function fill(){pace.innerHTML='';paces[mode].forEach(function(p,i){var o=document.createElement('option');o.value=p[0];o.textContent=p[1];if(i===1)o.selected=true;pace.appendChild(o);});perLock.value=mode==='foot'?3:15;} function run(){var d=parseFloat(dist.value);if(unit.value==='km')d=d/1.609;var n=Math.max(0,parseInt(locks.value,10)||0);var v=parseFloat(pace.value);var pl=Math.max(0,parseFloat(perLock.value)||0); if(!(d>=0)||!(v>0)){out.innerHTML='
Enter a distance to see an estimate.
';return;} var moving=d/v*60,lockTime=n*pl,total=moving+lockTime;out.innerHTML='';var big=document.createElement('p');big.className='big';big.textContent='About '+fmt(total);out.appendChild(big); var t=document.createElement('table');[['Moving time',fmt(moving)],[mode==='foot'?'Stopping to watch '+n+' locks':'Working '+n+' locks',fmt(lockTime)],['Distance',(unit.value==='km'?(d*1.609).toFixed(1)+' km':d.toFixed(1)+' miles')]].forEach(function(r){var tr=document.createElement('tr');r.forEach(function(c){var td=document.createElement('td');td.textContent=c;tr.appendChild(td);});t.appendChild(tr);});out.appendChild(t); var p=document.createElement('p');if(start.value){var s=start.value.split(':');var m=(parseInt(s[0],10)*60+parseInt(s[1],10)+total)%(24*60);p.textContent='Leaving at '+start.value+', expect to arrive around '+pad(Math.floor(m/60))+':'+pad(Math.round(m%60))+'.';} else p.textContent=mode==='foot'?'Canals are flat, so the pace is the whole story; add time for cafés, photographs and gongoozling.':'Sharing locks with another boat roughly halves the lock time; a queue at a flight can double it.';out.appendChild(p);} est.querySelectorAll('[data-mode]').forEach(function(b){b.addEventListener('click',function(){mode=b.getAttribute('data-mode');est.querySelectorAll('[data-mode]').forEach(function(x){x.setAttribute('aria-pressed',x===b?'true':'false');});fill();run();});}); [dist,unit,locks,pace,perLock,start].forEach(function(el){el.addEventListener('input',run);el.addEventListener('change',run);}); var qs=window.location.search,qm=qs.match(/[?&]miles=([\d.]+)/),ql=qs.match(/[?&]locks=(\d+)/);if(qm)dist.value=qm[1];if(ql)locks.value=ql[1];fill();run();} var gl=document.querySelector('[data-glossary]'); if(gl){var q=gl.querySelector('[name=q]'),count=gl.querySelector('[data-count]'),items=gl.querySelectorAll('dl.terms > div'); function filter(){var s=q.value.trim().toLowerCase();var n=0;items.forEach(function(it){var ok=!s||it.getAttribute('data-text').indexOf(s)>=0;it.hidden=!ok;if(ok)n++;});count.textContent=s?n+' of '+items.length+' terms match':items.length+' terms';} q.addEventListener('input',filter);filter();} })();