/* layout enhancer, used on every page.
 * Mathieu Gagnon <zebrocratie.org>
 */


/* 1. this should be done on resize but "some browser" dies upon it */
function yftcca_initLayout() {
	var maxH = 0;
	function maxHeight(id, maxH) {
		if (!document.getElementById(id))
			return maxH;
		var newH = document.getElementById(id).offsetHeight;
		return (newH > maxH) ? newH : maxH;
	}

	maxH = maxHeight('l', maxH);
	maxH = maxHeight('c', maxH);
	maxH = maxHeight('r', maxH);
	document.getElementById('l').style.height = maxH + 'px';
}


/* 2. menu highlights */
function yftcca_initMenu(currentElement, depth) {
	if (currentElement.nodeType != 1)
		return;
	var child = null;

	for (var i = 0; i < currentElement.childNodes.length; i++) {
		child = currentElement.childNodes[i];

		if (child.tagName && child.tagName.toUpperCase() == 'A')
			if ((child.href.indexOf('instructors') >=0 &&  window.location.href == child.href)
			|| (child.href.indexOf('instructors') == -1 &&  window.location.href.indexOf(child.href) >= 0))
			/* if (window.location.href.indexOf(child.href) >= 0) */
				child.className = 'menu-active';

		yftcca_initMenu(child, depth + 1);
	}
}


/* 3. let's play ! */
if (document.getElementById) {
	yftcca_initLayout();
	yftcca_initMenu(document.getElementById('h-menu'), 0);
	yftcca_initMenu(document.getElementById('l'), 0);
}


