document.observe('dom:loaded', function() {   
	// this array consists of the id attributes of the divs we wish to alternate between
	var divs_to_fade = new Array('online-backup', 'photo-sharing', 'disaster-recovery', 'file-sharing');

	// the starting index in the above array.  It should be set to the value of the div which doesn't have the CSS Display property set to "none"
	var i = 0;

	function increment() {
		$(divs_to_fade[i]).hide();
		i++;
		if (i == 4) i = 0;
		$(divs_to_fade[i]).show();
	}
	
	function decrement() {
		$(divs_to_fade[i]).hide();
		i--;
		if (i == -1) i = 3;
		$(divs_to_fade[i]).show();
	}
	
	var slideexe = new PeriodicalExecuter(
		function swapFade() {
			increment();
		}, 6);

	$('left-control').observe('click', function() {
		slideexe.stop(); decrement(); 
	});
	
	$('right-control').observe('click', function() {slideexe.stop(); increment(); });
	$('for-personal').observe('click', function() {document.location = '/dyn/actions/viewRegister?type=pro';	});
	$('for-business').observe('click', function() { document.location = '/dyn/actions/viewRegister?type=enterprise';	});
	
	$('left-control').observe('mouseover', function() {
		this.style.backgroundPosition = 'bottom left';
	});
	
	$('right-control').observe('mouseover', function() {
		this.style.backgroundPosition = 'bottom right';
	});
	
	$('left-control').observe('mouseout', function() {
		this.style.backgroundPosition = 'top left';
	});
	
	$('right-control').observe('mouseout', function() {
		this.style.backgroundPosition = 'top right';
	});
	
}); 

//validates homepage sign up form
function validateSignUpForm()
{
	returnVal = true;
	errorStr = "";
	firstName = $('sign-up-firstName').value;
	lastName = $('sign-up-lastName').value;
	emailAddress = $('sign-up-email').value;
	emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	agreeTerms = $('agree-terms-privacy');
	
	if (firstName.length < 1) {
		errorStr += "Please enter your first name.\n";
		returnVal = false;
	}
	if (lastName.length < 1) {
		errorStr += "Please enter your last name.\n";
		returnVal = false;
	}
	if (emailAddress.length < 5 || !emailFilter.test(emailAddress)) {
		errorStr += "Please enter a valid email address.\n";
		returnVal = false;
	}
	if (emailAddress.toLowerCase().indexOf("mailinator.com") > 0) {
		errorStr += "We do not accept registrations from 'throw away' email accounts.\n";
		returnVal = false;
	}
	if (!agreeTerms.checked) {
		errorStr += "You must agree to our terms of service and our privacy policy.\n";
		returnVal = false;
	}	
	if (!returnVal)
		alert(errorStr);
	
	return returnVal;
}
