$(document).ready(function(){
	
	// Give our answers an id based on the question
	$(".answer").each(function(){
		var h3 = $(this).prev('h3');
		if(h3.html() != null) 
		h3.attr('id', h3.html().toLowerCase().replace(/[^a-zA-Z0-9]+/g,''));		
	});
	
	// Check if we have a hash, and if so - un hide that answer
	
	$(".toggle_container").hide();
	$("h2.trigger").toggle(function(){
		$(this).addClass("active"); 
		if($(this).next().children().eq(0).children().length == 2)
		{
			
		}
		}, function () {
		$(this).removeClass("active");
	});
	
	$("h2.trigger").click(function(){
		if($(this).next().children().eq(0).children().eq(1).css('display') != 'block')
			$(this).next().children().eq(0).children().eq(0).show();
			
		$(this).next(".toggle_container").slideToggle("slow");
	});
	
	$(".toggle_container .answer").hide();
	$(".toggle_container .answer").css('overflow','hidden');
	$(".toggle_container h3").each(function(){
		$(this).css({'cursor':'pointer'});
		$(this).click(function(){
			/*
			// Slide up any other displayed items
			if($(this).next().css('display') != 'block')
			{
				$(".toggle_container .answer").each(function(){
					if($(this).css('display') == 'block')
						$(this).slideUp();
				});
			}*/
			var elementHeight = $(this).next().height();

        	//$(this).next().css('height', elementHeight + 'px'); 
			$(this).next().slideToggle();
		});
	});
	if(location.hash != '')
	{
		var defaultQuestion = $(location.hash);
		if(typeof defaultQuestion == 'object')
		{
			defaultQuestion.parent().parent('.toggle_container').show();
			defaultQuestion.next('.answer').show();
			//$(document).scrollTop(defaultQuestion.offset().top);
		}
	}

});
