function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}



function equalizeHeights(itemToChange) {
	maxHeight = 0;
	divs = document.getElementsByTagName('*');
	for (i = 0; i < divs.length ; i++) {
		if ((divs[i].className) && (divs[i].className == itemToChange) && (divs[i].offsetHeight > 0)) {
			tempHeight = divs[i].offsetHeight;
			//alert(divs[i].style.paddingTop);
			if (tempHeight > maxHeight) {maxHeight = tempHeight;}
		}
	}
	for (i = 0; i < divs.length ; i++){
		if ((divs[i].className) && (divs[i].className == itemToChange) && (divs[i].offsetHeight > 0)) {
			divs[i].style.height = maxHeight + "px";
		}
	}
}


function setEqualHeights (tab) {
	if (typeof(tab) == 'undefined') {tab = document.getElementById('tabs-1');}// for intial page load
	var holdList = new Array();
	var calculateHeight = false;
	var j = 0;
	list = document.getElementsByTagName('dl');
	for (h = 0; h < list.length; h++){
		if (list[h].parentNode == tab){
			//alert('parentnode is correct');
			items = list[h].getElementsByTagName('dt');
			for (i = 0; i < items.length ; i++) {
					holdList[j] = items[i];
					//alert(j+holdList[j]+i+items[i]);
					//alert (holdList[j].parentNode.children[i+1].className);
					
					if (items[i+1]) {
						//holdList[j].parentNode.children[i+1].style.color = 'red';
						if (items[i+1].offsetTop > holdList[j].offsetTop)
						{calculateHeight = true;
						//alert (items[i]+" is last item in row is "+holdList[j]);
						} // end check for new row
					} // end compare next item
					else {
						calculateHeight = true;
						//holdList[j].style.color = "blue";
						//alert (items[i]+" last item is "+holdList[j]);
					}
					
					// calculate height
					if (calculateHeight == true) {
						//alert('calculating height');
						var maxHeight = 0;
						for (k = 0; k < holdList.length ; k++) {
							if (holdList[k].offsetHeight > maxHeight)
							{maxHeight = holdList[k].offsetHeight;}
						}
						for (k = 0; k < holdList.length; k++) {
							holdList[k].style.height = maxHeight + "px";
						}
						holdList.length = 0;
						j = 0;
						calculateHeight = false;
					}
					else j = j+1;
					
					// end calculate height
			} // end parse all elements
		}
	}
}

function showTab() {
	allDivs = document.getElementsByTagName('div');
	
	/*allTabs = document.getElementsByClassName('tabby'); //gets all tabs in an array
	x = allTabs.length;*/
	for(i = 0; i < allDivs.length ; i++) {
		DivId = allDivs[i].getAttribute("id");
		if ((DivId != null) && (DivId.substring(0,5) == "tabs-"))
		allDivs[i].className = 'inactive';
	}
	tabToShow = this.href;
	splitter = (tabToShow.lastIndexOf('#')) + 1;
	tabToShow = tabToShow.substring(splitter);
	tabToShow = document.getElementById(tabToShow);
	tabToShow.className = 'active';
	setEqualHeights(tabToShow);
	//setEqualHeights(tabToShow,'minorItem');
	return false;
}

function clickTab() {
	links = document.getElementById("tabSelectorList").getElementsByTagName('a');
	for(i = 0; i < links.length ; i++)
		links[i].onclick = showTab;
}
	

addLoadEvent(clickTab);
addLoadEvent(setEqualHeights);