
//window.onload = function() {
//	initAnswers();
//}

document.observe('dom:loaded', function() {
	initAnswers();
});

function initAnswers() {
	if (document.getElementById('faqs')) {
		faqsList = $('faqs');
		list_items = $$('li');
		
		for (var i=0; i<list_items.length; i++) {
			if (list_items[i].descendantOf(faqsList)) {
				list_items[i].childElements()[1].toggle(); // toggle the answer paragraph
				list_items[i].childElements()[0].childElements()[0].onclick = function() { // add onclick function to anchor tag
					sibling = this.ancestors()[1].childElements()[1]; // get the answer paragraph
					this.ancestors()[1].className = (sibling.visible()) ? "" : "active"; // toggle classname of list item
					sibling.toggle(); // toggle the paragraph
					return false; // stop the hyperlink click event firing
				};
			}
		}
	}
}
