<?php

global $gp_settings, $wp_query;
$tags = wp_get_post_tags($post->ID);
$tempQuery = $wp_query;

// Posts Per Page
if($gp_settings['layout'] == "fullwidth") {
	$posts_per_page = 6;
} else {
	$posts_per_page = 4;
}

// Category IDs
if($gp_settings['post_type'] == "Review") {
	$related_items_cats = $theme_review_related_cats;
} else {
	$related_items_cats = $theme_post_related_cats;
}

if($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$newQuery=array(
'post_type' => 'post',
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'posts_per_page' => $posts_per_page,
'cat' => $related_items_cats,
'caller_get_posts' => 1);

query_posts($newQuery); if (have_posts()) : ?>

<!--Begin Related Items-->
<div id="related-items">
				
	<h3><?php _e('Related Items', 'gp_lang'); ?></h3>	
	
	<div>
		
	<?php while (have_posts()) : the_post(); 

	if($gp_settings['post_type'] == "Review") {
		$image_width = $theme_review_related_image_width;
		$image_height = $theme_review_related_image_height;
	} else {
		$image_width = $theme_post_related_image_width;
		$image_height = $theme_post_related_image_height;
	}
	
	?>
		
		<div class="related-item">			

			<!--Begin Image-->
			<?php if(has_post_thumbnail()) { ?>
				<div class="post-thumbnail">
					<?php if($gp_settings['post_type'] == "Video") { ?><span class="video-icon"></span><?php } ?>
					<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
						<?php $image = vt_resize(get_post_thumbnail_id(), '', $image_width, $image_height, true); ?>
						<img src="<?php echo $image[url]; ?>" alt="<?php if(get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true)) { echo get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true); } else { echo get_the_title(); } ?>" />		
					</a>				
				</div><div class="clear"></div>
			<?php } ?>
			<!--End Image-->	
		
			<a href="<?php the_permalink(); ?>" class="related-post-title" title="<?php the_title(); ?>"><?php the_title(); ?></a>
			
			<div class="related-post-cats"><?php the_category(', '); ?></div>
				
		</div>
		
	<?php endwhile; ?>
	
	</div>

</div>
<!--End Related Items-->

<?php endif; } wp_reset_query(); ?>