// Hidding the Contact Form by default
function defaultHideForm(){			
	$('#contact').hide(); 
	$('#siteFooter, .push').css('height','6em');
	$('#wrap').css('margin-bottom','-6em');			
}
	
// Show Contact Form
function showForm(){				
	$('.contactButton').css('border-bottom','none');					 
	$('.contactButton').next('#contact').fadeIn(1000);		
	$('#siteFooter').animate({height:'20em'}, 500);

	/* scroll to form */
		$('#contact').show().addClass('shown');
		$('html,body').animate({scrollTop: $('#contact').offset().top}, 500);
		$('#contact input#name').focus();
}
	
// Hidding the Contact Form after beeing pressed
function hideForm(){			
	/* scroll to form */
	$('#contact').removeClass('shown').fadeOut(500);
	
	$('#siteFooter').animate({height:'6em'}, 1500);
	$('html,body').animate({scrollTop: $('section').offset().top}, 1500);
	
	$('#siteFooter, .push').css('height','6em');
	$('#wrap').css('margin-bottom','-6em');			
}

// Hides the success message after sending a contact email
function hideMessage(){
	$('#formItMessage').fadeOut(500);
}

// Takes to homeContent
function scrollToHomeContent(){
	event.preventDefault();
	$('html,body').animate({scrollTop: $('#homeContent').offset().top}, 1500);
}


// Setting all to run when doc is ready
$(document).ready(function() {
	
			
	/* Shows muy pronto when hover español */
	$("li.languageOption span").addClass("hidden");
	$("#es").hover(
		function(){$("li.languageOption span").fadeIn(2500).removeClass("hidden").addClass("shown");}
		,
		function(){$("li.languageOption span").fadeOut(2500).addClass("hidden").removeClass("shown").stop();}
		);				
		 
	/* 
	Contact form: 
	*/
	// Set default to hide contact form
	defaultHideForm();	
	// Scroll to footer when contact button on navbar is clicked
	$("#menuContactButton").click(function(event) {
		event.preventDefault();
		showForm();
	});	
	// Show & hide contact form on click
	$(".contactButton").click(function(event) {
		event.preventDefault();
		if($('#contact').hasClass('shown'))
			/* then */{
				hideForm();	
			}
			else{					
				showForm();									
			}
	});
	// Hide success message
	$(".closeMessage").click(function(event){
		event.preventDefault();
		hideMessage();
	});
	
	/* Clears focus fileds by class */
	$("#search, input[type='text']").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
		})
		.blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
	
	/* Takes you to workDone when clicking #toWork*/
	$("#toWork").click(function(event){
			scrollToHomeContent();		
		});
	
});

