var fixTemplateTimeout;

function fixTemplate() {
	var wrapper = document.getElementById("wrapper");
	
	/* Set wrapper back to auto height */
	wrapper.style.height = "auto";
	
	if (window.innerHeight) {
		var windowHeight = window.innerHeight;
		var wrapperHeight = wrapper.offsetHeight;
		if (wrapperHeight <= windowHeight) {
			wrapper.style.height = "" + (windowHeight-60) + "px"; /* 60 is the bottom padding on wrapper */
		}
	}
	else if (document.body.clientHeight) {
		var windowHeight = document.body.clientHeight;
		var wrapperHeight = wrapper.offsetHeight;
	
		if (wrapperHeight <= windowHeight) {
			wrapper.style.height = "" + windowHeight + "px";
		}
	}
}

window.onresize = function() {
	clearTimeout(fixTemplateTimeout);
	fixTemplateTimeout = setTimeout(fixTemplate, 100);
}

// Apply getElementById patch
if ( !document.getElementById ) {
    if ( document.all ) {
        document.getElementById = function( x ) {
            return this.all[x];
        }
    }
    else if ( document.layers ) {
        document.getElementById = function( x ) {
            return this[x];
        }
    }
}
