$(document).ready(function(){
	$('.pngfix').pngFix();
	$('#discipline-subbrand-header').pngFix();
		
	/* Set random image for Homepage */
	var banners_arr = "bradley-stoke bristol-1 bristol-2 clevedon-1 clevedon-2 nailsea-1 nailsea-2 portishead-1 portishead-2 staple-hill weston-super-mare-1 weston-super-mare-2 worle yate".split(" ");
	var random_image = banners_arr[Math.floor(Math.random()*banners_arr.length)] +'.jpg';
	$("#home-section #primary #content #body #office-image").css({	'background-image':	'url(/_assets/images/home/'+random_image+')'	});
	var random_quote = 'quote' + Math.floor(Math.random()*8 + 1);
	$("#home-section #primary #content #body #home-quote").css({'background-image': 'url(/_assets/images/home/' + random_quote + '.gif)' });
	$("LI.biog").each(function (i) {
		if (!((i+1) % 3))	{
			$(this).css({ 'margin-right':'0px' });
		} else {
		}
	});


	$("#select-a-team-select").keyup(function () {
		var str = "";
		$("select option:selected").each(function () {
			str += $(this).text() + " " + $(this).attr('value');
		});
	}).change();

	$('.tactical').click(function()	{
		window.location = $(this).find("A").eq(0).attr('href');
	});


	anc = jQuery.url.attr("anchor");
	if (anc)	{
		$("#select-a-team-select").css('background-color','blue');
		$("SELECT OPTION").each(function () {
			if (anc == $(this).attr('value') ) $(this).attr('SELECTED','SELECTED');
		});
		$(".discipline-team-list").hide();
		$('UL.discipline > LI').find("UL#" + anc).show();
	}


/*	Discipline FAQ UI	*/
	$disc = $("#discipline-buttons");
	$jump = $("UL.jump");
	$jump.after($disc);
	$('.answer').hide();
	$('.answer').eq(0).show();
	$('UL.jump > LI > A').eq(0).toggleClass('active');
//	$('UL.jump').after('<div id="jump-controls"><a id="expand-collapse" href="#all">Expand/Collapse All</a></div>');

	initialContainerHeight = $('#for-you #content, #for-your-business #content').height() + $('#jump-controls').height();
	answerMaxHeight = 0;
	totalHeight = 0;

	collapseContainer();
	initialTotalHeight = totalHeight;

	$('A#expand-collapse').click(function()	{
		if ($('.answer').is(':hidden'))	{
			$('.answer').fadeIn("def");
			$('#for-you #content, #for-your-business #content').height(initialContainerHeight + initialTotalHeight);
		}	else {
			$('.answer').hide();
			collapseContainer();
		}
		return false;
	});

	$('UL.jump > LI > A').click(function()	{
		if ( $(this).attr("class") == 'directlink' )	{
			location.href = $(this).attr("href");
			return false;
		}
		$('.answer').hide();
		collapseContainer();
		answerLayer = $(this).attr("href");
		$('UL.jump > LI > A').removeClass('active');
		$(this).toggleClass('active');
		$(answerLayer).fadeIn("def");
		return false;
	});

	function collapseContainer()	{
		$('.answer').each(function(i){
			totalHeight += currentHeight = $(this).height() + 2;
			answerMaxHeight = (currentHeight > answerMaxHeight)	? currentHeight : answerMaxHeight;
		});
		containerHeight = (totalHeight - $('.answer').eq(0).height()) - initialContainerHeight;
		$('#for-you #content, #for-your-business #content').height(initialContainerHeight + answerMaxHeight);

// PA: Plan B, fix the FAQ container height the overall LHS bar height
		$('#for-you-section #content, #for-your-business-section #content, #about-section #content').height( $('#lhs-bar').height()-15-15-2 );

	}

/* Meet The Team: Team Member	*/
//		$('#biography-panel').hide();
		$('#career-history-panel').hide();

// PA: Rememeber the original height...
		$meet_the_team_height = $('#meet-the-team-section #content').height();
		$('#meet-the-team-section #content').height( $('#lhs-bar').height()-15-15-2 );

// PA: ... because here's the reasaon why.
		$('#meet-the-team-section .meet-the-team #content').height( $meet_the_team_height );

		$('A#biog-career-history').click(function()	{
			$('#career-history-panel').fadeIn("fast");
//			$('#biography-panel').fadeOut("fast");
			$('#biography-panel').hide();
			$('A#biog-career-history').addClass('active');
			$('A#biog-biography').removeClass('active');
			return false;
		});
		$('A#biog-biography').click(function()	{
//			$('#career-history-panel').fadeOut("fast");
			$('#career-history-panel').hide();
			$('#biography-panel').fadeIn("fast");
			$('A#biog-career-history').removeClass('active');
			$('A#biog-biography').addClass('active');
			return false;
		});

});
