<?php
	Gfxbucket::portfolio_header(get_post_meta(get_the_id()), true);
	
?>

<div class="container element element-spacing portfolio-single-description other">
	<?php the_content(); ?>
</div>

<?php
global $gfxbucket_options;

$socials = array('facebook', 'twitter', 'google-plus', 'linkedin', 'dribbble', 'behance', 'tumblr', 'instagram', 'pinterest', 'youtube', 'vimeo-square', 'github');

$any_social_active = false;

foreach( $socials as $social ) {
	if( isset($gfxbucket_options['gfxbucket-social-' . $social]) && $gfxbucket_options['gfxbucket-social-' . $social] != '' ) {
		$any_social_active = true;
		break;
	}
}
?>

<?php Gfxbucket::social_portfolio_icons(); ?>

<?php
	/* Next Post */
	$next_post = get_next_post();

	if( $next_post ) {
		$next_meta = get_post_meta( $next_post->ID );
		$next_image = wp_get_attachment_url( get_post_thumbnail_id( $next_post->ID ) );

		if( isset($next_meta['_gfxbucket_cover_image_url']) ) {
			$next_image = wp_get_attachment_url( $next_meta['_gfxbucket_cover_image_url'][0] );
		}
	}

	/* Previous Post */
	$prev_post = get_previous_post();

	if( $prev_post ) {
		$prev_meta = get_post_meta( $prev_post->ID );
		$prev_image = wp_get_attachment_url( get_post_thumbnail_id( $prev_post->ID ) );

		if( isset($prev_meta['_gfxbucket_cover_image_url']) ) {
			$prev_image = wp_get_attachment_url( $prev_meta['_gfxbucket_cover_image_url'][0] );
		}
	}
?>


<?php
	$actividad= $_GET['actividad'];
	$actividadGet = str_replace("-", "&", $actividad);
?>
<div class="container element element-spacing">
			<div class="proyectos-relacionados">
	
			

	<?php
	
	
	
	
	$the_query = new WP_Query( array(

		    'post_type'      		 => 'portfolio',
		    'nopaging'               => true,
		    'orderby'                => 'rand',
			'posts_per_page'         => 3,
			'tax_query' 			 => array(
											'tax_query2' => array(
																'taxonomy' 	=> 'portfolio_category',
																'field' 	=> 'name',
																'terms' 	=> array(
																					'Casos destacados' 		=> 'Casos destacados',
																					'actividad' => $actividadGet
																						),
																'operator' => 'AND',
																)
											 ),
				
			
				));

		if ( $the_query->have_posts() ) {
			
			?>
			<h2 class="style2">Proyectos Relacionados</h2>

			<div class="proyectos-relacionados-items">
			
			<?php
			$counter = 0;

			while ( $counter < 3 ) : $the_query->the_post(); 
				
				$image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), $image_size );

				$actividadGet = str_replace("&", "-", $actividad);

				$url = get_the_permalink().'?actividad='.$actividadGet;

				$return .= '<article class="relacionados portfolio-item '. $class . '" data-id="' . get_the_ID() . '">';
				$return .= '<a href="' . $url . '">';
					$return .= '<img src="' . $image[0] . '" alt="' . get_the_title() . '">';
					$return .= '<div class="hover">';
						$return .= '<div class="hover-content">';
							$return .= '<h5>' . get_the_title() . '</h5>';
							if( $below_title != 'none' ) {
								$return .= '<span>' . $below_title_content . '</span>';
							}
						$return .= '</div>';
					$return .= '</div>';
				$return .= '</a>';
			    $return .= '</article>';


			    $counter = $counter +1;

		    endwhile;
 
		    	wp_reset_postdata();

		
		?>
		</div>
		<?php
		}

		
			    echo $return;

	?>
	

  </div>
</div>




<div class="portfolio-nav">
	<?php if (!empty( $next_post )): ?>
		<div class="prev">
			<a href="<?php echo get_permalink( $next_post->ID ); ?>" style="background-image: url('<?php echo esc_attr( $next_image ); ?>');"><span><?php _e( 'Next Project', 'dropout' ); ?></span></a>
		</div>
	<?php endif; ?>

	<?php if (!empty( $prev_post )): ?>
		<div class="next<?php if (empty( $next_post )) { echo ' col-md-offset-6'; } ?>">
			<a href="<?php echo get_permalink( $prev_post->ID ); ?>" style="background-image: url('<?php echo esc_attr( $prev_image ); ?>');"><span><?php _e( 'Previous Project', 'dropout' ); ?></span></a>
		</div>
	<?php endif; ?>
</div>



