$(document).ready(function(){
	
// declare all variables;
var wheight, wwidth, navHeight, directiveHeight, directivePadTop, workHeight, workPadTop, workHeight, workPadTop, teamHeight, teamPadTop, contactHeight, contactPadTop, logoheight, taglineheight, tagline2height, headerheight, logotopmargin;	
	// declare variables for window height and width
	wheight = $(window).height();
	wwidth = $(window).width();
	
	// set height of header to height of viewport on page load	
	function setHeight () {
		$(".window-height").height(wheight);
	}	
	
	setHeight();
	
	// reset height of header on viewport resize
	$(window).resize(function() {
		setHeight();
	});
	
	// Set top margin of logo based on height of window and height of header elements
	
	logoheight = $("#logo").height();
	taglineheight = $("#tagline").height();
	tagline2height = $("#tagline-2").height();
	headerheight = logoheight + taglineheight + tagline2height
	logotopmargin = (wheight - headerheight) * 0.5 - 100
	
	$("#logo").css('margin-top', logotopmargin);
			
	// delay load of nav buttons in header for 3 seconds, nav buttons for 4.5 seconds, content for 5 seconds
	
	$("div#find-out-more").delay(3500).animate({
		'opacity' : '1.0'
	}, 750);
	
	// scroll to content sections
	
	$(".scrollhandle").click(function(e){
	    e.preventDefault();
	    var key = $(this).data("scrolltarget");
	    $.scrollTo("#" + key, 1500)
	});
	
	// fade nav links to white on hover, and back to initial on hoverout
	var navLinkColor = $("a.nav-link").css('color');
	$("a.nav-link").hover(
		function(){
			$(this).animate({
				'color' : '#FFF'
			}, 150);
		},
		function(){
			$(this).animate({
				'color' : navLinkColor
			}, 150);
		});
	
	// show nav when page is scroll past "home" area
	var HomeBottom = $('#directive').offset().top
	$(window).scroll(function(){
		scrollTop = $(window).scrollTop();
		if (scrollTop > HomeBottom - 50){
		    $('#nav-wrap').fadeIn();
		} else {
		    $('#nav-wrap').fadeOut();
		};
	});
	
	// Script to determine if About Our Process is showing in the window and highlight the appropriate menu item

	var DirectiveTop = $("#directive").offset().top - 20
	var DirectiveBottom = $("#directive").offset().top + $("#directive").height();

		 $(window).scroll(function(){
		  if (scrollTop > DirectiveTop && DirectiveBottom > scrollTop){
		      $(".directive-active .page").css("border-color" , "#444").stop().animate({'color' : '#FFF'}, 200);
		  } else {
		      $(".directive-active .page").css("border-color" , "#121212").stop().animate({'color' : '#AAA'}, 200);
		  }
		 });
	
	var WorkTop = $("#work").offset().top - 20;
	var WorkBottom = $("#work").offset().top + $("#work").height();

	    $(window).scroll(function(){
		  if (scrollTop > WorkTop && WorkBottom > scrollTop){
		      $(".work-active .page").css("border-color" , "#444").stop().animate({'color' : '#FFF'}, 200);
		  } else {
		      $(".work-active .page").css("border-color" , "#121212").stop().animate({'color' : '#AAA'}, 200);
		  };
		 });
	
	var TeamTop = $("#team").offset().top - 20
	var TeamBottom = $("#team").offset().top + $("#directive").height();

		 $(window).scroll(function(){
		  if (scrollTop > TeamTop && TeamBottom > scrollTop){
		      $(".team-active .page").css("border-color" , "#444").stop().animate({'color' : '#FFF'}, 200);
		  } else {
		      $(".team-active .page").css("border-color" , "#121212").stop().animate({'color' : '#AAA'}, 200);
		  };
		 });
		
		
	// portfolio scripts
	
	$("div.portfolio-item").hover(
        function(){
    	    $(this).find(".portfolio-meta").stop().animate({
    		    "margin-top": "0px" 
    	        }, 250)
            }, function(){
    	        $(this).find(".portfolio-meta").stop().animate({
    	        "margin-top": "150px" 
            }, 250);
    	});

	// validate the contact form
    // $("#contact-form").validate();
    
    
	// team
	$("#bio-inside>div").not(".current").hide();
	
	var dim;
	$(".team").hover(function(){
	    $(this).addClass("hover");
	    // team-name
	    var name = $(this).attr("id").split("-")[1];
	    var bioID = "bio-" + name;
	    $("#bio-inside div.current").removeClass("current");
	    $("#" + bioID).show().addClass("current");
	    $("#bio-inside>div").not(".current").hide();
	    
	    dim = false;
	    dimify();
	    
	}, function(){
	    $(this).removeClass("hover");
	    $("#bio-inside div.current").removeClass("current");
	    $("#bio-inside div").eq(0).addClass("current").show();
	    $("#bio-inside>div").not(".current").hide();
	    dim = true;
		dimify();
	});

	function dimify(){
	    if(dim){
	        var opacity = 1;
	    }else{
	        var opacity = 0.3;
	    }
	    $(".team").each(function(i,el){
	        if (!$(this).hasClass("hover") && !$(this).hasClass("scrollhandle")){
	            $(this).stop().animate({"opacity": opacity}, 200);
	        }
	    })
	}
	
	
	// to send email using ajax
	// Contact form script

				$('#contact-form').ajaxForm(function() { 
	                alert("SUCCESS!")
	            });			
	
});
