<?php

$page_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$short_page_url = $_SERVER["REQUEST_URI"];
$category_id = get_cat_ID(single_cat_title('', false));
$category_link = get_category_link($category_id);

?>

<div id="content-wrapper">
	
	<?php get_sidebar(); ?>

	<div id="main-content">
		
		<!--Begin Box Controls-->
		<?php if($theme_category_page_title == "0" OR $theme_category_order_options == "0" OR $theme_category_page_nav == "Top & Bottom" OR $theme_category_page_nav == "Top") { ?>
		
			<div id="box-details">
			
				<div class="left">
				
					<?php if($theme_category_page_title == "0") { ?>
	
						<h1 class="page-title">
						<?php if(is_search()) { ?>
							<?php echo $wp_query->found_posts; ?> <?php _e('search results found for', 'gp_lang'); ?> "<?php echo esc_html($s); ?>"
						<?php } elseif(is_category()) { ?>
							<?php single_cat_title(); ?>
						<?php } elseif(is_tag()) { ?>
							<?php single_tag_title(); ?>
						<?php } elseif(is_author()) { ?>
							<?php wp_title(''); ?>'s Posts
						<?php } elseif(is_archive()) { ?>
							<?php _e('Archives', 'gp_lang') ?> <?php wp_title(' / '); ?>			
						<?php } elseif(is_home()) { ?>
							Home
						<?php } ?>
						</h1>
						
					<?php } ?>
					
				</div>
	
				<?php if($theme_category_page_nav == "Top & Bottom" OR $theme_category_page_nav == "Top") { ?>
					<div class="right">	
						<?php gp_pagination(); ?>
					</div>
				<?php } ?>
				
			</div>

		<?php } ?>
		<!--End Box Controls-->
			
		<!--Begin Box Container-->
		<div id="box-container"<?php if($theme_category_page_title == "0" OR $theme_category_order_options == "0" OR $theme_category_page_nav == "Top & Bottom" OR $theme_category_page_nav == "Top") {} else { ?> class="box-shift"<?php } ?>>
		
			<?php if (have_posts()) : while (have_posts()) : the_post();			
											
			$args = array('post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $post->ID, 'numberposts' => 1, 'orderby' => 'menu_order', 'order' => 'ASC');
			
			$attachments = get_children($args); 
			
			?>
	
				<!--Begin Box-->
				<div id="post-<?php the_ID(); ?>" <?php post_class('box'); ?>>
				
					<!--Begin Image-->					
					<?php if(has_post_thumbnail() OR $attachments) { ?>
					
						<div class="box-thumbnail" style="width: <?php echo $theme_category_image_width; ?>px; height: <?php echo $theme_category_image_height; ?>px;">
		
							<a href="<?php if(get_post_meta($post->ID, 'ghostpool_lightbox_type', true) == "Video") { ?>file=<?php echo get_post_meta($post->ID, 'ghostpool_custom_link', true); ?><?php } elseif(get_post_meta($post->ID, 'ghostpool_lightbox_type', true) == "Image") { ?><?php echo get_post_meta($post->ID, 'ghostpool_custom_link', true); ?><?php } else { ?><?php if(get_post_meta($post->ID, 'ghostpool_custom_link', true)) { ?><?php echo get_post_meta($post->ID, 'ghostpool_custom_link', true); ?><?php } else { ?><?php the_permalink(); ?><?php } ?><?php } ?>"<?php if(get_post_meta($post->ID, 'ghostpool_lightbox_type', true) == "None") {} else { ?> rel="prettyPhoto"<?php } ?>>
							
								<span class="overlay" style="width: <?php echo $theme_category_image_width; ?>px; height: <?php echo $theme_category_image_height; ?>px;"></span>
								
									<img src="<?php if($theme_timthumb == "0") { ?><?php echo get_template_directory_uri(); ?>/lib/scripts/timthumb.php?src=<?php } ?><?php if(has_post_thumbnail()) {
									
										$image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
										echo $image[0];
										
									} elseif($attachments) { 
									
										foreach ($attachments as $attachment) {
											echo wp_get_attachment_url($attachment->ID);
										}
										
									} ?><?php if($theme_timthumb == "0") { ?>&amp;h=<?php echo $theme_category_image_height; ?>&amp;w=<?php echo $theme_category_image_width; ?>&amp;zc=1&amp;a=c<?php } ?>" style="width: <?php echo $theme_category_image_width; ?>px; height: <?php echo $theme_category_image_height; ?>px;" alt="<?php the_title(); ?>" />
							
							</a>
		
						</div>
						
						<div class="clear"></div>
						
					<?php } ?>
					<!--End Image-->								
					
					<!--Begin Box Text-->			
					<div class="box-text" style="width: <?php echo $theme_category_image_width; ?>px;">
					
						<?php if($theme_category_text_display == "Full") { ?>
				
							<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
						
							<?php if($theme_category_excerpt_length == '0') {} else { ?><p><?php echo excerpt($theme_category_excerpt_length); ?></p><?php } ?>
							
							<div class="box-meta">			
								<div class="left"><?php echo time_ago(); ?></div>
								<div class="right">
									<?php printLikes(get_the_ID()); ?>
									<?php if('open' == $post->comment_status) { comments_popup_link(__('0', 'gp_lang'), __('1', 'gp_lang'), __('%', 'gp_lang'), 'box-comments', ''); } ?>
								</div>
							</div>
						
						<?php } else { ?>
						
							<div class="left"><h2><a href="<?php the_permalink(); ?>"><?php _e('Details', 'gp_lang'); ?> &rarr;</a></h2></div>
	
							<div class="right">
								<?php printLikes(get_the_ID()); ?>
								<?php if('open' == $post->comment_status) { comments_popup_link(__('0', 'gp_lang'), __('1', 'gp_lang'), __('%', 'gp_lang'), 'box-comments', ''); } ?>
							</div>
								
						<?php } ?>
						
					</div>
					<!--End Box Text-->	
		
				</div>
				<!--End Box-->
				
			<?php endwhile; ?>	
		
			<?php else : ?>	
		
				<h2 class="page-title-error"><?php _e('No items found.', 'gp_lang'); ?></h2>
				<h4 class="page-title-error"><?php _e('Try using the search form above to search for the item you are looking for.', 'gp_lang'); ?></h4>
				
			<?php endif; wp_reset_query(); ?>	
	
		</div>
		<!--End Box Container-->
		
	</div>
	
</div>

<!--Begin Bottom Box Details-->
<?php if($theme_category_page_nav == "Top & Bottom" OR $theme_category_page_nav == "Bottom") { ?>

	<div class="clear"></div>
	
	<div id="box-details-bottom">
		<?php gp_pagination(); ?>
	</div>

<?php } ?>
<!--End Bottom Box Details-->

<script>
jQuery(document).ready(function() {
	var jQuerycontainer = jQuery('#box-container');
	jQuerycontainer.masonry({
		itemSelector: '.box',
		columnWidth: <?php echo $theme_category_image_width + 42; ?>
	}); 
});
</script>