<?php get_header(); ?>

<?php 
// Load saved values in Hermes Theme Options
$hermes_options = hermes_get_global_options(); 
?>

<?php 
while (have_posts()) : the_post();

$post_meta = get_post_custom($post->ID);
$display_featured = $post_meta['hermes_post_display_featured'][0];
$display_slideshow = $post_meta['hermes_post_display_slideshow'][0];
$slideshow_autoplay = $post_meta['hermes_post_display_slideshow_autoplay'][0];
$slideshow_speed = $post_meta['hermes_post_display_slideshow_speed'][0];
if (!$slideshow_speed) {
	$slideshow_speed = 4000;
}

$event_start_day = $post_meta['_start_day'][0];
$event_start_month = $post_meta['_start_month'][0];
$event_start_year = $post_meta['_start_year'][0];
$event_end_day = $post_meta['_end_day'][0];
$event_end_month = $post_meta['_end_month'][0];
$event_end_year = $post_meta['_end_year'][0];
$event_start_hour = $post_meta['_start_hour'][0];
$event_start_minute = $post_meta['_start_minute'][0];
$event_end_hour = $post_meta['_end_hour'][0];
$event_end_minute = $post_meta['_end_minute'][0];

$metaDateStart = "$event_start_day/$event_start_month/$event_start_year";
$metaDateEnd = "$event_end_day/$event_end_month/$event_end_year";
if ($event_start_hour != '00' && $event_start_minute != '00') {
	$metaTimeStart = "$event_start_hour:$event_start_minute";
}
$metaTimeEnd = "$event_end_hour:$event_end_minute";
$isoDateStart = "$event_start_year-$event_start_month-$event_start_day";
$isoDateEnd = "$event_end_year-$event_end_month-$event_end_day";

if ($metaDateEnd && ($metaDateEnd != $metaDateStart)) {
	$metaDate = "$metaDateStart - $metaDateEnd";
}
else {
	$metaDate = "$metaDateStart";
}

$day_start = date("j", mktime(0,0,0,$event_start_month, $event_start_day, $event_start_year));
$month_start = date("F", mktime(0,0,0,$event_start_month, $event_start_day, $event_start_year));
$year_start = date("Y", mktime(0,0,0,$event_start_month, $event_start_day, $event_start_year));
$day_end = date("j", mktime(0,0,0,$event_end_month, $event_end_day, $event_end_year));
$month_end = date("F", mktime(0,0,0,$event_end_month, $event_end_day, $event_end_year));
$year_end = date("Y", mktime(0,0,0,$event_end_month, $event_end_day, $event_end_year));

if (($day_start == $day_end) && ($month_start == $month_end)) {
	$same_day = true;
}

if ($same_day && ($event_start_hour == $event_end_hour) && ($event_start_minute == $event_end_minute)) {
	$same_time = true;
}
endwhile;
?>

<div id="content"<?php if ($display_featured == 'No' || !$display_featured) { echo ' class="no-slideshow"'; } ?>> 
	
	<?php 
	if ($display_featured == 'Yes') {
	
		get_template_part('slideshow');
	
	}
	?>
	
	<div class="wrapper">
		
		<div id="main" class="hermes-column wide">
			
			<?php while (have_posts()) : the_post(); ?>
			
			<div class="post-meta">
				<h1 class="title-l"><?php the_title(); ?></h1>
				<p class="postmeta"><span class="meta-date">
					<span class="value value-date"><?php echo $day_start; ?></span>
					<span class="value value-month"><?php echo $month_start; ?></span>
					<span class="value value-year"><?php echo $year_start; ?></span>
					
					<?php if ($same_day == false && $same_time == false) { ?>
					<?php _e('at', 'hermes_textdomain');?> <span class="value value-time"><?php echo "$event_start_hour:$event_start_minute"; ?></span>
					<?php } ?>

					<?php if ($same_day == false) { ?>
					<span class="value value-date"> &mdash; <?php echo $day_end; ?></span>
					<span class="value value-month"><?php echo $month_end; ?></span>
					<span class="value value-year"><?php echo $year_end; ?></span>

					<?php if ($same_time == false) { ?>
					<?php _e('at', 'hermes_textdomain');?> <span class="value value-time"><?php echo "$event_end_hour:$event_end_minute"; ?></span>
					<?php } ?>

					<?php } // if same day == false ?>

					<?php if ($same_day == true && $same_time == false) { ?>
					<?php _e('at', 'hermes_textdomain');?> <span class="value value-time"><?php echo "$event_start_hour:$event_start_minute - $event_end_hour:$event_end_minute"; ?></span>
					<?php } // if same day == true and same time == false ?>

				</span></p>
				<?php edit_post_link( __('Edit post', 'hermes_textdomain'), '<p class="postmeta">', '</p>'); ?>
				<div class="divider">&nbsp;</div>
			</div><!-- end .post-meta -->
			
			<div class="post-single">

				<?php the_content(); ?>
				
				<div class="cleaner">&nbsp;</div>
				
				<?php wp_link_pages(array('before' => '<p class="page-navigation"><strong>'.__('Pages', 'hermes_textdomain').':</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
				<?php the_tags( '<p class="postmeta"><strong>'.__('Tags', 'hermes_textdomain').':</strong> ', ', ', '</p>'); ?>

			</div><!-- end .post-single -->
			
			<?php endwhile; ?>

			<?php if ($hermes_options['hermes_social_sharing_posts'] == 1) { ?>
			
				<?php get_template_part('social-sharing', 'post'); ?>
			
			<?php } ?>

			<?php if ($hermes_options['hermes_post_comments'] == 1) { ?>
			
			<div id="hermes-comments">
				<?php comments_template(); ?>  
			</div><!-- end #hermes-comments -->

			<?php } ?>
			
		</div><!-- end .hermes-column.wide -->
		
		<aside class="hermes-column last">
		
			<?php
			if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?> <?php endif;
			?>

			<div class="cleaner">&nbsp;</div>
			
		</aside><!-- end .hermes-column.last -->
		
		<div class="cleaner">&nbsp;</div>

	</div><!-- end .wrapper-->

</div><!-- end #content -->
	
<?php get_footer(); ?>