window.onload = load_function;
window.onresize = load_function;

var x_count = 1;

function load_function() {
	dynamic_height();
}

function obj_height(id) {
	return(document.getElementById(id).offsetHeight);
}

function obj_width(id) {
	return(document.getElementById(id).offsetWidth);
}

function use(id) {
	return(document.getElementById(id));
}

function chkObject(id) {
    if (document.getElementById(id) != null) {
        return true;
    } else {
       return false;
    }
}

function getmaxheight_elements(tagname) {
	var children = use('container').getElementsByTagName(tagname);

	var max_height = 0;
    for (var x=0; x<children.length; x++) {
		if((children[x].offsetTop + children[x].offsetHeight) > max_height)
			max_height = children[x].offsetTop + children[x].offsetHeight;
    }

	return(max_height);
}

function dynamic_height() {
	var variable_height = 0;

	//if title is 2 lines or more
	if(obj_height('titel') > 100) {
		if(chkObject('sub_container')) {
			use('sub_container').style.top = obj_height('titel') - 67 + "px";
			variable_height = obj_height('titel') - 67;			
		}
	}

	//if provincie align map
	if(chkObject('provinciekaart')) {
		use('provinciekaart').style.left = obj_width('container') - 50 - obj_width('provinciekaart') + "px";
	}

	if(x_count < 2) {
		x_count++;

		var x = getmaxheight_elements('div');
		var y = getmaxheight_elements('img');
		var z = getmaxheight_elements('table');

		max_height = Math.max(x,y,z);

		//check if site is smaller dan viewport
		var site_height    = max_height + use('top_shadow').offsetTop;
		var browser_height = document.documentElement.clientHeight;

		if(site_height > browser_height) {
			use('container').style.height = max_height + 40 + variable_height + "px";
		} else {
			use('container').style.height = document.documentElement.clientHeight - use('top_shadow').offsetTop - 37 + 74 + "px";
		}
	}
}
