// Make all blocks (divs) on one page the same height as the tallest one (when faux columns can't be used)

function getHeights(){
	//check for standards compliance
	if(!document.getElementById) return;
	if(!document.getElementsByTagName) return;
	
	var maxH
	if (maxH=getMaxHeight("project-box")) setHeights("project-box", maxH)
}
	
	
function getMaxHeight(type) {
	var maxHeight=0;
	var elementId=type
	//alert("check id("+elementId+")");
	var holder = document.getElementById(elementId);

	// Does this page contain this holder???
	if (holder) {
	
		var blocks = holder.getElementsByTagName("div");
		for(var i = 0; i < blocks.length; i++){
			//alert("found block("+i+") class("+blocks[i].className+")");
			if(blocks[i].className.substr(0,10) == 'border-box') { // we only want <div class="landing-panel">
				height = blocks[i].offsetHeight;
				//alert ("got "+elementId+"  height("+height+")");
				if (height>maxHeight) maxHeight=height;
			}
		}
	
	}
	
	//alert ("got max("+maxHeight+") for "+type);	
	return maxHeight;
}

// make all divs the same height in pixels. must be run on window resize, text increase/decrease. (a ballache basically.)
function setHeights(type, height){
	var elementId=type;
	var holder = document.getElementById(elementId);
	
	if (!holder) alert ("Failed to get holder for "+type);
	else {
		var blocks = holder.getElementsByTagName("div");
		for(var i = 0; i < blocks.length; i++){
			if(blocks[i].className.substr(0,10) == 'border-box') { // we only want <div class="block">

				thisheight = blocks[i].offsetHeight;
				diff = height - thisheight;
				//alert ("this box["+i+"] is "+diff+" out");
				if (diff > 0) {
					var para = blocks[i].getElementsByTagName("h3");
					var curheight = para[0].offsetHeight;
					newheight = (curheight + diff - 10) + "px"; // Have to remove 10 as offsetheight includes padding but setting the height does not.
					//alert(para[0] + "was("+curheight+") should be "+newheight);
					para[0].style.height = newheight;
					//blocks[i].style.height=height+"px";
				}
			}
		}
	}
}

//addEvent(window,"load",getHeights);