$(document).ready(function(){
	$('#homepage_header_pictures').cycle({fx: 'scrollDown', speed: 300, timeout: 3500});
	$(window).resize(function(){
		$('.section').css("paddingLeft", ((returnWidth() - 900) / 2) + "px");
		$('.section').css("paddingRight", ((returnWidth() - 900) / 2) + "px");
		location.reload();
	});
	$('.section').css("paddingLeft", ((returnWidth() - 900) / 2) + "px");
	$('.section').css("paddingRight", ((returnWidth() - 900) / 2) + "px");	
	$.localScroll.defaults.axis = 'x';
	$("#content_container").localScroll({
		target: "#content"
	});
	$("#header_menu").localScroll({
		target: "#content"
	});
	$('#btnMail').click(function(){
		$('#txtEmail').css("background-color", "#fff");
		$('#txtName').css("background-color", "#fff");								 
		var int = 0;
		if($('#txtName').val() == ""){
			$('#txtName').css("background-color", "#ffb1b1");
			int++;
		}
		if($('#txtEmail').val() == ""){
			$('#txtEmail').css("background-color", "#ffb1b1");
			int++;
		}
		if(!isValidEmailAddress($('#txtEmail').val())){
			$('#txtEmail').css("background-color", "#ffb1b1");
			int++;									   
		}
		
		if(int > 0){
			alert("Het formulier is niet correct ingevuld!");
		}
		else{
			$.ajax({type: "POST", url: "mail.php", data: "txtName=" + $('#txtName').val() + "&txtEmail=" + $('#txtEmail').val() + "&txtCity" + $('#txtCity').val() + "&txtType=" + $('#lstType').val() + "&txtQuestion=" + $('#txtQuestion').val(), success:
				function(msg){
					alert(msg);
					$('#txtEmail').css("background-color", "#fff");
					$('#txtName').css("background-color", "#fff");							
					$('#txtName').val('');
					$('#txtEmail').val('');
					$('#txtCity').val('');
					$('#txtQuestion').val('');				
				}
			});			
		}
	});	
});

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}
function returnWidth() {
	var myWidth = 0
	if(typeof( window.innerWidth ) == 'number'){
		//Non-IE
		myWidth = window.innerWidth;
	}else if(document.documentElement && (document.documentElement.clientWidth)){
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	}
	return myWidth;
}
