$(document).ready(function(){

	speed = 250;
	
	// Hide all definitions
	$('.view-faq dd').css('display', 'none');
	
	// Display the one requested by URL
	if (document.location.hash != '') {
		$(document.location.hash).css('display', 'block');
		$('a[@href*='+document.location.hash+']').toggleClass('open');
	}
	
	// Toggle Hide and Show on clicks
	$('.view-faq dt a').click(function(){
		$(this).toggleClass('open');
		frag = $(this).attr('href');
		/* Insure we only get the info after the '#' sign (browsers handle the href attr differently) */
		frags = frag.split('#');
		frag = '#' + frags[1];
		$(frag).slideToggle(speed);
	});
	
	// Append collapse and expand links
	$('.view-faq').before('<div id="faq-tools">[<a href="javascript:void(0)">expand all</a>] | [<a href="javascript:void(0)">collapse all</a>]</div>');
	
	// Append instructions
	$('.view-faq').before('<p>Click on a question to view its answer.</p>');
	
	// Expand all function
	$('#faq-tools a:first').click(function(){
		$('.view-faq dd').each(function(){
			if($(this).css('display') == 'none'){
				$(this).slideDown(speed);
			}
		});
		$('dt a').addClass('open');
	});
	
	// Collapse all function
	$('#faq-tools a:last').click(function(){
		$('.view-faq dd').each(function(){
			if($(this).css('display') != 'none'){
				$(this).slideUp(speed);
			}
		});
		$('dt a').removeClass('open');
	});
	
});