// JavaScript Document

// PRELOADER //

function preLoaderInit() {

		countStop = 10;
		currSecond = 0;
		preLoaderCount();
		
		currBk = 1;
		totalBk = 4;
		
		currPh = 1;
		totalPh = 8;

}

function preLoaderCount() {

	currSecond++;

	if(currSecond > 1) {
		document.getElementById("pre-"+(currSecond - 1)).style.display = "none";
		//$("#pre-"+(currSecond - 1)).fadeOut('slow');
		/*
		$("#pre-"+(currSecond - 1)).hide("drop", { direction: "down" }, 400, function() {
			$("#pre-"+currSecond).show("drop", { direction: "up" }, 400);							 
		});
		*/
	}
	
	document.getElementById("pre-"+currSecond).style.display = "block";
	//$("#pre-"+currSecond).fadeIn('slow');
	//$("#pre-"+currSecond).show("drop", { direction: "up" }, 500);
	
	if(currSecond < countStop) {
		setTimeout("preLoaderCount()",1200);
	} else if(currSecond == countStop) {
		setTimeout("preLoaderCountLast()",1200);
	}

}

function preLoaderCountLast() {
	document.getElementById("pre-"+countStop).style.display = "none";
	document.getElementById("preloader").style.display = "none";
	//document.getElementById("main").style.display = "block";
	
	/*
	$('#scrollableContentBk').show('pulsate', { times:3 }, 150, function() {
		$('#scrollableContentBk').hide();
		$('#scrollableContentBk').fadeIn('slow', function() {
			$('#main').fadeIn(1000);
			setTimeout("bkSwap()",6000);
			setTimeout("phSwap()",6000);
		});
	});
	*/
	
	$('#scrollableContentBk').fadeIn('slow');
	$('#main').fadeIn('slow');
	$('#logoHolder').css('visibility', 'visible');
	
	setTimeout("bkSwap()",6000);
	setTimeout("phSwap()",6000);
	
}

function bkSwap() {

	$('#scrollableContentBk').fadeOut('slow', function() {
													   
		if(currBk == totalBk) {
			currBk = 1;
		} else {
			currBk++;
		}
													   
		$('#scrollableContentBk').css("background-image", "url(images/bks/bk"+currBk+".jpg)");
		$('#scrollableContentBk').fadeIn('slow');		  
	});
	
	setTimeout("bkSwap()",6000);

}

function phSwap() {

	$('#ph-'+currPh).fadeOut('slow', function() {
											 
		if(currPh == totalPh) {
			currPh = 1;
		} else {
			currPh++;
		}
											 
		$('#ph-'+currPh).fadeIn(1000);			  
	});
	
	setTimeout("phSwap()",6000);

}

function learnMore(what) {
	
	currDisplay = document.getElementById(what).style.display;
	
	if(currDisplay != "block") {
		document.getElementById(what).style.display = "block";
	} else {
		document.getElementById(what).style.display = "none";
	}
	
}

// UPDATES FORM //

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function submitUpdates() {

	emailStr = document.getElementById("emailfield").value;

	if(isValidEmailAddress(emailStr)) {
		
		$.post("_scripts/updates.php", { email: emailStr },
		   function(data){
				response = data;
				document.getElementById("errors").innerHTML = response;
			});
		
	} else {
	
		response = "please enter a valid email address";
		document.getElementById("errors").innerHTML = response;
	
	}

}