var ahOverlay = {
	init : function() {
		$('#contactForm #submitThis').live('click',
			function(e) {
				e.preventDefault();
				ahOverlay.sendForm();
			}
			);
		ahOverlay.slideOut();
		$('#main a.nyroModal').nyroModal({minHeight: '126'});
		$('#resumeLink a.nyroModal').nyroModal({width:'750'});
		$('#contactLink a.nyroModal').nyroModal({width:'750'});
	},
	
	sendForm : function() {
		//alert('Send Form');	
		$('#contactForm #submitThis').ajaxStart(function() {
			this.value = "Sending ...";
			this.disabled = true;
		}).ajaxStop(function() {
			this.value = "Send Message";
			this.disabled = false;
		});
		$.post(
			'handleForm.php',
			$('#contactForm :input').serialize(),
			function(json) {
				// Check for validation errors
				if (json.fName){
					$("label[for='fName']").find('.error').show();
				} else {
					$("label[for='fName']").find('.error').hide();
				}
				if (json.lName){
					$("label[for='lName']").find('.error').show();
				} else {
					$("label[for='lName']").find('.error').hide();
				}
				if (json.email){
					$("label[for='email']").find('.error').show();
				} else {
					$("label[for='email']").find('.error').hide();
				}
				if(json.status){
					$('#formStatus').text(json.status).fadeIn('slow');
					$('#contactForm input').add('#contactForm label').add('#contactForm textarea').hide();
					setTimeout(ahOverlay.hideOverlay,3000);
				}
				//alert (json);
			},
			'json'
			);
	},
	
	hideOverlay : function() {
		$.nyroModalRemove();
	},
		
	slideOut : function() {
		$('.slideOut ul').hide()
		$('.slideOut a:first').click(
			function(e) {
				e.preventDefault();
				$('.slideOut ul').slideToggle('slow');				
			}
		);
	}
}

$(document).ready(ahOverlay.init);

    
