<?php get_header(); ?>
    <!-- Single -->
	<?php 
	    // Single 
	    if (have_posts()):
		while (have_posts()): the_post(); 
		    global $post;
		    $minus = strtotime(get_post_meta($post->ID, '_tevent', true));
	        $tevent = get_post_meta($post->ID, '_tevent', true);
	        $jam = get_post_meta($post->ID, '_jam', true);
		    $lokasi = get_post_meta($post->ID, '_lokasi', true);
		    $roomaps = get_post_meta($post->ID, '_roomaps', true);
		    $dday = strtotime(date_i18n('d-m-Y H:i'));
			$end = get_post_meta($post->ID, '_tevent', true).' '.get_post_meta($post->ID, '_jam', true);
			$exp = strtotime(date_i18n($end));
			$sisa = $exp-$dday;
		?>
		
		<div class="press_page">
	    	<div class="bread_in">
	            <?php // Top before content
		        	the_title( '<h1 class="press_heading">', '</h1>' ); 
		        	dimox_breadcrumbs(); 
	        	?>
        	</div>
    	</div>
		
		<section class="press_singlepost">
	        <div class="press_container">
			
			    <div class="press_singlecontent clear">
				
				    <div class="press_primary">
					    <div class="primary_content">
						    
							<div class="event_box clear">
						    	<div class="left_box">
						        	<div class="press_eventdate"><?php echo esc_html(date_i18n('d', strtotime($tevent))); ?></div>
				                    <div class="press_eventmonth"><?php echo esc_html(date_i18n('M Y', strtotime($tevent))); ?></div>
						    	</div>
								<div class="right_box">
								    <div><?php printf(__('Hari : %1s , Jam : %2s', 'prestasi'), date_i18n('l', strtotime($tevent)), esc_html($jam) ); ?> </div>
									<?php if ( $sisa < 0 ) { ?>
									<h3 class="event_expired"><?php echo __( 'Acara Ini Sudah Lewat', 'prestasi' ); ?></h3>
									<?php } else { ?>
									<h3 class="event_active">
									    <?php echo __( 'Menuju Acara : ', 'prestasi' ); ?><span id="event">
										    <span class="event_day"></span> <?php echo __( 'Hari + ', 'prestasi' ); ?>
											<span class="event_hour"></span> : <span class="event_minutes"></span> : <span class="event_seconds"></span>
										</span>
									</h3>
									<?php } ?>
									<div><strong><?php echo __( 'Lokasi : ', 'prestasi' ); ?></strong><?php echo esc_html($lokasi); ?></div>
								</div>
							</div>
							
							<div class="event_maps"><?php echo $roomaps; ?></div>
							
							<?php if (has_post_thumbnail()) {
					            echo '<div class="content_thumbnail">'.get_the_post_thumbnail($post->ID, 'full',
    				                array(
				    	                'alt' => trim(strip_tags($post->post_title)),
				    	                'title' => trim(strip_tags($post->post_title)),
			    	                )).'</div>'; 
							} ?>
							
							<div class="press_article">
							    <?php the_content(); ?>
							</div>
							
						</div>
					</div>
					
					<div class="press_secondary">
					
						<div class="secondary_content">
						
							<?php 
								post_another_agendas(); 
							?>
							
						</div>
						
			        </div>
					
				</div>
				
			</div>
		</section>
		
		<script>

						function getTimeRemaining(endtime){
  						    var t = Date.parse(endtime) - Date.parse(new Date());
  					    	var seconds = Math.floor( (t/1000) % 60 );
  					    	var minutes = Math.floor( (t/1000/60) % 60 );
  					    	var hours = Math.floor( (t/(1000*60*60)) % 24 );
  					    	var days = Math.floor( t/(1000*60*60*24) );
  					    	return {
  						        'total': t,
  						        'days': days,
  						        'hours': hours,
  						        'minutes': minutes,
  						        'seconds': seconds
 						    };
						}

						function initializeClock(id, endtime){
  					    	var clock = document.getElementById(id);
  					    	var daysSpan = clock.querySelector('.event_day');
  					    	var hoursSpan = clock.querySelector('.event_hour');
  					    	var minutesSpan = clock.querySelector('.event_minutes');
  					    	var secondsSpan = clock.querySelector('.event_seconds');

  						function updateClock(){
   						    var t = getTimeRemaining(endtime);

    						daysSpan.innerHTML = t.days;
    						hoursSpan.innerHTML = ('0' + t.hours).slice(-2);
    						minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
    						secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);

    						if(t.total<=0){
     						    clearInterval(timeinterval);
    						}
  						}

  						updateClock();
  						var timeinterval = setInterval(updateClock,1000);
						}

						var deadline = <?php echo "'"; echo esc_html(date("F j Y", strtotime($tevent))); ?> <?php echo esc_html($jam); ?> UTC+0700';
						initializeClock('event', deadline);

						</script>
		
		<?php 
		endwhile; 
	    endif; 
	?>
	
<?php get_footer(); ?>