<?php
/**
 * The Template for displaying a single sermon.
 *
 * @package WordPress
 * @subpackage ChurchThemes
 *
 ===================================================================================================
 WARNING! DO NOT EDIT THIS FILE OR ANY TEMPLATE FILES IN THIS THEME!

 To make it easy to update your theme, you should not edit this file. Instead, you should create a
 Child Theme first. This will ensure your template changes are not lost when updating the theme.

 You can learn more about creating Child Themes here: http://codex.wordpress.org/Child_Themes

 You have been warned! :)
 ===================================================================================================
 */

get_header();

global $post;
$args=array(
	'post_type' => 'ct_sermon',
	'post_status' => 'publish',
	'p' => $post->ID,
	'posts_per_page' => 1,
);
$query = null;
$query = new WP_Query($args);

$sermon_speaker = get_the_term_list($post->ID, 'sermon_speaker');
$thespeakers = strip_tags($sermon_speaker);
$sermon_series = get_the_term_list($post->ID, 'sermon_series');
$theseries = strip_tags($sermon_series);
$sermon_service = get_the_term_list($post->ID, 'sermon_service');
$theservices = strip_tags($sermon_service);
$sermon_topic = get_the_term_list($post->ID, 'sermon_topic');
$thetopics = strip_tags($sermon_topic);

$sm_video_embed = get_post_meta($post->ID, '_ct_sm_video_embed', true);
$sm_video_file = get_post_meta($post->ID, '_ct_sm_video_file', true);
$sm_video_button_text = get_post_meta($post->ID, '_ct_sm_video_button_text', true);

$sm_audio_button_text = get_post_meta($post->ID, '_ct_sm_audio_button_text', true);
$sm_audio_length = get_post_meta($post->ID, '_ct_sm_audio_length', true);
$sm_audio_file = get_post_meta($post->ID, '_ct_sm_audio_file', true);

$sm_sg_button_text = get_post_meta($post->ID, '_ct_sm_sg_button_text', true);
$sm_sg_file = get_post_meta($post->ID, '_ct_sm_sg_file', true);

$sm_bible01_book = get_post_meta($post->ID, '_ct_sm_bible01_book', true);
$sm_bible01_start_chap = get_post_meta($post->ID, '_ct_sm_bible01_start_chap', true);
$sm_bible01_start_verse = get_post_meta($post->ID, '_ct_sm_bible01_start_verse', true);
$sm_bible01_end_chap = get_post_meta($post->ID, '_ct_sm_bible01_end_chap', true);
$sm_bible01_end_verse = get_post_meta($post->ID, '_ct_sm_bible01_end_verse', true);

$sm_bible02_book = get_post_meta($post->ID, '_ct_sm_bible02_book', true);
$sm_bible02_start_chap = get_post_meta($post->ID, '_ct_sm_bible02_start_chap', true);
$sm_bible02_start_verse = get_post_meta($post->ID, '_ct_sm_bible02_start_verse', true);
$sm_bible02_end_chap = get_post_meta($post->ID, '_ct_sm_bible02_end_chap', true);
$sm_bible02_end_verse = get_post_meta($post->ID, '_ct_sm_bible02_end_verse', true);

$sm_bible03_book = get_post_meta($post->ID, '_ct_sm_bible03_book', true);
$sm_bible03_start_chap = get_post_meta($post->ID, '_ct_sm_bible03_start_chap', true);
$sm_bible03_start_verse = get_post_meta($post->ID, '_ct_sm_bible03_start_verse', true);
$sm_bible03_end_chap = get_post_meta($post->ID, '_ct_sm_bible03_end_chap', true);
$sm_bible03_end_verse = get_post_meta($post->ID, '_ct_sm_bible03_end_verse', true);

$sm_bible04_book = get_post_meta($post->ID, '_ct_sm_bible04_book', true);
$sm_bible04_start_chap = get_post_meta($post->ID, '_ct_sm_bible04_start_chap', true);
$sm_bible04_start_verse = get_post_meta($post->ID, '_ct_sm_bible04_start_verse', true);
$sm_bible04_end_chap = get_post_meta($post->ID, '_ct_sm_bible04_end_chap', true);
$sm_bible04_end_verse = get_post_meta($post->ID, '_ct_sm_bible04_end_verse', true);

$sm_bible05_book = get_post_meta($post->ID, '_ct_sm_bible05_book', true);
$sm_bible05_start_chap = get_post_meta($post->ID, '_ct_sm_bible05_start_chap', true);
$sm_bible05_start_verse = get_post_meta($post->ID, '_ct_sm_bible05_start_verse', true);
$sm_bible05_end_chap = get_post_meta($post->ID, '_ct_sm_bible05_end_chap', true);
$sm_bible05_end_verse = get_post_meta($post->ID, '_ct_sm_bible05_end_verse', true);

$sermon_settings = get_option('ct_sermon_settings');
isset($sermon_settings['single_layout']) ? $page_layout = $sermon_settings['single_layout'] : $page_layout = null;
isset($sermon_settings['facebook_likes']) ? $facebook_likes = $sermon_settings['facebook_likes'] : $facebook_likes = null;
isset($sermon_settings['tweet_this']) ? $tweet_this = $sermon_settings['tweet_this'] : $tweet_this = null;
isset($sermon_settings['podcast_subscribe_url']) ? $podcast_subscribe_url = $sermon_settings['podcast_subscribe_url'] : $podcast_subscribe_url = null;
isset($sermon_settings['podcast_subscribe_button_text']) ? $podcast_subscribe_button_text = $sermon_settings['podcast_subscribe_button_text'] : $podcast_subscribe_button_text = null;

if(empty($podcast_subscribe_button_text)) $podcast_subscribe_button_text = 'Subscribe to Podcast';

?>
		<div id="ribbon" class="page">
			<div class="container_12 grid-container content">
				<div class="ribbon-wrapper">
					<div class="grid_9 grid-75 alpha">
						<h1><?php the_title(); ?></h1>
					</div>
					<div class="grid_3 grid-25 omega">
						<span class="tagline"><?php echo the_time('F j, Y'); ?></span>
					</div>
				</div>
			</div>
		</div>
		<div id="wrapper3" class="container_12 grid-container">
<?php if($page_layout == 'left'): get_sidebar(); endif; ?>
			<div id="content" class="<?php if($page_layout == 'full'): echo 'grid_12 grid-100'; else: echo 'grid_8 grid-66'; endif; ?> <?php if($page_layout == 'left'): echo 'omega'; else: echo 'alpha'; endif; ?> single single-sermon">
<?php if($query->have_posts()) while($query->have_posts()): $query->the_post(); ?>
				<div class="meta">
					<?php ct_sermon_meta(); ?>
				</div>
<?php if($sm_video_embed): ?>
				<div class="video_player">
					<?php echo apply_filters( 'the_content', $sm_video_embed ) ?>
				</div>
<?php elseif(has_post_thumbnail()): ?>
				<div class="image"><?php the_post_thumbnail('single'); ?></div>
<?php endif; ?>
<?php if(!empty($sm_audio_file) && ( function_exists('insert_audio_player') || function_exists('mejs_audio_shortcode') ) ): ?>
				<div class="audio_player">
<?php if(!empty($sm_video_embed)): ?>
					<h3><?php _e('Audio', 'churchthemes'); ?></h3>
<?php endif; ?>
					<?php if ( function_exists('mejs_audio_shortcode') ) : ?>
						<?php echo do_shortcode( '[mejsaudio src="' . esc_url($sm_audio_file) . '"]' ) ?>
					<?php elseif ( function_exists('insert_audio_player') ) : ?>
						<?php insert_audio_player("[audio:". esc_url($sm_audio_file) ."]"); ?>
					<?php endif; ?>
				</div>
<?php endif; ?>
<?php if((empty($facebook_likes) || $facebook_likes == 'on') || (empty($tweet_this) || $tweet_this == 'on')): ?>
				<div class="social">
					<ul>
<?php if((empty($facebook_likes) || $facebook_likes == 'on')): ?>
						<li><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="<?php the_permalink(); ?>" layout="button_count" show_faces="false" font="lucida grande"></fb:like></li>
<?php endif; ?>
<?php if((empty($tweet_this) || $tweet_this == 'on')): ?>
						<li><a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal"><?php _e('Tweet', 'churchthemes'); ?></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></li>
<?php endif; ?>
					</ul>
				</div>
<?php endif; ?>
<?php $the_content = get_the_content(); if($the_content): ?>
				<h3><?php _e('Summary', 'churchthemes'); ?></h3>
				<?php the_content(); ?>
<?php endif; ?>
<?php if($sm_bible01_book||$sm_bible02_book||$sm_bible03_book||$sm_bible04_book||$sm_bible05_book): ?>
				<div class="bible_refs">
					<h3><?php _e('Bible References', 'churchthemes'); ?></h3>
					<ul>
						<?php
							$book = $sm_bible01_book;
							$start_chap = $sm_bible01_start_chap;
							$start_verse = $sm_bible01_start_verse;
							$end_chap = $sm_bible01_end_chap;
							$end_verse = $sm_bible01_end_verse;

							if(!empty($book)):
								echo '<li>'. $book;
							endif;

							if(!empty($start_chap)):
								echo ' '. $start_chap;
							endif;

							if(!empty($start_chap) && !empty($start_verse)):
								echo ':'. $start_verse;
							endif;

							if(!empty($end_chap) && !empty($end_verse)):
								if($start_chap == $end_chap):
									echo ' - '. $end_verse;
								else:
									echo ' - '. $end_chap .':'. $end_verse;
								endif;
							endif;

							if(empty($end_chap) && !empty($end_verse)):
								if(!empty($start_verse)):
									echo ' - '. $end_verse;
								endif;
							endif;

							if(!empty($end_chap) && empty($end_verse)):
								if(!empty($start_chap) && empty($start_verse)):
									echo ' - '. $end_chap;
								endif;
							endif;

							if(!empty($book)):
								echo '</li>';
							endif;
						?>
						<?php
							$book = $sm_bible02_book;
							$start_chap = $sm_bible02_start_chap;
							$start_verse = $sm_bible02_start_verse;
							$end_chap = $sm_bible02_end_chap;
							$end_verse = $sm_bible02_end_verse;

							if(!empty($book)):
								echo '<li>'. $book;
							endif;

							if(!empty($start_chap)):
								echo ' '. $start_chap;
							endif;

							if(!empty($start_chap) && !empty($start_verse)):
								echo ':'. $start_verse;
							endif;

							if(!empty($end_chap) && !empty($end_verse)):
								if($start_chap == $end_chap):
									echo ' - '. $end_verse;
								else:
									echo ' - '. $end_chap .':'. $end_verse;
								endif;
							endif;

							if(empty($end_chap) && !empty($end_verse)):
								if(!empty($start_verse)):
									echo ' - '. $end_verse;
								endif;
							endif;

							if(!empty($end_chap) && empty($end_verse)):
								if(!empty($start_chap) && empty($start_verse)):
									echo ' - '. $end_chap;
								endif;
							endif;

							if(!empty($book)):
								echo '</li>';
							endif;
						?>
						<?php
							$book = $sm_bible03_book;
							$start_chap = $sm_bible03_start_chap;
							$start_verse = $sm_bible03_start_verse;
							$end_chap = $sm_bible03_end_chap;
							$end_verse = $sm_bible03_end_verse;

							if(!empty($book)):
								echo '<li>'. $book;
							endif;

							if(!empty($start_chap)):
								echo ' '. $start_chap;
							endif;

							if(!empty($start_chap) && !empty($start_verse)):
								echo ':'. $start_verse;
							endif;

							if(!empty($end_chap) && !empty($end_verse)):
								if($start_chap == $end_chap):
									echo ' - '. $end_verse;
								else:
									echo ' - '. $end_chap .':'. $end_verse;
								endif;
							endif;

							if(empty($end_chap) && !empty($end_verse)):
								if(!empty($start_verse)):
									echo ' - '. $end_verse;
								endif;
							endif;

							if(!empty($end_chap) && empty($end_verse)):
								if(!empty($start_chap) && empty($start_verse)):
									echo ' - '. $end_chap;
								endif;
							endif;

							if(!empty($book)):
								echo '</li>';
							endif;
						?>
						<?php
							$book = $sm_bible04_book;
							$start_chap = $sm_bible04_start_chap;
							$start_verse = $sm_bible04_start_verse;
							$end_chap = $sm_bible04_end_chap;
							$end_verse = $sm_bible04_end_verse;

							if(!empty($book)):
								echo '<li>'. $book;
							endif;

							if(!empty($start_chap)):
								echo ' '. $start_chap;
							endif;

							if(!empty($start_chap) && !empty($start_verse)):
								echo ':'. $start_verse;
							endif;

							if(!empty($end_chap) && !empty($end_verse)):
								if($start_chap == $end_chap):
									echo ' - '. $end_verse;
								else:
									echo ' - '. $end_chap .':'. $end_verse;
								endif;
							endif;

							if(empty($end_chap) && !empty($end_verse)):
								if(!empty($start_verse)):
									echo ' - '. $end_verse;
								endif;
							endif;

							if(!empty($end_chap) && empty($end_verse)):
								if(!empty($start_chap) && empty($start_verse)):
									echo ' - '. $end_chap;
								endif;
							endif;

							if(!empty($book)):
								echo '</li>';
							endif;
						?>
						<?php
							$book = $sm_bible05_book;
							$start_chap = $sm_bible05_start_chap;
							$start_verse = $sm_bible05_start_verse;
							$end_chap = $sm_bible05_end_chap;
							$end_verse = $sm_bible05_end_verse;

							if(!empty($book)):
								echo '<li>'. $book;
							endif;

							if(!empty($start_chap)):
								echo ' '. $start_chap;
							endif;

							if(!empty($start_chap) && !empty($start_verse)):
								echo ':'. $start_verse;
							endif;

							if(!empty($end_chap) && !empty($end_verse)):
								if($start_chap == $end_chap):
									echo ' - '. $end_verse;
								else:
									echo ' - '. $end_chap .':'. $end_verse;
								endif;
							endif;

							if(empty($end_chap) && !empty($end_verse)):
								if(!empty($start_verse)):
									echo ' - '. $end_verse;
								endif;
							endif;

							if(!empty($end_chap) && empty($end_verse)):
								if(!empty($start_chap) && empty($start_verse)):
									echo ' - '. $end_chap;
								endif;
							endif;

							if(!empty($book)):
								echo '</li>';
							endif;
						?>
					</ul>
				</div>
<?php endif; ?>
<?php if($sermon_topic): ?>
				<div class="topics">
					<h3><?php _e('Topics', 'churchthemes'); ?></h3>
					<p><?php echo get_the_term_list($post->ID, 'sermon_topic', '', '&nbsp;&nbsp;&nbsp;&nbsp;'); ?></p>
				</div>
<?php endif; ?>
<?php if($podcast_subscribe_url || ($sm_audio_button_text && $sm_audio_file) || ($sm_video_button_text && $sm_video_file) || ($sm_sg_button_text && $sm_sg_file)): ?>
				<div class="action">
<?php if($podcast_subscribe_url): ?>
					<a href="<?php echo $podcast_subscribe_url; ?>" class="button" title="<?php echo $podcast_subscribe_button_text; ?>"><img src="<?php echo get_template_directory_uri(); ?>/images/icon-podcast_sub.png"><?php echo $podcast_subscribe_button_text; ?></a>
<?php endif; ?>
					<ul>
<?php if($sm_audio_button_text && $sm_audio_file): ?>
						<li><a href="<?php echo add_query_arg( array( 'ct_download' => $sm_audio_file ), get_permalink() ) ?>" class="button" title="<?php _e('Download','churchthemes'); ?> <?php echo $sm_audio_button_text; ?>"><img src="<?php echo get_template_directory_uri(); ?>/images/icon-download.png"><?php echo $sm_audio_button_text; ?></a></li>
<?php endif; ?>
<?php if($sm_video_button_text && $sm_video_file): ?>
						<li><a href="<?php echo add_query_arg( array( 'ct_download' => $sm_video_file ), get_permalink() ) ?>" class="button" title="<?php _e('Download','churchthemes'); ?> <?php echo $sm_video_button_text; ?>"><img src="<?php echo get_template_directory_uri(); ?>/images/icon-download.png"><?php echo $sm_video_button_text; ?></a></li>
<?php endif; ?>
<?php if($sm_sg_button_text && $sm_sg_file): ?>
						<li><a href="<?php echo add_query_arg( array( 'ct_download' => $sm_sg_file ), get_permalink() ) ?>" class="button" title="<?php _e('Download','churchthemes'); ?> <?php echo $sm_sg_button_text; ?>"><img src="<?php echo get_template_directory_uri(); ?>/images/icon-download.png"><?php echo $sm_sg_button_text; ?></a></li>
<?php endif; ?>
					</ul>
				</div>
<?php endif; ?>
				<div class="prev"><?php previous_post_link('%link', '' . _x('&larr;', 'Previous sermon link', 'churchthemes') . ' %title'); ?></div>
				<div class="next"><?php next_post_link('%link', '%title ' . _x('&rarr;', 'Next sermon link', 'churchthemes') . ''); ?></div>
				<div class="clear"></div>

				<?php edit_post_link( __('Edit this sermon', 'churchthemes'), '<div class="edit-post">', '</div>'); ?>

				<?php comments_template('', true); ?>

<?php endwhile; // end of the loop. ?>
			</div>
<?php if($page_layout == 'right' || empty($page_layout)): get_sidebar(); endif; ?>
		</div>
<?php get_footer(); ?>