<?php get_header(); global $gp; ?>

<?php if (have_posts()) : while (have_posts()) : the_post();

	// Portfolio Column Classes			
	if ( $GLOBALS['gp_type'] == 'left-image' OR $GLOBALS['gp_type'] == 'left-slider' ) {
		$portfolio_class_1 = 'portfolio-left-col';
		$portfolio_class_2 = 'portfolio-right-col';
	} else {
		$portfolio_class_1 = 'portfolio-full-col';
		$portfolio_class_2 = '';			
	} 

 ?>		
 
	<?php gp_page_header( get_the_ID() ); ?>

	<div id="content-wrapper"<?php if ( $GLOBALS['gp_layout'] != 'gp-fullwidth' ) { ?> class="gp-container"<?php } ?>>
						
		<div id="content">

			<article <?php post_class( 'post-content' ); ?>>

				<div class="entry-content portfolio-row">
		
					<?php if ( $GLOBALS['gp_type'] != 'none' ) { ?>

						<?php $image = aq_resize( wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) ), $GLOBALS['gp_image_width'], $GLOBALS['gp_image_height'], $GLOBALS['gp_hard_crop'], false, true ); ?>
						<?php if ( $gp['retina'] == 'gp-retina' ) {
							$retina = aq_resize( wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) ),  $GLOBALS['gp_image_width'] * 2, $GLOBALS['gp_image_height'] * 2, $GLOBALS['gp_hard_crop'], true, true );
						} else {
							$retina = '';
						} ?>

						<?php if ( $GLOBALS['gp_type'] == 'left-slider' OR $GLOBALS['gp_type'] == 'fullwidth-slider' ) {

							// Gallery Image IDs
							$gp_image_ids = array_filter( explode( ',', $gp['portfolio_item_gallery_slider'] ) );

							?>

							<div class="<?php echo sanitize_html_class( $portfolio_class_1 ); ?>">

								<div class="gp-slider <?php echo sanitize_html_class( $GLOBALS['gp_type'] ); ?>" style="width: <?php echo absint( $image[1] ); ?>px;"> 
									 <ul class="slides">
										<?php foreach ( $gp_image_ids as $gp_image_id ) { ?>
											<li>
												<?php $image = aq_resize( wp_get_attachment_url( $gp_image_id ), $GLOBALS['gp_image_width'], $GLOBALS['gp_image_height'], $GLOBALS['gp_hard_crop'], false, true ); ?>
												<?php if ( $gp['retina'] == 'gp-retina' ) {
													$retina = aq_resize(wp_get_attachment_url( $gp_image_id ),  $GLOBALS['gp_image_width'] * 2, $GLOBALS['gp_image_height'] * 2, $GLOBALS['gp_hard_crop'], true, true );
												} else {
													$retina = '';
												} ?>
												<img src="<?php echo esc_url( $image[0] ); ?>" data-rel="<?php echo esc_url( $retina ); ?>" width="<?php echo absint( $image[1] ); ?>" height="<?php echo absint( $image[2] ); ?>" 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 { the_title_attribute(); } ?>" class="wp-post-image" />			
											</li>
										<?php } ?>
									</ul>
								 </div>
	 
							 </div>

							<script>
							jQuery( window ).load( function() {
								'use strict';
								jQuery( '.post-<?php the_ID(); ?> .gp-slider' ).flexslider({ 
									animation: 'fade',
									slideshowSpeed: 9999999,
									animationSpeed: 600,
									directionNav: true,			
									controlNav: false,			
									pauseOnAction: true, 
									pauseOnHover: false,
									prevText: '',
									nextText: '',
									smoothHeight: true
								});

							});
							</script>

						<?php } else { ?>

							<div class="<?php echo sanitize_html_class( $portfolio_class_1 ); ?>">
						
								<img src="<?php echo esc_url( $image[0] ); ?>" data-rel="<?php echo esc_url( $retina ); ?>" width="<?php echo absint( $image[1] ); ?>" height="<?php echo absint( $image[2] ); ?>" 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 { the_title_attribute(); } ?>" class="wp-post-image" />

							</div>
						
						<?php } ?>
			
					<?php } ?>

					<div class="<?php echo sanitize_html_class( $portfolio_class_2 ); ?>">

						<?php the_content(); ?>

					</div>
					
				</div><!-- END ENTRY CONTENT -->
							
				<?php wp_link_pages( 'before=<ul class="page-numbers single-nav">&pagelink=<span class="page-numbers">%</span>&after=</ul>' ); ?>
			
				<?php if ( $gp['portfolio_item_related_items'] == 'enabled' ) { ?>
					<?php get_template_part( 'lib/sections/related', 'items' ); ?>
				<?php } ?>
				
				<?php comments_template(); ?>

			</article>		

		</div><!-- END CONTENT -->

		<?php get_sidebar(); ?>

	</div><!-- END CONTENT WRAPPER -->

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