jQuery(document).ready(function($) {



		
		$('input#s').click(function(){
			if ( $(this).val() == 'Search our blog...' ) { 
				$(this).val('');
			}
		});
		$('input#s').blur(function(){			   
			if ( $(this).val() == '' ) 
				$(this).val('Search our blog...'); 
		});
		
		$('input.bmform_frm104442').click(function(){
			if ( $(this).val() == 'Your Name' || $(this).val() == 'Your Email' ) { 
				$(this).val('');
			}
		});
		$('input.bmform_frm104442').blur(function(){
			if ( $(this).val() == '' ) { 
				if ( $(this).attr('id') == 'news_name' ) 
					$(this).val('Your Name');
				if (  $(this).attr('id') == 'news_email' ) 
					$(this).val('Your Email');
			}
		});
		

		$('.home #featured div.box, .home #featured div.box-two, .home #featured div.box-three').hover(function(){
			$(this).children('div').stop().animate({
				height: '260px' 
			}, 'fast').addClass('active');
			$(this).prev('a').stop().animate({ bottom: '260px', opacity: .7 }, 'fast');
			$(this).children('div').children('.more').stop().show();
		}, function(){
			$(this).children('div').stop().animate({
				height: '84px' 
			}, 'fast').removeClass('active');
			$(this).prev('a').stop().animate({ bottom: '83px', opacity: 1 }, 'fast');
			$(this).children('div').children('.more').stop().hide();
		});
		
		$('.home #featured div div').click(function(){
			var gotourl = $(this).children('.more').attr('href');
			window.location.href = gotourl;
		});
		
		$('#contact-form button').click(function(){
			var errors = 0;
			var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
			$('#contact-form p').removeClass('error'); 
			
			$('#contact-form .req').each(function(){
				if ( $(this).val().length < 1 ) { 
					$(this).parent().addClass('error');
					//alert($(this).attr('id'));
					errors++;
				}
			});
			/*
			if (! regex.test($('#email').val()) ) { 
				$(this).parent().addClass('error');
				errors++;
			}
			*/
			if ( errors > 0 ) { 
				return false; 
				alert('Please complete all required fields');
			} 
			else { return true; }
		});
		
		$('#quiz #btnSubmit').click(function(){
			var errors = 0;
			$('#quiz p').removeClass('error'); 
			$('#quiz tr').removeClass('error');
			
			$('#quiz .required').each(function(){
				if ( $(this).val().length < 1 ) { 
					$(this).parent().addClass('error');
					errors++;
				}
			});
			
			for ( var a = 1; a <= 10; a++ ) { 
				var radiovalue = false;
				$('#quiz input[name=A_'+a+']:radio').each(function(){
					if ( $(this).is(':checked') ) { radiovalue = true; }
				});
				if ( radiovalue == false ) { $('#quiz input#A_'+a+'_1').parent().parent().addClass('error'); errors++; }
			}
			for ( var a = 1; a <= 10; a++ ) { 
				var radiovalue = false;
				$('#quiz input[name=B_'+a+']:radio').each(function(){
					if ( $(this).is(':checked') ) { radiovalue = true; }
				});
				if ( radiovalue == false ) { $('#quiz input#B_'+a+'_1').parent().parent().addClass('error'); errors++; }
			}
			var radiovalue = false;
			$('#quiz input[name=C_1]:radio').each(function(){
				if ( $(this).is(':checked') ) { radiovalue = true; }
			});
			if ( radiovalue == false ) { $('#quiz input#C_1_1').parent().parent().addClass('error'); errors++; }
			
			if ( errors <= 0 ) return true; 
			else { 
				var anchor = $('#quiz .error:first').offset().top - 50;
				$('html,body').stop().animate({ scrollTop: anchor}, 500);
				alert("Please complete all fields");
				return false;
			}
		});

		$('#registration-form button').click(function(){
			var errors = 0;
			var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
			$('#registration-form p').removeClass('error'); 
			
			$('#registration-form .req').each(function(){
				if ( $(this).val().length < 1 ) { 
					$(this).parent().addClass('error');
					errors++;
				}
			});
			
			if (! regex.test($('#email').val()) ) { 
				$(this).parent().addClass('error');
				errors++;
			}
			
			if ( errors > 0 ) { 
				return false; 
				console.log('Please complete all required fields'); 
			} 
			else { return true; }
		});

		$('#respond #submit').click(function(){
			var errors = 0;
			var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
			$('#comment-form p').removeClass('error');  	
			
			if ( $('#author').val().length < 1 ) { 
				$('#author').parent().addClass('error');
				errors++
			}
			if ( $('#email').val().length < 1 ) { 
				$('#email').parent().addClass('error');
				errors++;
			}
			if (! regex.test($('#email').val()) ) { 
				$('#email').parent().addClass('error');
				errors++;
			}
			if ( $('#comment').val().length < 1 ) { 
				$('#comment').parent().addClass('error');
				errors++;
			}
			if ( errors > 0 ) { 
				return false; 
				alert('Please complete all required fields'); 
			} 
			else { return true; }
		
		});
		
		$('.newsletter #btnSubmit').click(function() { 
			var errors = 0;
			var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
			$('.newsletter p ').removeClass('error');
			
			if ( $('#news_name').val().length < 1 || $('#news_name').val() == 'Your Name' ) { 
					$('#news_name').parent().addClass('error');
					errors++;
			}
			if ( $('#news_email').val() == '' || $('#news_email').val() == 'Your Email' ) { 
					$('#news_email').parent().addClass('error');
					errors++;
			}
			if (! regex.test($('#news_email').val()) ) { 
				$('#news_email').parent().addClass('error');
				errors++;
			}
			
			if ( errors > 0 ) { alert('Please enter a Name and a valid Email Address.'); return false; }
			else return true;
		});
		
		
		$('#referred').change(function() {
			if ( $(this).val() == 'Other') $('#other').addClass('required');
			else $('#other').removeClass('required');
		});


});
