// JavaScript Document
function overlay() {
	el = document.getElementById("overlay");
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
	resizeHandler();
}

function changeContent(p){
	gamePath = p;
	//alert("Game Path = "+gamePath);
	Spry.Utils.updateContent('overlay','brochure.html');
	overlay();
}

function changeContentBlank(p){
	gamePath = p;
	//alert("Game Path = "+gamePath);
	Spry.Utils.updateContent('overlay','blank.html');
	overlay();
}

function closeOverlay(d){
	changeContentBlank();
}

function resizeHandler(){
	//alert("Width: "+window.innerWidth+" Height:"+window.innerHeight);
	var _w = f_clientWidth();
	var _h = f_clientHeight();
	
	var frame = document.getElementById("overlay");
	var htmlheight = document.body.parentNode.scrollheight;  
	var windowheight = window.innerHeight;
	if ( htmlheight < windowheight ) { document.body.style.height = windowheight + "px"; frame.style.height = windowheight + "px"; }
	//else { document.body.style.height = htmlheight + "px"; frame.style.height = htmlheight + "px"; }
	if(frame != null){
		var overlayHolder = document.getElementById("overlay");
		frame.style.left = (((_w-968)/2))+'px';
		frame.style.top = (((_h-409)/2))+'px';
	}
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
