
/*
	Authors:		Dan Nye & Jeff Home, Coedit Limited - http://www.coedit.co.uk/
	Description:	Symphony Corp - Markup enhancing JavaScript
	Copyright:		Copyright 2007 - Coedit Limited - http://www.coedit.co.uk/

	Not to be reproduced without permission of the authors.
*/

function getElementsByClassName(classToFind, baseElement) {
	if (arguments.length == 1) {
		baseElement = document;		// Assume whole document if no base element passed in
	} else if (!baseElement) {
		return([]);					// If base element is passed in and doesn't exist, return empty array
	}

	var tempElements = baseElement.getElementsByTagName('*');

	// getElementsByTagName('*') doesn't work in IE 5.0/Win or IE 5.5/Win... so use this as a backup
	if (!tempElements.length && baseElement.all) tempElements = baseElement.all;

	var matchingElements = [];
	for (var loop=0; loop<tempElements.length; loop++) {
		if ((' ' + tempElements[loop].className + ' ').indexOf(' ' + classToFind + ' ') != -1) {
			matchingElements[matchingElements.length] = tempElements[loop];
		}
	}
	return(matchingElements);
}


function enhanceMarkup() {

	if (ieWin) {
		// Set z-indexes of menu items so that rounded corners appear OK
		var lis = document.getElementById('navigationUpper').getElementsByTagName('li');
		for (var loop=0; loop<lis.length; loop++) {
			lis[loop].style.zIndex = (lis.length + 1) - loop;
		}
	}

	// Set height of main pods on any page to the same height, if there is more than one on the page
	var podContainers = getElementsByClassName('mainBodyPromoContainer');
	if (podContainers.length == 1) {
		var pods = getElementsByClassName('promo', podContainers[0]);
		if (pods.length > 1) {
			// Set the text to flow naturally, then find the height of the largest pod
			for (var loop=0; loop<pods.length; loop++) {
				pods[loop].style.height = 'auto'
			}

			// Find largest height
			var theHeight = 0;
			for (var loop=0; loop<pods.length; loop++) {
				var tempHeight = parseInt(pods[loop].offsetHeight, 10);
				if (tempHeight > theHeight) theHeight = tempHeight;
			}

			// Take into 16px of top and bottom padding - assume padding on both pods is the same
			theHeight -= 32;

			// Set all pods to the max height
			for (var loop=0; loop<pods.length; loop++) {
				pods[loop].style.height = theHeight + 'px';
			}
		}
	}
}


window.onload = enhanceMarkup;

