// Get element to add ad to
const ad = document.getElementById('flash-banner-ad');

// Show ad
if (hasFlash) {
	// Get list of ads
	var request = new XMLHttpRequest();
	request.open("GET", "/flash/ads/ads.json", false);
	request.send(null);
	const adList = JSON.parse(request.responseText);
	
	// Pick random ad to embed
	let i = Math.floor(Math.random() * adList.length);
	let randomAd = adList[i];
	
	ad.innerHTML = `
		<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="780" height="100">
			<param name="movie" value="/flash/ads/${randomAd}.swf">
			<param name="quality" value="high">
			<embed src="/flash/ads/${randomAd}.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="780" height="100"></embed>
		</object>
	`;
} else {
	ad.innerHTML = "<p>This content requires Flash player or Ruffle.</p>";
}
ad.innerHTML += "<p id=\"ad-disclaimer\">The ads used on this site are historic flash banner ads.</p>"
