/**
 * faq.js
 *
 * Copyright (c) 2010 by Benjamin Ragheb <ben@benzado.com>
 */

function hashPartOf(url) {
	return url.substring(url.indexOf('#'));
}

function questionClicked() {
	$('div.answer').hide();
	$(hashPartOf(this.href) + '_answer').show();
	return true;
}

function documentReady() {
	var questions = $('#questions');
	var allAnswers = $('div.answer');
	allAnswers.each(function(i){
		var a = document.createElement('a');
		a.innerText = $(this).children(':header').text();
		a.href = '#' + this.id;
		a.onclick = questionClicked;
		var li = document.createElement('li');
		li.appendChild(a);
		questions.append(li);
		this.id += "_answer";
	});
	allAnswers.hide();
	if (window.location.hash) {
		$(window.location.hash + '_answer').show();
	} else {
		allAnswers.eq(0).show();
	}
}

$(document).ready(documentReady);

