var winWidth = 0;
var winHeight = 0;

// initialize window width/height variables:
if(typeof( window.outerWidth ) == 'number')
{	//Non-IE
	winWidth = window.innerWidth;
	winHeight = window.innerHeight;
}
else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
{	//IE 6+ in 'standards compliant mode'
	winWidth = document.documentElement.clientWidth;
	winHeight = document.documentElement.clientHeight;
}
else if(document.body && ( document.body.clientWidth || document.body.clientHeight))
{	//IE 4 compatible
	winWidth = document.body.clientWidth;
	winHeight = document.body.clientHeight;
}

function equalColumns() {
	var colIDs = new Array('contentLeft2','mainRightPage');

	var i;
	var maxHeightLeftCol;
	var cols;
	var indexRightCol;
	var topLeftCol;
	var topRightCol;
	var initWinHeightWidth = isResized();

	cols = new Array(colIDs.length);
	indexRightCol = colIDs.length - 1;
	maxHeightLeftCol = 0;

	externalLinks();

	// Find max height of first 3 columns;
	for(i = 0; i < indexRightCol; i++) 
	{
		cols[i] = document.getElementById(colIDs[i]);
		// By setting height property to auto, offsetHeight gets reset.
		// Otherwise, offsetHeight keeps previous max value. 
		cols[i].style.height = 'auto';
		cols[i].style.height = cols[i].offsetHeight;
		if(maxHeightLeftCol < cols[i].offsetHeight) 
		{	maxHeightLeftCol = cols[i].offsetHeight;
		}

	}
	cols[indexRightCol] = document.getElementById(colIDs[indexRightCol]);
	cols[indexRightCol].style.height = 'auto';

	// Find top offset difference between 3 (left) columns and 4th column (righ):
	var topLeftCol = findTop(cols[0]);
	var topRightCol = findTop(cols[indexRightCol]);
	dif = topLeftCol - topRightCol;

	// If right column is larger than left columns plus differnece:
	if(maxHeightLeftCol + dif < cols[indexRightCol].offsetHeight)
	{	for(i = 0; i < indexRightCol; i++) 
		{	cols[i].style.height = (cols[indexRightCol].offsetHeight - dif) + 'px';
			// resolve in a case padding is pressent offsetHeight = sytle.height + padding;
			if(cols[i].offsetHeight > (cols[indexRightCol].offsetHeight - dif))
				cols[i].style.height = ((2 * (cols[indexRightCol].offsetHeight - dif)) - cols[i].offsetHeight) + 'px';
		}
	}
	else
	{	cols[indexRightCol].style.height = (maxHeightLeftCol + dif) + 'px';
		// resolve in a case padding is pressent offsetHeight = sytle.height + padding;
		if(cols[indexRightCol].offsetHeight > (maxHeightLeftCol + dif))
			cols[indexRightCol].style.height = (2 * maxHeightLeftCol - cols[indexRightCol].offsetHeight) + 'px';
		for(i = 0; i < indexRightCol; i++) 
		{	cols[i].style.height = maxHeightLeftCol + "px";
			// resolve in a case padding is pressent offsetHeight = sytle.height + padding;
			if(cols[i].offsetHeight > maxHeightLeftCol)
				cols[i].style.height = (2 * maxHeightLeftCol - cols[i].offsetHeight) + 'px';
		}
		
	}

	if(typeof( window.outerWidth ) == 'number')
	{	//Non-IE
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{	//IE 6+ in 'standards compliant mode'
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
	}
	else if(document.body && ( document.body.clientWidth || document.body.clientHeight))
	{	//IE 4 compatible
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
	}

}

function findTop(obj) {
	var curtop = 0;
	if (obj.offsetParent) 
	{	curtop = obj.offsetTop;
		while (obj = obj.offsetParent) 
		{	curtop += obj.offsetTop;
		}
	}
	return curtop;
}

function reloadWindow()
{	if(isResized())
		window.document.location = window.document.location;
	return true;
}


function isResized()
{	var myWidth = 0, myHeight = 0;
	
	if(typeof( window.outerWidth ) == 'number')
	{	//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{	//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if(document.body && ( document.body.clientWidth || document.body.clientHeight))
	{	//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	//if((winHeight != myHeight) || (winWidth != myWidth))
	if((winWidth - 20) > myWidth || winWidth < myWidth)
	{	//alert(winWidth + ", " + myWidth);
		winHeight = myHeight;
		winWidth = myWidth;

		return true;
	}
	else
		return false;
}

//setup initialisation function
if(typeof window.addEventListener != 'undefined')
{
	//.. gecko, safari, konqueror and standard
	window.addEventListener('load', equalColumns, false);
	window.addEventListener('resize', reloadWindow, false);
}
else if(typeof document.addEventListener != 'undefined')
{
	//.. opera 7
	document.addEventListener('load', equalColumns, false);
	document.addEventListener('resize', reloadWindow, false);
}
else if(typeof window.attachEvent != 'undefined')
{
	//.. win/ie
	window.attachEvent('onload', equalColumns);
	window.attachEvent('onresize', reloadWindow);

}
 
//window.onresize=reloadWindow;
