
// REMOVE NAVIGATION LINK HIGHLIGHTING
//==================================================
$(function(){
	$('.link-home').click(function(){
		$('#nav a').removeClass('activ');
	});
});


// NAVIGATION LINK HIGHLIGHTING
//==================================================
$(function(){
	$('#nav a').click(function(){
		$('#nav a').removeClass('activ');
			$(this).addClass('activ');
	});
});


// LOCALSCROLL
//==================================================
$(function(){
	$('#nav, #header, .content-main').localScroll({
	   target:'#content',
	   queue:true,
	   duration:700
	});
});


// CONTACT INPUT + TEXTAREA FIELD DEFAULT VALUE HIDING
//==================================================
$(function(){
	var el = $('input[type=text], input[type=email], textarea');
	    el.focus(function(e) {
	        if (e.target.value == e.target.defaultValue)
	            e.target.value = '';
	    });
	    
	    el.blur(function(e) {
	        if (e.target.value == '')
	            e.target.value = e.target.defaultValue;
	    });
});

// FORM VALIDATION
//==========
$(function() {
	$("#comment-form").bind('submit.sn', function() {
		var defaults = {
			name: $('#comment-form #name').get(0).defaultValue,
			email: $('#comment-form #email').get(0).defaultValue,
			comments: $('#comment-form #comments').get(0).defaultValue
		};
		var values = {
			name: $('#comment-form #name').val(),
			email: $('#comment-form #email').val(),
			comments: $('#comment-form #comments').val()
		};

		// RFC 2822-compliant email regex
		var email_regex = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/;

		if(defaults.name === values.name || $.trim(values.name) === "") {
			$('#response').text('Name field is required');
			return false;
		}
		if(defaults.email === values.email || $.trim(email) === "") {
			$('#response').text('Email field is required');
			return false;
		}
		if(defaults.comments === values.comments || $.trim(comments) === "") {
			$('#response').text('Questions/Comments are required');
			return false;
		}
		if(!values.email.match(email_regex)) {
			$('#response').text('Invalid email address');
			return false;
		}
	});
});

