/*
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}
*/

//addLoadEvent(function() {
	// Pop Menus -- thank you, projectseven!
	//P7_initPM(1, 0, 1, -20, 10);
	// Equal Columns -- thank you, projectseven!
	//P7_equalCols2(1, 'pageleafheightdiv', 'DIV', 'pagediv', 'DIV');
//});



var $G = function(n) {
	return document.getElementById(n);
};

function KDS_INIT() {
	
	// on all pages except the homepage, make the mastheaddiv clickable!
	if (!$G('homepage')) {
		$G('mastheaddiv').onclick = function() { window.location='/'; };
		$G('mastheaddiv').style.cursor='pointer';
		$G('mastheaddiv').title='Return to Homepage';
	}
	
	// if we are on the "application" page, then remove the link for the "apply now" action!
	if ($G('applicationpage')) {
		// remove the "a" as well as containing parent "li"
		var a = $G('actiondiv').getElementsByTagName('a')[0];
		a.parentNode.removeChild(a);
		var b = $G('actiondiv').getElementsByTagName('li')[0];
		b.parentNode.removeChild(b);
	}
	
	setActiveNav();
	
	KDS_SETCOLS();
	
}


function KDS_SETCOLS() {
	// strecth the container-overlay absolute div to match that of the containerdiv.
	//P7_equalCols2(1, 'container-overlay-inner', 'DIV', 'containerdiv', 'DIV');
	// hmm, can't do this, because they are not siblings, they are nested...
	// calculate the desired height for our pageleafdiv,
	// and use the handy P7 equalcolumns function to animate the height.
	// (actually, to animate, set second parameter to 0.  Set to desired final height for no animation
	var theHeight = $G('container').offsetHeight;
	//alert('theHeight is ' + theHeight);
	//alert('the container overlay initially shows in IE7??!  container-overlay-left offsetHeight is ' + $G('container-overlay-left').offsetHeight);
	P7_eqA2('container-overlay-left', theHeight, theHeight);
	P7_eqA2('container-overlay-right', theHeight, theHeight);
	// better yet, just set ourselves?
	//$G('container-overlay-left').style.paddingBottom = theHeight;
	//$G('container-overlay-right').style.paddingBottom = theHeight;
};





function setActiveNav() {
	var classToApply = 'active';
	var rootElement = document.getElementById('container');
	var curPage = window.location.href;
	// apply "active" class name to the LI element containing the active link
	var links = rootElement.getElementsByTagName('A');
	var li, a;
	for (var i=0; i<links.length; i++) {
		a =  links[i].getAttribute('href');
		if (a) {
			if (a == curPage.substr(curPage.length - a.length)) {
				li = links[i].parentNode; 
				if (!li.className || li.className == '') {
					li.className = classToApply;
				}
				else {
					li.className = li.className + ' ' + classToApply;
				}
			}
		}
	}
};




