/*
	Church of the Highlands | Online Campus
	Birmingham, Alabama, USA
	Version 1
	Global JavaScript (It DOMinates.)
	Code: Scott Wehrenberg + David Russell
*/
function startCountdown(next_time) {
	$('#webcast').hide();     
	$('#countdown').countdown('destroy');
	$('#countdown').countdown({
		until: '+' + next_time,
		layout: '{dn} {dl}, {hn} {hl}, {mn} {ml}, {snn} {sl}',
		onExpiry: startFeed,
		alwaysExpire: 'TRUE'
	});
}

function startFeed() {
	$('#webcast').show();     
	$('#countdown').hide();
	$.ajax({
		url: "./next_close.php"
		, success: function(data) {
			 setTimeout(data, closeVideo);
		 }
		, type: "POST"
		, error: function(e) { }
	});
}

function closeVideo() {
	$('#webcast').hide();
	$('#countdown').show();
	$.ajax({
		url: "./next_start.php"
		, success: function(data) { startCountdown(data); }
		, type: "POST"
		, error: function(e) { startFeed(); }
	});
}
/*
	Windows
*/
$(document).ready(function() {
	$('a.give, a.window').popupWindow({ 
		centerScreen: 1,
		resizeable: 1,
		menubar: 1,
		scrollbars: 1,
		height: 650,
		width: 700
	});
	$('a.audio').popupWindow({ 
		centerScreen: 1,
		resizeable: 1,
		menubar: 1,
		scrollbars: 0,
		height: 220,
		width: 500
	});
	$('a.notes').popupWindow({ 
		centerScreen: 1,
		resizeable: 0,
		menubar: 1,
		scrollbars: 0,
		height: 600,
		width: 800
	});
});
