$(document).ready(function(){
	var headings = 'h1, h2, h3, h4, h5, h6';

	$(headings).click(function() {
		if ($(this).hasClass('selected')) {
			// remove class selected to clicked header
			$(this).removeClass('selected');
			// hide answer for clicked question
			$(this).parent().next().slideUp();
		} else {
			// add class selected to clicked header
			$(this).addClass('selected');
			// remove class selected from all headers
			$(this).parent().siblings().children(headings).removeClass('selected');

			// show answer for clicked question
			$(this).parent().next().slideDown();
			// hide all open answers
			$(this).parent().nextAll('div.expand').slice(1).slideUp();
			$(this).parent().prevAll('div.expand').slideUp();
		}
		return false;
	});
});