var openHeader = null;
var subSectionCurrentHeight = 0;
	    
function openHeaderSection(selector) { 
	if( $(selector).css('display') == "none" ) {
		
		var bgHeight = $(selector).height();
		
		$('.sectionHeader').stop();
		$('.sectionHeader').hide();
		$('.sectionHeader .content .inner').hide();
		$('ul.nav li a').removeClass('active');
		
		if(openHeader == null)
			$(selector).slideDown(800,'easeOutExpo')
		else
			$(selector).fadeIn(500);
		
		$('.header .bg').show();
		$('.header .bg').animate({height:bgHeight},800,'easeOutExpo');
		
		$('ul.nav li'+selector+' a').addClass('active');
		
		openHeader = selector;
		subSectionCurrentHeight = 0;
	}
	
}

function openSubSection(selector,textHeight) {
	
	var regularHeight = 560; 
	var columnWrapHeight = (typeof textHeight == "undefined") ? 450 : textHeight;
	if( $(selector).css('display') == "none" ) {
	
		$('.sectionHeader .content .inner').hide();
		
			
		if ( $(selector).height() != subSectionCurrentHeight ) {
			
			var targetHeight = $(selector).height();
			$(selector).height(subSectionCurrentHeight);
			
			$(selector).fadeIn(500);
			$(selector).animate({height:targetHeight},{duration:800,easing:'easeOutExpo',queue:false});
			
			subSectionCurrentHeight = targetHeight;
			
		} else {  
		
			$(selector).fadeIn(500);
			subSectionCurrentHeight = $(selector).height();
		}
		
		
		if( $('.textContent .column',selector).length == 0 ) {
			$('.textContent',selector).columnize({
				width:362,
				height: columnWrapHeight,
				buildOnce: true,
				doneFunc: function(){
						$('.textColumns',selector).ptColScroll();
					}
			});
		}

	}
}

function closeHeaderSection() {

	$('.sectionHeader .content .inner').hide();
	$('.sectionHeader').slideUp('fast');
	$('.header .bg').animate({height:0},800,'easeOutExpo');
	$('ul.nav li a').removeClass('active');
	
	openHeader = null;

}

function closeSubSection() {

	$('.sectionHeader .content .inner').slideUp('fast');
	subSectionCurrentHeight = 0;
}

function toggleMoreText() {
	$('.mainCol .hidden').slideToggle(800,"easeOutExpo");
	
	if( $('#moreInfo').html() == "View More" )
		$('#moreInfo').html("Close");
	else
		$('#moreInfo').html("View More");
}

function fadeOutIntro() {
	var duration = 1000;
	
	$('.intro').fadeOut(duration);
	$('ul.nav,.home .header .logo,.imageCaptionHome').fadeIn(duration);
	
}

$(document).ready(function() {
	
		
	$('.header .subnav .closeButton').click( function(){ closeHeaderSection(); } );
	$('.header .content .closeButton').click( function(){ closeSubSection(); } );

});





