/* 
Author: Mitch Gohman with much love to JQuery. The Cross Browser Equalizer.
Date: 2010-11-28
*/
var MNC = {};

/*Home*/
MNC.splashCurrent = 1;
MNC.currSlide = 3; //the 4th element of our looped array. We show the first 4. Reduce server load.
MNC.totalSlides; //when we loop we will count the number of slides.
MNC.slides = Array();

MNC.splash_slide = function() {
	MNC.totalSlides = MNC.slides.length;
	
	if (MNC.currSlide == (MNC.totalSlides-1))
			{
			MNC.currSlide = 0;
			}
			else
			{
			MNC.currSlide++;
			}
	
	var loadNewImage = new Image();
	loadNewImage.src = MNC.slides[MNC.currSlide];
	//console.log(MNC.currSlide);
	
	$("#splashSlides img").css({'margin-top':'0px'});
	var topImage = $("#splashSlides img:first");	
	
	
	$(topImage).animate({'margin-top':'-327px'},1000,
	function() { 
		$(topImage).attr('src',loadNewImage.src);
		$(topImage).appendTo("#splashSlides .clippingMask");
	
		
		setTimeout(function() { MNC.splash_slide(); },4000);
	});
		
	
}



MNC.email_show = function (event) {
	$("#theLight h2").html('Send Us An Email');
	$("#theLight .content").html('');
	
	var duplicateForm = $(".emailUs").clone();
	$(duplicateForm).appendTo("#theLight .content");
	
	$("#theLight, #theDark").css({ display:'block' });
	
	$("#theLight .content .emailUs input.sendMessage").click(MNC.email_process_validate);
	
	event.preventDefault();
	
}


MNC.email_close = function () { $("#theLight, #theDark").css({ display:'none' }); }

MNC.email_process_validate = function(event) {
	//check the fields
	var reqFields = $("#theLight .emailUs .required");
	var error = false;
	var feedback = '';
	var validEmail = false;
	var missingField = false;
	
	for (var i = 0; i < reqFields.length; i++)
		{
		var value = $(reqFields[i]).attr('value');
		if (value.length < 1)	
			{
			$(reqFields[i]).addClass('missing');
			missingField = true;
			}
			else
			{
			$(reqFields[i]).removeClass('missing');
			//see if its a valid email
			emailValue = $("#theLight .emailUs .email").attr('value');
			validEmail = MNC.isValidEmail(emailValue);
			
			if (!validEmail)
				{
				$(reqFields[i]).addClass('missing');
				missingField = true;
				}
				
			}
		}
	
	
	if (!validEmail)
		{
		feedback += 'The email you provided does not appear to be valid. ';
		error = true;
		$("#theLight .emailUs .email").addClass('missing');
		}
	
	if (missingField)
		{
		feedback += 'You forgot to fill out one of the required fields.';
		error = true;
		}
	
	//do not send form
	if (error)
		{
		event.preventDefault();
		alert(feedback + 'Please check the form and try again.');
		}
		else
		{
		event.preventDefault();
		MNC.email_process();	
		}
}


MNC.isValidEmail = function(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

$(document).ready(function() {
	
});
