/***************************************
// Site design and programming by:
// Logan Stellway - logsup1@yahoo.com 
***************************************/

/* FONT REPLACEMENT */
Cufon.replace('h1', {
	fontFamily: 'metaserif',
	textShadow: '#006ea4 1px 1px'
});
Cufon.replace('.nav h2', {
	fontFamily: 'metaserif'
});
Cufon.replace('h2', {
	fontFamily: 'metaserif'
});
Cufon.replace('a.form_btn_send', {
	fontFamily: 'metaserif'
});
Cufon.replace('.bio_heading', {
	fontFamily: 'metaserif',
	fontSize: '44px',
	color: '-linear-gradient(#006da4, #006ca3)'
});

/* DOCUMENT READY */
$(document).ready(function(){
	$('a.js_check').hide();
	$("a.btn_top").smoothScroll();
	/* FORM INITIALIZE */
	$(".wp_search input").focus(function(){
		$(this).parents("div.wp_search:first").addClass("wp_search_active");
	}).blur(function(){
		$(this).parents("div.wp_search:first").removeClass("wp_search_active");
	});
	$(".form_input_right input").focus(function(){
		$(this).parent().addClass("form_input_right_active").parent().addclass("form_input_left_active");
	}).blur(function(){
		$(this).parent().removeClass("form_input_right_active").parent().removeClass("form_input_left_active");
	});
	$(".form_textarea_padder textarea").focus(function(){
		$(this).parent().parent().addClass("form_textarea_right_active").parent().addclass("form_textarea_left_active");
	}).blur(function(){
		$(this).parent().parent().removeClass("form_textarea_right_active").parent().removeClass("form_textarea_left_active");
	});
	
	/* FORM SUBMISSION */
	$("a.wp_search_submit, a.submit_form").click(function(){
		$(this).parents("form:first").submit();
	});
});


/* SCROLL */
jQuery.fn.smoothScroll = function(settings) {
 	settings = jQuery.extend({
		speed : 1200
	}, settings);	
	return this.each(function(){
		$(this).click(function (event) {	
			event.preventDefault();
			var locationHref = window.location.href;
			var elementClick = $(this).attr("href");
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").stop().animate({scrollTop:destination}, settings.speed, function() {
				window.location.hash = elementClick;
			});
		  	return false;
		})
	})
}


/* FORM VALIDATION */
// EMAIL
jQuery.fn.validateEmail = function() {
	$(this).blur(function(){
		var theValue = $(this).val().replace(/ /g,'');
		var theLabel = $(this).attr("name");
		if(!validEmail(theValue)) {
			$('label[for="'+theLabel+'"]').removeClass('red').addClass('red');
		} else {
			$('label[for="'+theLabel+'"]').removeClass('red');
		}
	});
}
function validEmail(e) {
	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(e);
}
// NAME
jQuery.fn.validateAlphabetic = function() {
	$(this).blur(function(){
		var theValue = $(this).val().replace(/ /g,'');
		var theLabel = $(this).attr("name");
		if(!validAlphabetic(theValue)) {
			$('label[for="'+theLabel+'"]').removeClass('red').addClass('red');
		} else {
			$('label[for="'+theLabel+'"]').removeClass('red');
		}
	});
}
function validAlphabetic(n) {
	var pattern = new RegExp(/^[a-zA-Z.]+[a-zA-z.]+[a-zA-Z.]*$/i);
	return pattern.test(n);
}
