glow.ready(function() 
{ 
	initHelp(); 
});
	document.write('<link rel="stylesheet" href="/cbbc/help/style/help_collapse.css" type="text/css" media="screen" />');
function initHelp() {
	// get all of the A tags in the Q&A list
	var qaList = glow.dom.get("#help-box h3");
	// loop through each A and apply an onclick event
	// to open/close the answer
	for(var i = 0; i < qaList.length; i++) {
		glow.events.addListener(
		    qaList[i],
		    'click',
		    function () { 
				toggleQA(this);
				return false; 
			}
		);
	}

	if(document.location.hash) {
		toggleQA(document.location.hash);
	}
}

function toggleQA(qaItem) {
	var clickedItem = glow.dom.get(qaItem);
	if(clickedItem.parent().hasClass("faq-open")) {
		clickedItem.parent().removeClass("faq-open");
		clickedItem.parent().addClass("faq-closed");
	} else {
		closeAllQAs();
		clickedItem.parent().removeClass("faq-closed");
		clickedItem.parent().addClass("faq-open");
		replaceURL(qaItem);
	}
}

function closeAllQAs() {
	var qaList = glow.dom.get("#help-box li");
	qaList.each(function(i) {
		var qaListItem = glow.dom.get(qaList[i]);
		if (qaListItem.hasClass("faq-open")) {
			qaListItem.removeClass("faq-open");
			qaListItem.addClass("faq-closed");
		}
	});
}

function replaceURL(elementID) {
	if(typeof(elementID) == 'string') {
		document.location.replace(elementID);
	} else {
		document.location.replace("#"+elementID.id);
	}
}