var pages = new Array(5);

pages[0] = "home";
pages[1] = "about";
pages[2] = "projects";
pages[3] = "contact";
pages[4] = "blog";

function display_clear() 
{	
	for(var i=0; i < pages.length; i++) 
	{
		document.getElementById(pages[i]).className = 'content_off';
	}
}
function is_page(page) {	

	for(var i=0; i < pages.length; i++)
	{
		if (pages[i] == page) {		
			return true;		
		}		
	}	
	return false;
}
function display(a) {
			
	display_clear();
	
	if (a == 0) {
		var a = pages[0];	
	}
	
	document.getElementById(a).className = 'content_on';
	
	resize_content(a);
	
}
function display_get() {
	var page = location.hash.split("#")[1];

	if (is_page(page)) {
		display(page);
	} else if (typeof page != 'string') {
		display(0);	
	}
}

function resize_content(a) {
	
	// 100x100 viewpoint
	
	var height = $("html").height();
	//var width = $("html").width();
	
	var name = "#"+a+"_wrap";
	
	var content = $(name).height();
	var size = content+180;
	
	// If the size of the wrapper is greater than that of
	// the window, set it to the height else set the min-height for IE7
	if (size > height) {
		$("* body #wrapper").css("height",size);		
	} else {
		$("#wrapper").css("min-height",size);		
	}
	
	// diag.
	//alert("size: " + size + " height: " +  height + " name: " + name);

}

$(document).ready(function(){					   

	$('.site_about').click(function (e) {
		e.preventDefault();
		$('#basicModalContent').modal();
	});
	
	$("#submit").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var email = $("#email").val();
		if(email == '') {
			$("#l_email").after('<span class="error">You forgot to enter the email address.</span>');
			hasError = true;
		} else if(!emailReg.test(email)) {	
			$("#l_email").after('<span class="error">Enter a valid email address.</span>');
			hasError = true;
		}
		
		var name = $("#name").val();
		if(name == '') {
			$("#l_name").after('<span class="error">You forgot to enter your name.</span>');
			hasError = true;
		}
		
		var message = $("#message").val();
		if(message == '') {
			$("#l_message").after('<span class="error">You forgot to enter the message.</span>');
			hasError = true;
		}
		
		
		if(hasError == false) {
			$(this).hide();
			$("#form_contact div.buttons").append('<img src="images/loading.gif" alt="Loading" id="loading" />');
			
			$.post("sendemail.php",
   				{ email: email, name: name, message: message },
   					function(data){
						$("#form_contact").slideUp("normal", function() {				   
							
							$("#form_contact").before('<h1>Success</h1><p>I will be in contact with you shortly. Until then, feel free to browse the rest of the site.</p>');											
						});
   					}
				 );
		}
		
		return false;
	});						   
});