

$(document).ready(function() {
	
	$('.nav_getinvolved').click(function(){
		$('#overlay').show();
		$('#popup_get_involved').show();
	});
	
	$('.signup_click').click(function(){
		var bodyheight = $('body').height();
		var highlight_height = bodyheight - 480;
		$('.signup_highlight_bottom').height(highlight_height);
		
        $('html, body').animate({scrollTop:0}, 'slow');
		$('.signup_highlight').fadeIn();
		
		setTimeout(function(){
			$('.signup_highlight').fadeOut();
		}, 3500);
		
        return false;
    });
	
	$('#signupInp').focus(function(){
		clearInput(this);
	});
	$('#signupInp').blur(function(){
		resetInput(this);
	});
	
	$('#signupInp').keyup(function(e) { 
		if (e.which == 13) {
			submitEmail();
		}
	});
	$('.btn_signup').click(function(){
		submitEmail();
	});
	
	$('#btn_send_form').click(function(){
		submitForm();
	});
	
	$('.btn_video').click(function(){
		$('#overlay').show();
		$('#popup_video').show();
	});
	
	
	$('.popup_close').click(function(){
		closeOverlays();
	});
	$('#overlay').click(function(){
		closeOverlays();
	});
	$(document).keyup(function(e) { 
		if (e.which == 27) {
			closeOverlays();
		}
	});
	
	
	function submitForm(){
		$('#popup_gi_form').fadeOut(function(){
			$('#popup_gi_wait').fadeIn(function(){
				
				var name = $('#name').val();
				var school = $('#school').val();
				var tel = $('#tel').val();
				var email = $('#email').val();
				var comments = $('#comments').val();
				
				$.ajax({ 
					type: "POST", 
					url: "ajax/contact.php", 
					data: 	"name=" + name +
							"&school=" + school +
							"&tel=" + tel +
							"&email=" + email +
							"&comments=" + comments,
					timeout: (15 * 1000),
					success: function(result, status) {
						setTimeout( function() {
							$('#popup_gi_wait').fadeOut(function(){
								$('#popup_gi_success').fadeIn(function(){
									setTimeout( function() {
										$('#name').val('');
										$('#school').val('');
										$('#tel').val('');
										$('#email').val('');
										$('#comments').val('');
										$('#popup_gi_success').fadeOut(function(){
											$('#popup_gi_form').fadeIn();
										});
									}, 4000);
								});
							});
						}, 500);
					},
					error: function(request,error) {
						setTimeout( function() {
							$('#popup_gi_wait').fadeOut(function(){
								$('#popup_gi_form').fadeIn();
							});
						}, 500);
					}
				});
			});
		});
	}
	
	
	function submitEmail(){
		$('#signup_form').fadeOut(function(){
			$('#signup_wait').fadeIn(function(){
				
				var signupinput = $('#signupInp').val();
				
				$.ajax({ 
					type: "POST", 
					url: "ajax/signup.php", 
					data: 	"email=" + signupinput,
					timeout: (15 * 1000),
					success: function(result, status) {
						setTimeout( function() {
							$('#signup_wait').fadeOut(function(){
								$('#signup_thanks').fadeIn(function(){
									setTimeout( function() {
										$('#signupInp').val('Enter your email for updates');
										$('#signup_thanks').fadeOut(function(){
											$('#signup_form').fadeIn();
										});
									}, 4000);
								});
							});
						}, 500);
					},
					error: function(request,error) {
						
					}
				});
			});
		});
	}
	

	function closeOverlays(){
		$('#overlay').hide();
		$('#popup_get_involved').hide();
		$('#popup_video').hide();
	}

});


