/*
 * Thanks to stchur for fixing the IE6 resize bug via the below functions resize(), initIE6(), and getViewportSize()!!
 * http://ecmascript.stchur.com/2006/09/06/the-ie-resize-bug-revisited/ (solution)
 * http://www.stchur.com/personal/resize2.html (example)
 */




function detectIE()
{
	/*

	Thanks to http://etc.ecordero.net/index.php/2006/10/02/javascript-object-detection-targeting-ie-6-or-ie-7/
	for this test!
	
	- window.external
		Only IE returns true
		
	- typeof window.XMLHttpRequest:
		IE 6 returns undefined
		IE 7 & Safari returns object
		Firefox returns function.
	
	Tested with IE 6 and IE 7 RC.
	
	*/

	if (window.external && (typeof window.XMLHttpRequest == "undefined")) {
		return 'ie6';
	} else if (window.external && (typeof window.XMLHttpRequest == "object")) {
		return 'ie7';
	} else {
		return false;
	}

}




function moveSubcontent()
{

	// Moves #content_sub from below the main content block to a position below the secondary navigation
	
	var subNav = document.getElementById('nav_sub');
	var content = document.getElementById('content');
	var mainContent = document.getElementById('content_main');
	var subContent = document.getElementById('content_sub');
	
	// move the secondary content to the sidebar
	var offset1 = subNav.offsetHeight + subNav.offsetTop - 48;
	if(subContent) {
		subContent.style.position="absolute";
		subContent.style.width="11em";
		//subContent.style.right="-15em";
		if(detectIE() == 'ie6') {
			subContent.style.right="1em";
		} else {
			subContent.style.right="-15em";
		}
		subContent.style.top = offset1 + "px";
		var offset2 = subContent.offsetHeight + subNav.offsetHeight + subNav.offsetTop - 48;
	} else {
		var offset2 = offset1;
	}

	// expand the content area to the length of the sidebar if the sidebar is longer
	if(mainContent.offsetHeight < offset2) {
		content.style.height = offset2 + "px";
	} else {
		content.style.height = mainContent.offsetHeight + "px";
	}
	
}



function resize()
{
	var currentSize = getContentSize();
	if (currentSize != content_prevSize) {
		content_prevSize = currentSize;
		moveSubcontent();
	}
}



function init()
{
	window.content_prevSize = getContentSize();
	setInterval(resize, 100);
	moveSubcontent();
}



function getContentSize()
{
	return document.getElementById('content_main').offsetHeight;
}



init();
