$(function(){
	$('#slideparty img:gt(0)').hide();
	setInterval(function(){ $('#slideparty :first-child').fadeOut(2000).next('img').fadeIn(1000).end().appendTo('#slideparty');}, 5000);
});
$("#l1").click(function(){window.open('http://www.tonichealthshot.com/', '_blank');});
$("#l2").click(function(){window.open('http://www.drinkgive.com/', '_blank');});
$("#l3").click(function(){window.open('http://www.drinkgive.com/', '_blank');});

$("#submitform").click(function(){ validateContact(); return false; });
$("#contactform").submit(function(){ validateContact(); return false; });
$("#contactme").click(function(){ contactme(); return false; });

function contactme(){
	formSetup();
	$('#contactpop').reveal({
		 animation: 'fadeAndPop',                   //fade, fadeAndPop, none
		 animationspeed: 300,                       //how fast animtions are
		 closeonbackgroundclick: true,              //if you click background will modal close?
		 dismissmodalclass: 'close-reveal-modal2'    //the class of a button or element that will close an open modal
	});
}

function formThanks(){
	$("#theform").slideUp(600, function(){ $("#thanks").slideDown(200); });
}
function formSetup(){
	$("#theform").show();
	$("#thanks").hide();
}
function validateContact(){
	var starter = document.contactform;
	if (starter.first_name.value == ''){
		alert("Please enter your first name.");
		starter.first_name.focus();
		return 0;
	}
	if (starter.last_name.value == ''){
		alert("Please enter your last name.");
		starter.last_name.focus();
		return 0;
	}
	if (starter.email.value == ''){
		alert("Please enter your email address.");
		starter.email.focus();
		return 0;
	} else {
		var str = starter.email.value;
	    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	    if (!str.match(re)) {
	        alert("Your email address is invalid. Please verify that you have entered it correctly.");
			starter.email.focus();
			return 0;
	    }
	}
	if (starter.phone.value == ''){
		alert("Please enter your phone number.");
		starter.phone.focus();
		return 0;
	}
	if (starter.company.value == ''){
		alert("Please enter your company name.");
		starter.company.focus();
		return 0;
	}
	$.post("ajax_service.php?do=postform", $("#contactform").serialize(), function(){ formThanks(); });
	return false;
	//starter.submit();
}
