// equlize column
var currentTallest = 0,
		currentRowStart = 0,
		rowDivs = new Array();

function setConformingHeight(el, newHeight) {
	// set the height to something new, but remember the original height in case things change
	el.data("originalHeight", (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight")));
	el.height(newHeight);
}

function getOriginalHeight(el) {
	// if the height has changed, send the originalHeight
	return (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight"));
}

function columnConform() {

	// find the tallest DIV in the row, and set the heights of all of the DIVs to match it.
	$('.motivos > li').each(function() {
	
		// "caching"
		var $el = $(this);
		
		var topPosition = $el.position().top;

		if (currentRowStart != topPosition) {

			// we just came to a new row.  Set all the heights on the completed row
			for(currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) setConformingHeight(rowDivs[currentDiv], currentTallest);

			// set the variables for the new row
			rowDivs.length = 0; // empty the array
			currentRowStart = topPosition;
			currentTallest = getOriginalHeight($el);
			rowDivs.push($el);

		} else {

			// another div on the current row.  Add it to the list and check if it's taller
			rowDivs.push($el);
			currentTallest = (currentTallest < getOriginalHeight($el)) ? (getOriginalHeight($el)) : (currentTallest);

		}
		// do the last row
		for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) setConformingHeight(rowDivs[currentDiv], currentTallest);

	});

}


$(window).resize(function() {
	columnConform();
});

// Dom Ready
// You might also want to wait until window.onload if images are the things that
// are unequalizing the blocks
$(function() {
	columnConform();
});

// Show and Hide contents from White Paper tab | Hide and Show contents from Footer Extra Info
if (document.getElementById){ 
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('.infomenu{display: block;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("div"); 
		if(el.style.display != "block"){ 
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu")
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function SwitchInfo(obj, linkId){
	if(document.getElementById){
	var linkEl = document.getElementById(linkId);
	var el = document.getElementById(obj);
	var ar = document.getElementById("extrainfo").getElementsByTagName("div"); 
		if(el.style.display != "none"){ 
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="infomenu")
				ar[i].style.display = "block";
			}
			el.style.display = "none";
			linkEl.className += " infohover"; 
		}else{
			linkEl.className = linkEl.className.replace(' infohover','');
			el.style.display = "block";
		}
	}
}

