var slideshowDelay = 5000;
var slideshowAnimationDelay = 1000;
var slideWidth = 960;
var slideshowRunning = true;
var slideActive = 1;

var slides = new Array();

$(document).ready(function() {
	$('.slideshow-nav li').each(function() {
		slides.push($(this).html());
	});
	
	$('.slideshow-nav li').click(function() {
		if(!$(this).hasClass("active")) {
			slideshowRunning = false;
			animateSlideshow($(this).attr("rel"));
		}
	});
	
	startSlideshow();
	
	$('.submit').click(function() {
//		return validateForm();
		if(validateForm()) {
			$.post('/splashpage/post_contact.php', $(this).parents('form').serialize(), function() {
				$('input.submit').parent().html('<p>Your submission has been delivered.<br>Thank you for your interest.</p>');
			});
		}
		return false;
	});
});


function startSlideshow() {
	if(slideshowRunning) {
		setTimeout(function() {
			var newIndex = slideActive + 1;
			if(newIndex > $('#slideshow-wrapper').children().length) {
				newIndex = 1;
			}
			if(slideshowRunning) {
				animateSlideshow(newIndex);
			}
			startSlideshow();
		}, slideshowDelay);
	}
}

function animateSlideshow(index) {
//	index = index * 1;
//	var new_left = (index - 1) * slideWidth * -1;
	$('.slideshow-box.active').animate({opacity: 0}, slideshowAnimationDelay, function() {
		$('.slideshow-box.active').removeClass('active');
	});
	$('.slideshow-box[rel=' + index + ']').animate({opacity: 1}, slideshowAnimationDelay, function() {
		$('.slideshow-box[rel=' + index + ']').addClass('active');
	});
	slideActive = index;
}


function validateForm() {
	var errors = false;
	$('input').removeClass('error');
	
	var $name = $('input[name=name]');
	var $email = $('input[name=email]');
	
	if($.trim($name.val()) == '') {
		errors = true;
		$name.addClass('error');
	}
	if($.trim($email.val()) == '') {
		errors = true;
		$email.addClass('error');
	}
	
	return !errors;
}



