$(function() {
	if(returnDocument() == 'faq.php' || returnDocument() == 'faq.php#') {
		//alert("hello");
		$('#content span.titleL').siblings('span.topSpan').after('<br><br><a href="javascript:;" id="showHide" class="link showAll">Show All FAQs</a><br><ol class="copy faqs"></ol>');
	}
		
	$('.question').each(function(i) {
		var question = $(this).html();
		//alert(question);
		$(this).remove();
		$('<li></li>')
			.appendTo('ol.faqs')
			.html('<a href="javascript:;" id="question' + (i + 1) + '" class="link question">' + question + '</a>');
	});
	
	$('.answer').each(function(i) {
		var answer = $(this).html();
		$(this).remove();
		$('#question' + (i + 1)).parents('li').after('<div id="answer' + (i + 1) + '" class="answer"></div>');
		
		$('#answer' + (i + 1))
			.addClass('copy')
			.hide()
			.html('<hr class="hr100"><strong>' + answer + '</strong><br><br><a href="javascript:;" class="link hideAnswer">Click to Hide</a> | <a href="#" class="link">Top</a><br><hr class="hr100">');
	});
	
	$('li').children('a').click(function() {
		var id = $(this).attr('id');
		if (!id) {
			var classes = $(this).attr('class');

			var num = classes.split(' ').slice(2,3);
			$('.answer' + '.' + num).stop().toggle('slow', function() {
				resize();
			});
		} else {
			var answer = 'answer' + id.slice(8);
			$('#' + answer).stop().toggle('slow', function() {
				resize();
			});
		}
	});
	
	$('.hideAnswer').click(function() {
		var id = $(this).parents('div').attr('id');
		if (!id) {
			var classes = $(this).parents('div').attr('class');
			/*var group = classes.split(' ').slice(2,3);*/
			var num = classes.split(' ').slice(1,2);

			$('.answer' + '.' + num).stop().toggle('slow', function() {
				resize();
			});
		} else {
			$('#' + id).stop().toggle('slow', function() {
				resize();
			});
		}
	});
	
	$('#showHide').click(function() {
		if($(this).hasClass('showAll')) {
			$(this)
				.addClass('hideAll')
				.removeClass('showAll')
				.empty()
				.text('Hide All FAQs');
			$('.answer').each(function() {
				if(!($(this).is(':visible'))) {
					$(this).stop().show('slow', function() {
						resize();
					});
				}
			});
		} else if($(this).hasClass('hideAll')) {
			$(this)
				.addClass('showAll')
				.removeClass('hideAll')
				.empty()
				.text('Show All FAQs');
			$('.answer').each(function() {
				if($(this).is(':visible')) {
					$(this).stop().hide('slow', function() {
						resize();
					});
				}
			});
		}
		
	});
});