function init() {
	var top = $(document).scrollTop() + ($(window).height() - $('.popup').outerHeight()) / 2;
	var left = $(document).scrollLeft() + ($(window).width() - $('.popup').outerWidth()) / 2;

	$('.popup').css('top', top);
	$('.popup').css('left', left);

	$('.prayer-close').click(function() {
		$('.mask').hide();
		$('.popup').hide();
	});

	$('.prayer-button input').click(function() {
		if (!$('.prayer-textarea').val()) {
			alert('Please enter your message!');

			return false;
		}

		$(this).val('Sending...').attr('disabled', true);

		$.ajax({
			url: 'http://prayer.thejobconnection.org/index.php',
			data: ({
				eID: 'tx_prayer_pray',
				id: $('.prayer-id').val(),
				pray: $('.prayer-textarea').val()
			}),
			dataType: 'script',
			success: function() {
				$('.prayer-button').html(data.info).removeClass('prayer-button');

				setTimeout(function() {
					$('.prayer-close').trigger('click');
				}, 3000);
			}
		});
	});
}

$(document).ready(function() {
	$('.prayer:last').css('margin-bottom', '0px');

	$('.prayer-link').click(function() {
		$.ajax({
			url: 'http://prayer.thejobconnection.org/index.php',
			data: ({
				eID: 'tx_prayer_popup',
				prayer: this.getAttribute('id')
			}),
			dataType: 'script',
			success: function() {
				$('.mask').height($(document).height()).show();
				$('.popup').html(data.info).show();

				init();
			}
		});
	});

	$('.agreement').click(function() {
		$.ajax({
			url: 'index.php',
			data: ({
				eID: 'tx_prayer_popup',
				agreement: 1
			}),
			dataType: 'script',
			success: function() {
				$('.mask').height($(document).height()).show();
				$('.popup').html(data.info).show();

				init();
			}
		});
	});
});
