var oldonload = window.onload;

if (typeof(oldonload) == 'function') {
	window.onload = function(){
		oldonload();
		myOnload();
	}
}
else {
	window.onload = function(){
		myOnload();
	}
}

window.onresize = function() {
	setContentHeight();
	setContentWidth();
}

function myOnload() {
	drawBG();
	setContentHeight();
	setContentWidth();
}


function drawBG() {
	var bg = document.createElement('img');
	bg.setAttribute('src', 'images/bg_no_corners.gif');
	bg.setAttribute('id', 'background');
	document.body.appendChild(bg);
}

function getWindowHeight() {
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') {
		windowHeight=window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body&&document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getWindowWidth() {
	var windowWidth=0;
	if (typeof(window.innerWidth)=='number') {
		windowWidth=window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body&&document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}

function setContentHeight() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var headerHeight = document.getElementById("content_title").offsetHeight + 20;
			var footerHeight = 50;
			
			var mainElement = document.getElementById('content');
			var mainHeight = mainElement.offsetHeight;
			
			mainElement.style.height = (windowHeight - (headerHeight + footerHeight)) + 'px'; 
		}
	}
}

function setContentWidth() {
	if (document.getElementById) {
		var windowWidth = getWindowWidth();
		if (windowWidth > 0) {
			var leftWidth = document.getElementById("left_quote").offsetWidth + 20;
			var rightWidth = 50;
			
			var mainElement = document.getElementById('content_container');
			var mainWidth = mainElement.offsetWidth;
			
			mainElement.style.width = (windowWidth - (leftWidth + rightWidth)) + 'px'; 
		}
	}
}

function setNavWidth() {
	var navDiv = document.getElementById('nav');
	var navUL;
	var navCount = 0;
	var itemWidth = 115;
	
	for (i=0;i<navDiv.childNodes.length;i++) {
		if (navDiv.childNodes[i].nodeName == 'UL')
			navUL = navDiv.childNodes[i];
	}
	
	for (i=0;i<navUL.childNodes.length;i++) {
		if (navUL.childNodes[i].nodeName == 'LI') {
			navCount++;
		}
	}
	
	if (navCount > 0) {
		if ( !((navCount * itemWidth) > (getWindowWidth() - 200)) ) {
			navUL.style.width = (navCount * itemWidth) + 'px';
		}
	}
}

function showSubCat(maincatid) {
	var subCatElement = document.getElementById("sub_of_" + maincatid);
	if (subCatElement) {
		if (subCatElement.className != "hide") {
			subCatElement.className = "hide";
		}
		else {
			subCatElement.className = "";
		}
	}
	else {
		window.location = "browse.asp?catid=" + maincatid;
	}
}
