function next_week(target_week_day, basedOnServiceStart)
{         
	date = new Date();

	day = date.getDate();
	month = date.getMonth();
	year = date.getFullYear();
	week_day = date.getDay();
	last_service = new Date();
	if(basedOnServiceStart)
	{
		// Use the beginning of the Edge Service
		last_service.setUTCHours(17);
		last_service.setUTCMinutes(0);
		last_service.setUTCSeconds(0);		
	} else {
		// Use the end of the last service
		last_service.setUTCHours(18);
		last_service.setUTCMinutes(15);
		last_service.setUTCSeconds(0);
	}
	

	months = new Array('January',
	                   'February',
	                   'March',
	                   'April',
	                   'May',
	                   'June',
	                   'July',
	                   'August',
	                   'September',
	                   'October',
	                   'November',
	                   'December');
                           

	//This assumes that if today is a target week day,
	//today's date will be used and not next week's.
	//To change that, just change
	//if(week_day <= target_week_day)
	//to
	//if(week_day < target_week_day)

	if(week_day <= target_week_day && date < last_service)
	   days_left = target_week_day - week_day;
	else
	   days_left = 7 - (week_day - target_week_day);

	//This script works by finding out the number of days separating
	//the current date and the next target week day.
	next_week_day = new Date(year, month, day + days_left);

	next_week_html = months[next_week_day.getMonth()] + " " + next_week_day.getDate() + ", " + next_week_day.getFullYear();
                                     
	//document.write(next_week_html);
	return next_week_day;
	
}

function nextService() {
	
	nextService = new Date();
		
	var traditionsService = new Date();
	traditionsService = next_week(0, true);
	traditionsService.setUTCHours(14);
	traditionsService.setUTCMinutes(0);
	 
	var mosaicService = new Date();
	mosaicService = next_week(0, true);
	mosaicService.setUTCHours(15);
	mosaicService.setUTCMinutes(30);
		
	var edgeService = new Date();
	edgeService = next_week(0, true);
	edgeService.setUTCHours(17);
	//edgeService.setUTCMinutes(10);
	
	if(traditionsService > date.getTime())
	{
		nextService = traditionsService;
	} else {
		if(mosaicService > date.getTime()) {
				nextService = mosaicService;
		} else {
			if(edgeService > date.getTime()) {
					nextService = edgeService;
			}
		}
				
	}
	
	return nextService;

}

// A quick function to see if we are currently live.  There will be a 15 minute buffer
// at the beginning.  I will we will not be considered live at 12:10 PM CST.  
// 
// Return true of false
function isLive()
{
	var startServices = new Date();
	startServices = next_week(0, false);
	startServices.setUTCHours(13);
	//startServices.setUTCMinutes(15);

	var endServices = new Date();
	endServices = next_week(0, false);
	endServices.setUTCHours(18);
	endServices.setUTCMinutes(15);
	
	var now = new Date();
	//now = date.getTime();

	if(now > startServices && now < endServices)
	{
		return true;
	} else {
		return false;
	}
}	

// This is the slide show script functions. Requires JQuery 
function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
     var $sibs  = $active.siblings();
     var rndNum = Math.floor(Math.random() * $sibs.length );
     var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
// slideshow