function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
		}
	else {
		window.onload = function() {
			oldonload();
			func();
			}
		}
	}

function fit_flash() {
	var slideshow;
	var initial_height;
	var margin;
	var ratio;

	addLoadEvent(init);

	function init() {
		slideshow = document.getElementById("slideshow");
		initial_height = slideshow.height;
		margin = slideshow.offsetTop;
		ratio = slideshow.width/slideshow.height;

		window.onresize = resize;
		resize();
		}

	function resize() {
		var window_height = window.innerHeight || document.documentElement.clientHeight;
		var target_height = Math.max(window_height - 2*margin, 400);

		if (target_height < initial_height) {
			slideshow.height = target_height;
			slideshow.width = target_height*ratio;
			}
		else {
			slideshow.height = initial_height;
			slideshow.width = initial_height*ratio;
			}
		}
	}

fit_flash();
