$(document).ready(function() {
	
	// Activate Home Page Slideshow
	if (document.getElementById('slideshow')) {
		$('#slideshow').slideshow({
			timeout: 6000,
			fadetime: 2000,
			type: 'sequence'
		});
	}
	
	// Animate About Submenu
	if (document.getElementById('about-menu')) {
		$('#about-menu li').append('<span class="hover"></span>').each(function () {
			var $span = $('> span.hover', this).css('opacity', 0);
			$(this).hover(function () {
				$span.stop().fadeTo(100, 1);
			}, function () {
				$span.stop().fadeTo(300, 0);
			});
		});
		
		$('.information div').css({'display': 'none', 'opacity': '0', 'position': 'absolute'});
		$('#about').css('overflow-y', 'hidden');
		$('#who-we-are').css('display', 'block').fadeTo(300,1).css('z-index', '1');
		
		
		$('#who').hover(function () {
			$('#who-we-are').css('display', 'block').fadeTo(300,1);
			$('#our-mission').fadeTo(300,0).css('display', 'none');
			$('#what-we-do').fadeTo(300,0).css('display', 'none');
		});
		
		$('#mission').hover(function () {
			$('#our-mission').css('display', 'block').fadeTo(300,1);
			$('#who-we-are').fadeTo(300,0).css('display', 'none');
			$('#what-we-do').fadeTo(300,0).css('display', 'none');
		});
		
		$('#what').hover(function () {
			$('#what-we-do').css('display', 'block').fadeTo(300,1);
			$('#who-we-are').fadeTo(300,0).css('display', 'none');
			$('#our-mission').fadeTo(300,0).css('display', 'none');
		});
	}
		
	// Validate contact form
	if (document.getElementById('contact-form')) {
		$("#contact-form").validationEngine({
			success :  false,
			failure : function() {}
		});
	}
	
	// Capabilities Page Logic
	if (document.getElementById('capabilities')) {
		$('.view .enter').css('top', '5px');
		$('.view .return').css({'opacity': '0', 'filter': 'alpha(opacity=0)'});
		$('.capability').hover(function () {
			$('.view .enter', this).animate({top: '0'}, 100);
		}, function () {
			$('.view .enter', this).animate({top: '5px'}, 100);
		});
		$('.capability').click(function () {
			// Make clicked section active
			$(this).addClass('active');
			
			// Fade out "View" button and fade in "Return" button
			$('.view .enter', this).fadeTo(600,0).css('display', 'none');
			$('.view .return', this).fadeTo(1000,0).fadeTo(300,1);
			
			// Fade out inactive sections
			$(".capability:not(.active) img").css('display', 'none');
			if (jQuery.browser.msie) {
				$(".capability:not(.active)").fadeTo(300,0).css({'width': '0', 'margin': '0', 'padding': '0', 'display': 'none'});
			} else {
				$(".capability:not(.active)").fadeTo(600,0).animate({'width': '0', 'margin': '0', 'padding': '0'}, 600);
			}
			
			// Fade in active section's description
			$('.description', this).css({'display': 'block', 'opacity': '0', 'cursor': 'auto'}).fadeTo(1000,0).fadeTo(600,1);
			$("#capability-description").css({'display': 'block', 'opacity': '0'}).fadeTo(800,0).fadeTo(1000,1);
			$(this).unbind();
		});
		
	}

});
