// Function to equalise the height of product pairs in the product summary page 
function equaliseProducts(){
	
	// Check that we can access elements by their tag name	
	if (!document.getElementsByTagName){ return; }
	
	// Grab all the div elements
	var allDivs = document.getElementsByTagName("div");
	
	// Set-up an array to hold all the title divs that need equalising
	var titleDivs = new Array();
	
	// Set-up an array to hold all the detail divs that need equalising
	var detailDivs = new Array();
	
	// Loop through all div elements
	for (var i=0; i<allDivs.length; i++){
		
		// Assign the current div element
		var currentDiv = allDivs[i];

		// If the current div element needs to be equalised - record it
		if (currentDiv.getAttribute("rel") == "eqTitle"){
			titleDivs.push(currentDiv);
		} else if (currentDiv.getAttribute("rel") == "eqDetail"){
			detailDivs.push(currentDiv);
		}
	}

	// Equalize the title divs
	for (var i=0; i<titleDivs.length; i=i+2){
		if (titleDivs[i] && titleDivs[i+1]){
			equalizeElements(titleDivs[i],titleDivs[i+1])
		}
	}

	// Equalize the detail divs
	for (var i=0; i<detailDivs.length; i=i+2){
		if (detailDivs[i] && detailDivs[i+1]){
			equalizeElements(detailDivs[i],detailDivs[i+1])
		}
	}
}

// Function to equalise the height of two elements
function equalizeElements(elm1,elm2){

	// If element 1 is taller than element 2
	if (elm1.clientHeight > elm2.clientHeight){
		elm2.style.height = elm1.clientHeight+'px';
	}
	// If element 2 is taller than element 1
	else if (elm2.clientHeight > elm1.clientHeight){
		elm1.style.height = elm2.clientHeight+'px';
	}
}
	
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

// run equaliseProducts onLoad
addLoadEvent(equaliseProducts);