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();
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');
	$("#skills-show").hide().addClass('hidden');
	footerHeight();
	$("#skills").click(function(){
		if($(this).siblings("#skills-show").hasClass('hidden')) $("#skills-show").slideDown().removeClass('hidden');	
		else $("#skills-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("resume/luis-carrasco-resume.pdf");
				}
				else {window.open("resume/luis-carrasco-resume.pdf");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;
	});	
});	



$('#logotype').qtip({
	   content: 'Computer Engineering and Design',
	   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: 'dark' 
		}

	});

$('#contact').qtip({
	   content: 'Ask me for my resume, work examples, or anything else you like!',
	   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: 'dark' 
		}

	});
$('#skills').qtip({
	   content: 'Click here to view some of my skills',
	   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: 'dark' 
		}

	});
$('.skills-table thead').qtip({
	   content: 'This is my skill level. One being good, five a wizard',
	   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: 'dark' 
		}

	});
$('.sudoku').qtip({
	   content: 'Sudoku solver application for WIndows VIsta and Windows 7',
	   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: 'dark' 
		}

	});
$('.wiimote').qtip({
	   content: 'Wiimote whiteboard implementation for Windows Vista and Windows 7. Uploading Soon',
	   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: 'dark' 
		}

	});
$('.resume').qtip({
	   content: 'Click to view or download my resume',
	   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: 'dark' 
		}

	});
$('.aip1').qtip({
	   content: 'Artificial Intelligence Gesture Recognition',
	   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: 'dark' 
		}

	});
$('.aip2').qtip({
	   content: 'Artificial Intelligence Handwritting Recognition Using Matlab Neural Nets toolbox',
	   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: 'dark' 
		}

	});
$('.aip3').qtip({
	   content: 'Natural Language Processing using Hidden Markov Models',
	   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: 'dark' 
		}

	});
$('#downloads').qtip({
	   content: 'Here you can find a few examples of my work...it will hopefully keep expanding. If there is anything you want to see, and is not here, please let me know in the contact form below!',
	   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: 'dark' 
		}

	});

$('.ttt1').qtip({
	   content: 'Simple Tic Tac Toe game using windows forms',
	   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: 'dark' 
		}

	});

$('.ttt2').qtip({
	   content: 'Simple Tic Tac Toe game using Windows Presentation Foundation',
	   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: 'dark' 
		}

	});

$('.paint').qtip({
	   content: 'Simple Paint Program in C# using WIndows Forms',
	   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: 'dark' 
		}

	});
$('.encrypt').qtip({
	   content: 'File Encrypt/Decrypt program in C# using WIndows Forms',
	   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: 'dark' 
		}

	});
$('.slide').qtip({
	   content: 'Windows picture SlideSHow. Add images to drop area and press play for a full size slideshow',
	   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: 'dark' 
		}

	});

 });
