$(document).ready(function() {
	$('#faqcontent h3').each(function() {
		$(this).attr('class', '').next('div').each(function() {
			if(this.tagName == 'h3') { return false; }	
			$(this).hide();
			return true;
		}).end().mouseout(function() {
			$(this).removeClass('hover'); 
		}).mouseover(function() {
			var h = $(this);
			if (!h.is('.selected')) {
				h.addClass('hover');
			}
		}).click(function() {
			var __thisP = $(this).next('div').get(0);
			$('#faqcontent div').each(function() {
				if (this != __thisP) {
					$(this).hide().prev('h3').removeClass('selected');
				}
			});
			$(this).toggleClass('selected').next('div').toggle();
		});
	});
	
	$('#faqcontent a').each(function() {
		var baseURL = document.location.href.substring(0,document.location.href.indexOf('#'));
		var fragment = getFragmentFromURL(this.href);
		if(this.href.indexOf(baseURL) !== 0 || !fragment) {
			return;
		}
		
		$(this).click(function() {
			var fragment = getFragmentFromURL(this.href);
			$(fragment).click();
			return false;
		});
	});
});

function getFragmentFromURL(url) {
	var fragment = url.match(/(#.+)$/);
	return fragment ? fragment[1] : null;
}