/*
 * Email form validation
 */

var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(text, img, name, title){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#emailPopupBackground").css({
		"opacity": "0.7"
	});
	$("#emailPopupBackground").fadeIn("slow");
	$("#emailPopup").fadeIn("slow");
	popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1) {
		$("#emailPopup").fadeOut("slow");
		$("#emailPopupBackground").fadeOut("slow");
		popupStatus = 0;
		$('#show').cycle('resume');
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#emailPopup").height();
	var popupWidth = $("#emailPopup").width();
	//centering
	$("#emailPopup").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#emailPopupBackground").css({  
		"height": windowHeight  
	}); 
}


$(document).ready(function() {
	$("#popupButton").click(function() {
		$('#show').cycle('pause');
		centerPopup();
		loadPopup();
	});
	
	$("#emailPopupBackground").click(function() {
		if (popupStatus == 1) {
			disablePopup();
		}
	});
	  
	$(".button").click(function() {  
		var email = $("#email").val();
		if (email == "") {
			return false;
		}
		var firstname = $("#firstname").val();
		var lastname = $("#lastname").val();
		
		var dataString = 'firstname='+ firstname + '&lastname='+ lastname + '&email='+ email;
		// alert (dataString);return false;
		$.ajax({
			type: "POST",
			url: "http://www.jaguardesignstudio.com/testarossa/email_popup/send_email.php",
			data: dataString,
			success: function() {
				$("#email_popup").html("<div id='message'></div>");
				$("#message").html("&nbsp;<br /><h3>Sign-Up Submitted!</h3><br />&nbsp;<br />Click outside of this window to close<br />");
			}
		});
		return false;
	});  
});



