function footerHeight(){if( $(window).height() > ( $("#wrapper").height() + $("#footer").height() ) ) $("#footer").height($(window).height()-$("#wrapper").height()-25);}

$(window).resize(function(){footerHeight();});

function sendMail(data){
$.ajax({
	url: "lib/php/process.php",	
	type: "GET",	
	data: data,		
	cache: false,
	success: function (html) {				
		if (html==1) {
			$("#name,#email,#comment").val("");
			$('#submit').val("Send Another").addClass('c-bold');
			$(".form").children().children().removeAttr('disabled').prev().show();
		} else alert('Sorry, unexpected error. Please try again later.');				
	}		
});
}


$(document).ready(function(){
footerHeight();

$(".top").click(function(){window.location.href = "http://lcarrasco.com";});

if($("#name").val())$("#name").prev().hide();
if($("#email").val())$("#email").prev().hide();
if($("#comment").val())$("#comment").prev().hide();

$("#name,#email,#comment").focus(function(){
	$(this).prev().fadeOut();
}).blur(function(){
	if(!$(this).val())
		$(this).prev().fadeIn();
});

$(".again").click(function(){
	$(this).fadeOut();
	$(".form").fadeIn().children().children().removeAttr('disabled').prev().show();
});

//////////////////////////////////
//////////     Button Hover //////////
///////////////////////////////////
$('#submit').hover(  
//Mouseover, fadeIn the hidden hover class    
function() {  
$(this).animate({ 
        opacity: 0.4,
      }, 300 );
},   
//Mouseout, fadeOut the hover class  
function() {  
$(this).animate({ 
        opacity: 1,
      }, 300 );      
});

$(document).ready(function() {
	$("#message").hide();
	$("#wrapper").show().removeClass('hide');
	$("#footer").show().removeClass('hide');
	$("#part1-show").hide().addClass('hidden');
	footerHeight();
	$("#part1").click(function(){
		if($(this).siblings("#part1-show").hasClass('hidden')) $("#part1-show").slideDown().removeClass('hidden');	
		else $("#part1-show").slideUp().addClass('hidden');
		footerHeight();
	});
	
	$("#part2-show").hide().addClass('hidden');	
	$("#part2").click(function(){
		if($(this).siblings("#part2-show").hasClass('hidden')) $("#part2-show").slideDown().removeClass('hidden');	
		else $("#part2-show").slideUp().addClass('hidden');	
		footerHeight();
	});
	
	$("#part3-show").hide().addClass('hidden');	
	$("#part3").click(function(){
		if($(this).siblings("#part3-show").hasClass('hidden')) $("#part3-show").slideDown().removeClass('hidden');	
		else $("#part3-show").slideUp().addClass('hidden');	
		footerHeight();
	});
	
	$("#downloads-show").hide().addClass('hidden');	
	$("#downloads").click(function(){
		if($(this).siblings("#downloads-show").hasClass('hidden')) $("#downloads-show").slideDown().removeClass('hidden');	
		else $("#downloads-show").slideUp().addClass('hidden');	
		footerHeight();
	});
	
	$('#submit').click(function () {		
		
		//Get the data from all the fields
		var name = $('input[name=name]');
		var email = $('input[name=email]');
		var website = $('input[name=website]');
		var comment = $('textarea[name=comment]');
		
		var count = 0;
		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
		if ($("#name").val()=="") {
			$("#name").addClass("highlight");
			$('#name').prev().qtip({
			   content: 'Please enter your name',
			   show: 'mouseover',
			   hide: 'mouseout',
			   position: {
				corner: {
					target: 'rightMiddle',
					tooltip: 'leftMiddle'
				}
			   },
			   effect: {
					type:'slide',
					length:1000
			   },
			   style: {
					border: {
						width: 5,
						radius: 10
					},
					padding: 10,
					textAlign: 'center',
					tip: true, 
					name: 'red' 
				}
		
			});
			count++;
		} else $("#name").removeClass("highlight");
		
		if ($("#email").val()=="") {
			$("#email").addClass('highlight');
			$('#email').prev().qtip({
			   content: 'Please enter your email',
			   show: 'mouseover',
			   hide: 'mouseout',
			   position: {
				corner: {
					target: 'rightMiddle',
					tooltip: 'leftMiddle'
				}
			   },
			   effect: {
					type:'slide',
					length:1000
			   },
			   style: {
					border: {
						width: 5,
						radius: 10
					},
					padding: 10,
					textAlign: 'center',
					tip: true, 
					name: 'red' 
				}
		
			});
			count++;
		} else $("#email").removeClass('highlight');
		
		emailval = $("#email").val();
			
		if((emailval.match("@")==null)||(emailval.match(".")==null)) {
			$("#email").addClass('highlight');
			$('#email').qtip({
			   content: 'Please enter a valid email',
			   show: 'mouseover',
			   hide: 'mouseout',
			   position: {
				corner: {
					target: 'rightMiddle',
					tooltip: 'leftMiddle'
				}
			   },
			   effect: {
					type:'slide',
					length:1000
			   },
			   style: {
					border: {
						width: 5,
						radius: 10
					},
					padding: 10,
					textAlign: 'center',
					tip: true, 
					name: 'red' 
				}
		
			});
			count++;
		} else $("#email").removeClass('highlight');
		
		if ($("#comment").val()=="") {
			$("#comment").addClass('highlight');
			$('#comment').prev().qtip({
			   content: 'Please enter a comment',
			   show: 'mouseover',
			   hide: 'mouseout',
			   position: {
				corner: {
					target: 'rightMiddle',
					tooltip: 'leftMiddle'
				}
			   },
			   effect: {
					type:'slide',
					length:1000
			   },
			   style: {
					border: {
						width: 5,
						radius: 10
					},
					padding: 10,
					textAlign: 'center',
					tip: true, 
					name: 'red' 
				}
		
			});
			count++;
		} else $("#comment").removeClass('highlight');
		
		if(count>0)return false;
				
		var data = 'name=' + name.val() + '&email=' + email.val() + '&website='
		+ website.val() + '&comment='  + encodeURIComponent(comment.val());
		
		str = $("#comment").val();
		
		if((str.match("resume")!=null)||(str.match("Resume")!=null)||(str.match("curriculum")!=null))
		{
			var answer = confirm("I see you might be interested in my resume, do you want to view it?");
			if (answer){
				var answer1 = confirm("Do you want to send your question/comment anyway?")
				if(answer)
				{
					data = 'name=' + name.val() + '&email=' + email.val() + '&website='
					+ "resume downloaded" + '&comment='  + encodeURIComponent(comment.val());
					window.open("http://www.lcarrasco.com/resume/resume.doc");
				}
				else {window.open("http://www.lcarrasco.com/resume/resume.doc");return false;}
				
			}
			else{
				alert("Your message was sent!");
				data = 'name=' + name.val() + '&email=' + email.val() + '&website='
				+ "resume not downloaded" + '&comment='  + encodeURIComponent(comment.val());
			}

			
		}
		
		$('.text').attr('disabled','true');

		$('.loading').show();

		sendMail(data);
		
		return false;
	});	
});	

 });
