// CustomerService.js
// NOTE: pages referencing this file must include jQuery

var JQ = jQuery.noConflict();

JQ(document).ready(function() {
	JQ(".scLink").live( "click", function() {
		HTB.getFadeUp($("scFDC"));
		showSizeChartContent((JQ(this).attr("id").search("dudes") > -1) ? 'dudesTopsDiv' : 'bettysTopsDiv');
	});	
	
	JQ(".toggleQuestion").live( "click", function() {
		JQ(this).siblings(".toggleAnswer").css("display","none");
		JQ(this).next(".toggleAnswer").css("display","block");
	});

	JQ(".mainCategory .categoryTitle").click( function() {
		if(JQ(this).hasClass("exposed") && !JQ(this).is("a"))
			return false;
			
		/*if(JQ(this).is("a")) {
			JQ("#helpBody").load(JQ(this).attr("href"));
			return false;
		}*/
		
		if(JQ(this).siblings(".subCategory").length == 1) {
			showBodyContent( JQ(this).siblings(".subCategory").find("h1") );
			return false;
		}
			 
		JQ(".mainCategory .subCategory").slideUp();
		JQ(".mainCategory .categoryTitle").removeClass("exposed");
		JQ(this).siblings(".subCategory").children("*:not('h1')").css("display","none");
		JQ(this).siblings(".subCategory").slideDown();
		JQ(this).addClass("exposed");
	});
	
	JQ(".subCategory h1").click( function() { showBodyContent(JQ(this)); } );
	
	JQ(".mainCategory .subCategory").hide();
	
	var subId = window.location.search.match(/subCategory=.*/);
	if(subId) {
		subId = subId.toString().substr(12).split("&",1)[0];
		JQ("#"+subId).siblings(".categoryTitle").trigger('click');
		JQ("#"+subId+" h1").trigger('click');
	}
});

function showBodyContent(el) {
	if(!JQ(el).children().is("a"))
	{
		JQ("#helpBody").html(JQ(el).parent().html());
		JQ("#helpBody").children(":not(.toggleAnswer)").css("display","block");
	/*} else { 
		JQ("#helpBody").load(JQ(this).children("a").attr("href"));*/
	}
}
	
