// javascript for pages in '/help/' directory

// register the flash player with the SWFObject library for flash version detection
if ($("#help_help-success").length!=0) {
	swfobject.registerObject('how-it-works-vid','9.0.0','/expressInstall.swf');
}

// ### AMEND LAYOUT OF HELP PAGE; ENABLE TOGGLING OF SECTION CONTENT ###
$(function () {
	var content = $(".content:first");					
	// if #top-questions exists in page (i.e. we're at help home),
	if ($("#top-questions").length!=0) {
		// shift #top-questions up a level and float it right, beside .content
		$("#main").prepend($("#top-questions").addClass("fr js shifted"));
		// then add class to .content to reduce its width
		content.addClass("home");
	}
	// but if we're at any other help section except 'contact',
	else if ($("#help_email").length==0) { // content.find("h2:contains('Contact Us')").length==0
		// wrap inner html of .content to create wide grey border
		content.wrapInner("<div class=\"js wrap c4 b50\" />");
		// attach function to each h2 to toggle class 'down' on parent and 'h' on siblings, on click ,
		// also - initially hide all siblings of an h2 (by adding class 'h')
		content.find("h2").click(function() {$(this).parent().toggleClass("down").children().not("h2").toggleClass("h")}).siblings().addClass("h");
		// open a section if it appears as named anchor in URL, mark it as 'down', and scroll to top of page
		if (location.href.indexOf("#help-")!=-1) {
			var num = location.href.split("#help-")[1];
			var curr = $("#help-" + num);
			curr.find(".h").removeClass("h");
			curr.addClass("down");
			$(window).scrollTop(0);
		}
	}
	// add class 'down' to .nav li the text of which matches the page's h1
	var hText = content.find("h1:first").text();
	$(".aside .nav li a:contains(" + hText + ")").parent().addClass("down");	
});