// JavaScript Document
jQuery.fn.makefaq = function(){
//NOTES:
// to load any .faq container as open, give it an additional class of 'oo' in the markup 
// example <div class="faq oo">
// to keep from showing +/x links, give container a class of 'noLinks'
// ---- SET UP FUNCTIONS ----
// base show hide function
var $showhide =  function() { 
	var theclass = $(this).attr('class');
	var upclass = $(this).parents('.faq').attr('class');
  	$(this).siblings(".aa").slideToggle(225);
	$(this).siblings("a").toggle();
	$(this).parent(".faq").toggleClass('xx').toggleClass('oo');
	if ((theclass == 'aaShow') || (theclass == 'aaHide')) {
	$(this).hide();
	}
	if (upclass.match('xx')){
	$(this).parents().siblings('a.allHide').show();
	} else {
	$(this).parents().siblings('a.allShow').show();
	};
	return false;
 } 
 // show-hide-all function
var $showhideall = function(){
	var fw = $(this).siblings('.faq');
	var shaclass = $(this).attr('class');
	if (shaclass == 'allShow'){
	$(fw).children('.aa').slideDown(225);
	$(this).siblings('.xx').children('a').toggle();
	$(fw).removeClass('xx').addClass('oo');
	} else {
	$(fw).children('.aa').slideUp(225);
	$(this).siblings('.oo').children('a').toggle();
	$(fw).removeClass('oo').addClass('xx');
	}
$(this).hide();
$(this).siblings('a').show();
return false;
}
// ---- START PROCESSING ----
// assign class of 'faqList' to our targeted container
$(this).addClass('faqList');
// assign class of xx to all faq without class oo in markup
$('.faq:not(.oo)').addClass('xx');
// close the xx content sectionswith javascript - no js, all answers load open
$('.xx > .aa').hide();
// create the show/hide links
var sh = '<a href="#" class="aaShow" title="Show">+</a><a href="#" class="aaHide" title="Hide">x</a>';
var sha = '<a class="allShow" href="#">Show All</a><a class="allHide" href="#">Hide All</a><br style="clear:both" />';
var ff = $('.faqList:not(.noLinks) .qq');
var fq = $('.faqList');
// insert links into our markup
$(sh).insertBefore(ff);
$(sha).prependTo(fq);
// show the correct buttons for each div - no js, all links/buttons hidden with css
$('.xx > .aaShow').show();
$('.oo > .aaHide').show();
$('a.allShow').show();
$('a.allHide').show();

// ------ START CLICK EVENTS -----
// aaShow shows the sibling content
$('a.aaShow').click($showhide);
// aaHide hides the sibling content
$('a.aaHide').click($showhide);
 // q is clickable, and toggles the content
$(".qq").click($showhide);
// 'show all' link shows content in all siblings('aa')
$('a.allShow').click($showhideall);
// 'hide all' link hides content in all siblings('aa')
$('a.allHide').click($showhideall);
}
