/**************************************************************

	Set a div to a height if smaller... Or to page height or to a
	static height, depending on parameters and content of said div's.

	Author : Tom van Gemert
	For: TriMedia interactive projects
	http://www.TriMedia.nl
	Added to project: 20051207

	Script based on: http://www.saila.com/attic/sandbox/set-height.html


	Dit script is aangepast door Jean-Peter Adams op 8-3-2006 voor AZZZ.nl
	content, content_left en content_right worden op de goede lengte gezet
	container krijgt 20px extra spacing mee aan de onderkant.

**************************************************************/

function pageHeight() {

  var myWidth = 0, myHeight = 0;

  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myHeight = document.body.clientHeight;
  }
  //window.alert( 'Height = ' + myHeight );
  return myHeight;

}

function sortit(a,b){
	return(a-b)
}

function set_div_height(static_height, min_height) {

	page_height = pageHeight();
	d = document;

	box = new Array("left_1b","left_2b"); 		//list of DIV ids
	box_top_space = new Array(20,10); 		//list of DIV's position from top (of containing div). Positioning + margins
	box_length = box.length;
	box_heights = new Array(box_length);
	for(x = 0; x < box_length; x++) {

		boxname = box[x];

		if (d.getElementById(box[x]) != null) {
	  		h = d.getElementById(box[x]).offsetHeight + box_top_space[x];
	  		box_heights[x] = h;

	  		//alert("Boxname " + boxname + " Height: " + h);

	  	} else {
	  		box_heights[x] = 0;
	  	}

	 }

	box_heights.sort(sortit);
	tallest_h = box_heights[(box_length-1)];
	
	//alert("min_height: " + min_height + " tallest_h: " + tallest_h + " page_height: " + page_height);



	if (static_height != "") {
		for(x = 0; x < box_length; x++) {

		  if (d.getElementById(box[x]) != null) {
		  	d.getElementById(box[x]).style.height = static_height - box_top_space[x] + "px";
		  }

		}

	} else {

		if (tallest_h < min_height) {

			for(x = 0; x < box_length; x++) {

			  if (d.getElementById(box[x]) != null) {

			  	d.getElementById(box[x]).style.height = min_height - box_top_space[x] + "px";

			  }

			}

		} else if (box_top_space[0] + tallest_h <= page_height) {
			for(x = 0; x < box_length; x++) {
		
				if (d.getElementById(box[x]) != null) {
		
			  		d.getElementById(box[x]).style.height = tallest_h - box_top_space[x] + "px";
			  	}
		
			}


		} else if (tallest_h < page_height) {
			for(x = 0; x < box_length; x++) {

				if (d.getElementById(box[x]) != null) {

			  		d.getElementById(box[x]).style.height = page_height - box_top_space[x] + "px";
			  	}

			}



		} else {
			for(x = 0; x < box_length; x++) {

				if (d.getElementById(box[x]) != null) {

			  		d.getElementById(box[x]).style.height = tallest_h - box_top_space[x] + "px";
			  		d.getElementById(box[0]).style.height = 109 + tallest_h - box_top_space[0] + "px";
			  		
			  	}

			}

		}

	}

}
