// 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("primarycontent")) setHeights("primarycontent", maxH)
	if (maxH=getMaxHeight("middlecontent")) setHeights("middlecontent", maxH);
	//if (maxH=getMaxHeight("videos")) setHeights("videos", maxH);
	//if (maxH=getMaxHeight("reports_l1")) setHeights("reports_l1", maxH)
	//if (maxH=getMaxHeight("galleries_l1")) setHeights("galleries_l1", 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) {
	
		if (elementId == "primarycontent") {
			var blocks = holder.getElementsByTagName("div");
			for(var i = 0; i < blocks.length; i++){
				//alert("found block("+i+") class("+blocks[i].className+")");
				//if (type=="primarycontent") {
					//alert("got class("+blocks[i].className+")");
					if(blocks[i].className == 'panel-dblue' || blocks[i].className == 'sphere'){ // we only want <div class="block">
						height = blocks[i].offsetHeight;
						//alert ("got "+elementId+"  height("+height+")");
						if (height>maxHeight) maxHeight=height;
					}
				//}
			}
		}
		else if (elementId == "middlecontent") {
			var blocks = holder.getElementsByTagName("div");
			for(var i = 0; i < blocks.length; i++){
				//alert("found block("+i+") class("+blocks[i].className+") id("+blocks[i].id+")");
				if(blocks[i].id == 'boxes' || blocks[i].id == 'middleright'){ // we only want <div class="block">
					height = blocks[i].offsetHeight;
					//alert ("got "+elementId+"  height("+height+")");
					if (height>maxHeight) maxHeight=height;
				}
			}
			//alert ("got max("+maxHeight+") for "+type);	
		}
	}
	
	//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 (type=="primarycontent") {
				if(blocks[i].className == 'panel-dblue' || blocks[i].className == 'sphere'){ // we only want <div class="block">
					//alert ("got height("+blocks[i].offsetHeight+") need("+height+")");
					if (blocks[i].offsetHeight<height) {
						if (blocks[i].className=="panel-dblue") {
							var offset = height - blocks[i].offsetHeight;
							document.getElementById("news-options").style.marginTop = (offset-5)+"px";
						}
						else {
							blocks[i].style.height=(height-5)+"px";
						}
					}
				}
			}
			else if (type=="middlecontent") {
				if(blocks[i].id == 'boxes' || blocks[i].id == 'middleright'){ 
					//alert ("got height("+blocks[i].offsetHeight+") need("+height+")");
					if (blocks[i].offsetHeight<height) {
						var offset = height - blocks[i].offsetHeight;
						//alert ("offset = "+offset);
						if (blocks[i].id=="boxes") {
							//alert("set margin bottom on box-row-2 to offset+25");
							document.getElementById("box-row-2").style.marginTop = offset+"px";
						}
						else {
							//alert("set margin top on event-options to offset-4");
							document.getElementById("event-options").style.marginTop = offset+"px";
							/*
							var inner = blocks[i].getElementsByTagName("div");
							for(var j = 0; j < blocks.length; j++){
								if (inner[j].className=="sp_c") {
									inner[j].style.paddingBottom = offset+"px"
								}
							}
							*/
						}
					}
				}
			}
		}
	}

}

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