
function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
        $('<img/>')[0].src = this;
        // Alternatively you could use:
        // (new Image()).src = this;
    });
}

// Usage:

preload([
    '/resources/images/layout/bkg-top.jpg'
]);

$(document).ready(function(){
	$(window).bind("resize load", function(){
		var img_height = $("#bkg-top").height();
		//alert(img_height);
		
		//if(img_height < 910){
			var img_gap = (img_height - 910);
			var resize = 600+img_gap;
			$("#pandavibox").css("margin-top",resize);
		//}
	});
	
	$("#navigation a").bind("click",function(){
		var anchorlink = $(this).attr("href");
		$('html, body').animate({
			scrollTop: $(anchorlink).offset().top
			}, 500);
		return false;
	});
	
	$('#name').focus(function() {
        if (this.value == 'Frank Ricard'){
        	this.value = '';
    	}
    });
    $('#name').blur(function() {
        if (this.value == ''){
        	this.value = "Frank Ricard";
    	}
    });
	$('#email').focus(function() {
        if (this.value == 'frankthetank@lambdaepsilonomega.org'){
        	this.value = '';
    	}
    });
    $('#email').blur(function() {
        if (this.value == ''){
        	this.value = "frankthetank@lambdaepsilonomega.org";
    	}
    });
	$('#message').focus(function() {
        if (this.value == "I'm not a talker, I'm not a talker"){
        	this.value = '';
    	}
    });
    $('#message').blur(function() {
        if (this.value == ''){
        	this.value = "I'm not a talker, I'm not a talker";
    	}
    });
	$("#submit").click(function(){
		//alert("I clicked submit!");
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

		var nameVal = $("#name").val();
		if(nameVal == '') {
			$("#name").after('<br /><span class="error">You forgot to enter the subject.</span>');
			hasError = true;
		}
		
		var emailFromVal = $("#email").val();
		if(emailFromVal == '') {
			$("#email").after('<br /><span class="error">Enter a valid email address.</span>');
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {
			$("#email").after('<br /><span class="error">Enter a valid email address.</span>');
			hasError = true;
		}

		var messageVal = $("#message").val();
		if(messageVal == '') {
			$("#message").after('<br /><span class="error">You forgot to enter the message.</span>');
			hasError = true;
		}
		
		var subject = $("#subject").val();
		
		if(hasError == false) {
			$(this).hide().before('<div id="status"><p>Sending...</p></div>');
			$("#loading").show();
			$.post("/resources/includes/email.php",
				{ email: emailFromVal, name: nameVal, message: messageVal, subject: subject },
				function(data){
				$("#submit").slideUp("normal", function() {
					$("#loading").hide();
					$("#status p").text('Thanks, your email was sent.');
				});
			});
		}
		
		return false;
	});
});
