function initChallenges() {
	var list = document.getElementById("challenge_list");
	if(!list || list.blocks) return;
	
	if(isIE && parseFloat(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE") + 4)) < 7) {
		list.getElementsByTagName("table")[0].className += " notransparency";
	}

	var expandMemory = readCookie("n_challenge");
	list.blocks = list.getElementsByTagName("a");
	if(list.blocks.length == 1) {
		// if only one item, make it so it's not clickable since it will always be visible
		list.blocks[0].onclick = function() {
			return false;	
		}
		return;
	}
	list.selectedItm = (expandMemory == null) ? list.blocks[0] : list.blocks[expandMemory];
	
	var pageUrl = location.href;
	if(pageUrl.indexOf("#") >= 0) {
		var overRideTab = location.href.substring(location.href.indexOf("#")+11);
		list.selectedItm = list.blocks[overRideTab-1];
	}

	for(var i = 0; i < list.blocks.length; i++) {
		var block = list.blocks[i];
		block.details = document.getElementById("challenge_detail"+block.href.substring(block.href.lastIndexOf("_")));
		block.order = i;

		if(list.selectedItm == block) {
			block.parentNode.className += " visible";
			block.details.className += " visible";
		}
		else {
			block.parentNode.className += " hidden";
			block.details.className += " hidden";
		}

		block.onclick = function() {
			return false;
		}
		
		block.parentNode.block = block;
		block.parentNode.onclick = function() {
			var yPos = getXY(this)[1];
			if(document.documentElement.scrollTop < yPos-100) scroll(0,yPos);
			if(this.className.indexOf("visible") < 0) {
				if(list.selectedItm != null) {
					list.selectedItm.parentNode.className = list.selectedItm.parentNode.className.replace("visible","hidden");
					list.selectedItm.details.className = list.selectedItm.details.className.replace("visible","hidden");
				}
				this.className = this.className.replace("hidden","visible");
				this.block.details.className = this.block.details.className.replace("hidden","visible");
				list.selectedItm = this.block;
				createCookie("n_challenge",this.block.order,null,location.pathname);
				addChallengeBorder(this.block);
			}
			this.blur();
			return false;
		}
	}
	addChallengeBorder(list.selectedItm);
}

function addChallengeBorder(challenge) {
	var borderBtn = document.getElementById("challenge_border");
	if(!borderBtn) {
		borderBtn = document.createElement("div");
		borderBtn.id = "challenge_border";
		borderBtn.className = "themebg3";
		challenge.parentNode.parentNode.parentNode.parentNode.parentNode.appendChild(borderBtn);
	}
	with(borderBtn.style) {
		width = (challenge.parentNode.offsetWidth -3) + ((isIE) ? 4 : 0) + "px";
		left = (getXY(challenge.parentNode)[0] - getXY(challenge.parentNode.parentNode)[0]) + "px";
	}
}

var oldOnload = window.onload;
window.onload = function() {
	initChallenges();
	if(oldOnload) oldOnload();
}