jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$(document).ready(function(){

	//preload images for accordion
	$.preloadImages("images/buttonPersonalCreditMentorOn.gif", "images/buttonCreditReportsOn.gif", "images/buttonCreditRepairOn.gif", 
	"images/buttonBillReporterOn.gif", "images/buttonDebtNegotiationOn.gif", "images/buttonCreditCardsOn.gif", "images/buttonLoansOn.gif");
	
	//initial states for accordion
	$(".accordion .tab h3").eq(0).addClass("active");	//make first h3 visible (ie. selected -- blue state)
	$(".accordion p").eq(0).show();						//make first p visible (ie. open tab so text is visible)
	$(".accordion .tab .learnMore").hide();				//hide all "Learn More" links
	$(".accordion .tab .learnMore").eq(0).show()		//show only the first .learnMore class and link

	$(".accordion .tab").click(function(){				//when a tab is clicked:
		
		if ( !($(this).children("h3").hasClass("active")) ) {
			$(this).next("p").slideToggle("slow")						//toggle the corresponding p tag (open or close it)
			.siblings("p:visible").slideUp("slow");						//close any other tabs that are open				
			$(this).children("h3").toggleClass("active");				//toggle the h3 class to the selected ("active") or not selected state
			$(this).siblings().children("h3").removeClass("active");	//toggle any other "active" h3s so they are no longer active
			$(this).children(".learnMore").toggle();
			$(this).siblings().children(".learnMore").hide();
		}
	
	});
	
});
