<?php
if ( ! evrst_is_ajax() ) {
	include(TEMPLATEPATH. '/index.php');
	exit();
}


while(have_posts()):the_post();
?>

<div class="genre">
<?php
function get_genre_name($n){
	return $n->name;
}

$genres = array();

$all_genres = array_map("get_genre_name", get_terms('genre', array('hide_empty' => false)));
$album_genres = get_the_terms($post->ID, 'genre');
if ( is_array( $album_genres ) ) {
	$album_genres = array_map("get_genre_name", $album_genres );
} else {
	$album_genres = [];
}


	$counter = 0;
	foreach($all_genres as $genre){
		if(in_array($genre, $album_genres)){
			$counter++;
			echo ($counter > 1)
				? "&nbsp;|&nbsp;"
				: '';
	?>
	<a href="#" class="in-genre"><?php echo $genre;?></a>
	<?php
}
	}
?>
</div>
<?php
$src_cover     = wp_get_attachment_image_src( get_post_meta( get_the_ID(), 'evrst_cover', true), 'full' );
$src_tracklist = wp_get_attachment_image_src( get_post_meta( get_the_ID(), 'evrst_tracklist', true), 'full' );
//$link_itunes = get_post_meta(get_the_ID(), 'evrst_itunes_link', true);
$link_linkfire = get_post_meta(get_the_ID(), 'evrst_linkfire_link', true);
$link_spotify  = get_post_meta(get_the_ID(), 'evrst_spotify_link', true);
//$link_amazon = get_post_meta(get_the_ID(), 'evrst_amazon_link', true);
?>
<?php if ( $src_tracklist ) { ?>
	<input type="radio" name="overlay_show" id="overlay_show_cover" value="cover" checked />
	<input type="radio" name="overlay_show" id="overlay_show_tracklist" value="tracklist" />
<?php } ?>
<div class="covers">
<img src="<?php echo $src_cover[0]; ?>" id="cover" alt="Album Cover"/>
<?php if ( $src_tracklist ) { ?>
	<img src="<?php echo $src_tracklist[0]; ?>" id="tracklist" alt="Track List"/>
<?php } ?>
</div>
<?php if ( $src_tracklist ) { ?>
	<div class="overlay-show-cover">
		<label for="overlay_show_cover"><?php
			echo wp_get_attachment_image( get_post_meta( get_the_ID(), 'evrst_cover', true), 'thumbnail' );
		?></label>
		<label for="overlay_show_tracklist"><?php
			echo wp_get_attachment_image( get_post_meta( get_the_ID(), 'evrst_tracklist', true), 'thumbnail' );
		?></label>
	</div>
<?php } ?>

<h1><?php the_title();?></h1>
<div class="subline">
  <h2><?php echo get_post_meta(get_the_ID(), 'evrst_catalog_number', true); ?></h2>
    <div class="dist"></div>
  <?php if($link_linkfire): ?><a href="<?php echo $link_linkfire; ?>" id="linkfire-link" target="_blank"><img src="https://www.alshire.com/wp-content/uploads/listen-here.png" id="linkfire" height="39" alt="Linkfire"/></a><?php endif; ?>
  <?php if($link_spotify): ?><a href="<?php echo $link_spotify; ?>" id="spotify-link" target="_blank"><img src="https://www.alshire.com/wp-content/uploads/spotify.png" height="39" id="spotify"  alt="Spotify"/></a><?php endif; ?>
  <?php /*if($link_itunes && false): ?><a href="<?php echo $link_itunes; ?>" target="_blank"><img src="<?php echo get_bloginfo('template_directory')?>/img/itunes.png" width="108" height="39" id="itunes" /></a><?php endif; */?>
</div>
<div class="content">
	<?php the_content();?>
</div>
<?php
$related_posts = MRP_get_related_posts(get_the_ID(), true, true, 'post');

if($related_posts && !empty($related_posts)):
?>
<h2 class="white">Blog</h2>
<?php
foreach($related_posts as $related_post):?>
		<h3><?php echo $related_post->post_title;?></h3>
		<?php echo wpautop(wp_trim_words($related_post->post_content, 10)); ?>
		<a href="<?php echo get_permalink($related_post->ID)?>" class="more-link"><img src="<?php echo get_bloginfo('template_directory')?>/img/more.png" width="77" height="18" class="more" alt="more"/></a>
	<?php endforeach; ?>
<?php endif; ?>
<?php endwhile; ?>
