var popupTopSpace = 200; //value in pixels or 'middle' (with quotes) to place it on the screen middle



//other variables, you shouldn't change these
var popupVisible = false;
var popupHeight = 0;
var popupTop = 0;

function popup() {

	//reset
	popupVisible = true;
	
	//show popup
	$('#np_curtain').fadeIn(150, function() {
	
		setTimeout(function() {
			//center it vertically
			popupHeight = $('#np_popup').height();
			
			if (popupTopSpace == 'middle' || $(document).height() < (popupHeight + popupTopSpace)) {
				
				if (($(document).height() - popupHeight) < 0) {
					var newTop = '2px';
				} else {
					var newTop = ($(document).height() - popupHeight) / 2;
				}
				
			} else {
				var newTop = popupTopSpace + 'px';
			}
			
			popupTop = newTop;
			
			
			$('#np_popup').animate({top: newTop}, 300);
			
		}, 300);
	
	
	});
	
	return true;

}


function closePopup() {

	popupVisible = false;
	$('#np_curtain, #np_popup').hide();

}


$(document).ready(function() {

	setTimeout(popup, 500);
	
	$('#popup-close').click(closePopup);
	$('#np_popup').css('left', ($(document).width() - 400) / 2);
	
});

$(document).scroll(function() {

	$('#np_popup').animate({top: $(document).scrollTop() + popupTopSpace}, 300);

});

function checkTime() {
		
		if (isNaN(parseInt($('#year').val())) || isNaN(parseInt($('#month').val())) ||
			isNaN(parseInt($('#day').val()))) {
			return alert('All fields must be filled with a numeric value');
		}
		
		var birth = new Date(parseInt($('#year').val()), parseInt($('#month').val()), parseInt($('#day').val()));
		var today = new Date();
	
		var diff = (today.getTime() - birth.getTime())/1000;
		
		if (diff < 662695445) {
			alert('Return when you are over 21');
		} else {
			$.ajax({
				type: 'POST',
				url: 'remember.php',
				success: function(data) {
					if(data == 'ok') {
						closePopup();
						window.location = 'http://sites.google.com/site/ciscobeers/';
					}
				}
			});
		}
		
}

