<?php
if($_POST['request_source'] != 'evrst_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 = array_map("get_genre_name", get_the_terms($post->ID, 'genre'));

	$counter = 0;
	foreach($all_genres as $genre){
		if(in_array($genre, $album_genres)){
			$counter++;
			if($counter > 1) {
				$sep = "&nbsp;|&nbsp;";
			}
			echo $sep;
	?>
	<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), 'medium');
	$src_tracklist = wp_get_attachment_image_src(get_post_meta(get_the_ID(), 'evrst_tracklist', true), 'medium');
	//$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);
?>
<div class="covers">
<img src="<?php echo $src_cover[0]; ?>" id="cover" alt="Album Cover"/>
<img src="<?php echo $src_tracklist[0]; ?>" id="tracklist" alt="Track List"/>
</div>
<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; ?>
