/*
#####################################################
# 
# Global Leaders Academy
# Animations
#
# Hand-crafted by Phenotype (phenotype.net)
#
#####################################################
*/

	
	/* 
	hideContent()
	
	Hides content for animation on DOM load
	-----------------------------------------------------------------------
	*/

	function hideContent() {
	
		////////////////////////////////////////////////////////////////////
		//	Dynamic CSS
		////////////////////////////////////////////////////////////////////
	
		$('#content, #content > *, #extras, #extras > *').css({
			'display' : 'none'
		});
		
	};  // End hideContent()
	
	/* 
	animateContent()
	
	Animates content on page load
	-----------------------------------------------------------------------
	*/

	function animateContent() {
	
		////////////////////////////////////////////////////////////////////
		//	Animation queuing
		////////////////////////////////////////////////////////////////////
		
		// Custom animation for Grounding
		if($('#grounding')[0]) {
			
			$('#navigation').animate({'top' : '160px'}, {duration: 800, easing: 'easeOutQuart', queue: 'contentAnimation'});
			$('#wrapper-int').css({'top' : '234px'});
			$('#content').slideDown({preDelay: 500, duration: 1000, easing: 'easeOutQuart', queue: 'contentAnimation'});
			$('#content > *').fadeIn({preDelay: 200, duration: 500, queue: 'contentAnimation', scope: 'second', complete: clearTypeFade});
			
			// Complete animation chain
			$('body').animate({'background-color' : '#ffffff'}, {duration: 100, queue: 'contentAnimation', complete: postSetup});
			
		// Default behaviour
		} else {
			
			$('#content').slideDown({duration: 1000, easing: 'easeOutQuart', queue: 'contentAnimation', scope: 'first'});
			$('#extras').slideDown({duration: 1600, easing: 'easeOutQuart', queue: 'contentAnimation', scope: 'first'});
			$('#content > *').fadeIn({preDelay: 200, duration: 500, queue: 'contentAnimation', scope: 'second', complete: clearTypeFade});
			$('#extras > *').fadeIn({preDelay: 200, duration: 500, queue: 'contentAnimation', scope: 'second', complete: clearTypeFade});
			
			// Complete animation chain
			$('body').animate({'background-color' : '#ffffff'}, {duration: 100, queue: 'contentAnimation', complete: postSetup});
			
		}	

	};  // End animateContent()
	
	/* 
	toggleWindow()

	Shows or hides content window...?!
	-----------------------------------------------------------------------
	*/
	function toggleWindow() {
	
		// If window isn't hidden, hide it
		if($('#inner-content').css('display') != 'none') {
		
			// Fade out
			$('#inner-content > *').fadeOut({preDelay: 200, duration: 500, queue: 'contentAnimation', scope: 'first', complete: clearTypeFade});
			$('#extras > *').fadeOut({preDelay: 200, duration: 500, queue: 'contentAnimation', scope: 'first', complete: clearTypeFade});
			
			// Slide
			$('#content').animate({'height' : '20px', 'padding-bottom' : '10px'}, {duration: 1200, easing: 'easeInQuart', queue: 'contentAnimation', scope: 'second'});
			$('.jScrollPaneContainer').slideUp({duration: 1200, easing: 'easeInQuart', queue: 'contentAnimation', scope: 'second'});
			$('#inner-content').slideUp({duration: 1200, easing: 'easeInQuart', queue: 'contentAnimation', scope: 'second'});
			$('#extras').slideUp({duration: 1200, easing: 'easeInQuart', queue: 'contentAnimation', scope: 'second'});
			
			// Complete animation chain
			$('#toggle-window').fadeOut({preDelay: 200, duration: 500, queue: 'contentAnimation', complete: clearTypeFade});
			$('body').animate({'background-color' : '#ffffff'}, {duration: 100, queue: 'contentAnimation', complete: function() {
					$('#toggle-window > a').html('Show window &gt;'); // Change link text
				}
			});
			$('#toggle-window').fadeIn({duration: 500, queue: 'contentAnimation', complete: clearTypeFade});
			
		
		// If window is hidden, show it
		} else {
		
			// Slide
			$('#content').animate({'height' : '300px', 'padding-bottom' : '20px'}, {duration: 1200, easing: 'easeOutQuart', queue: 'contentAnimation', scope: 'first'});
			$('.jScrollPaneContainer').slideDown({duration: 1000, easing: 'easeOutQuart', queue: 'contentAnimation', scope: 'first'});
			$('#inner-content').slideDown({duration: 1000, easing: 'easeOutQuart', queue: 'contentAnimation', scope: 'first'});
			$('#extras').slideDown({duration: 1600, easing: 'easeOutQuart', queue: 'contentAnimation', scope: 'first'});
			
			// Fade in
			$('#inner-content > *').fadeIn({preDelay: 200, duration: 500, queue: 'contentAnimation', scope: 'second', complete: clearTypeFade});
			$('#extras > *').fadeIn({preDelay: 200, duration: 500, queue: 'contentAnimation', scope: 'second', complete: clearTypeFade});
			// Complete animation chain
			$('#toggle-window').fadeOut({preDelay: 200, duration: 500, queue: 'contentAnimation', complete: clearTypeFade});
			$('body').animate({'background-color' : '#ffffff'}, {duration: 100, queue: 'contentAnimation', complete: function() {
					$('#toggle-window > a').html('&gt; Hide window'); // Change link text
				}
			});
			$('#toggle-window').fadeIn({duration: 500, queue: 'contentAnimation', complete: clearTypeFade});
		
		}
	};  // End toggleWindow()
	
	/* 
	insertFlash()
	
	Inserts animated Flash elements
	-----------------------------------------------------------------------
	*/
	
	function insertFlash() {
		
		if($('#grounding')[0]) {
			//roots
			var flashvars = {};
			var params = {};
			params.wmode = "transparent";
			params.swliveconnect = "true";
			params.allowscriptaccess = "sameDomain";
			var attributes = {};
			attributes.id = "tree-animation-replaced";
			attributes.name = "tree-animation-replaced";
			swfobject.embedSWF("/flash/swf/roots.swf", "tree-animation", "525", "470", "9.0.0", false, flashvars, params, attributes);
			
		} else if (!$('#community')[0] && !$('#news')[0]) {
			// tree
			var flashvars = {};
			var params = {};
			params.wmode = "transparent";
			params.swliveconnect = "true";
			params.allowscriptaccess = "sameDomain";
			var attributes = {};
			attributes.id = "tree-animation-replaced";
			attributes.name = "tree-animation-replaced";
			swfobject.embedSWF("/flash/swf/tree.swf", "tree-animation", "330", "300", "9.0.0", false, flashvars, params, attributes);
		
		}
		
	} // End insertFlash()
	
	