<?php
	global $ainex;
	switch ($ainex['portfolio_style']) {
		case '2':
			$class_width = 'one_half';
			$columns	 = 2;
		break;

		case '3':
			$class_width = 'one_third';
			$columns	 = 3;
		break;

		default:
			$class_width = 'one_fourth';
			$columns	 = 4;
		break;
	}
	$dem = 1;
	if ( have_posts() ) : while ( have_posts() ) : the_post();
		$post_id  = (int)get_post_thumbnail_id( );
		$port_img = wp_get_attachment_image_src( $post_id, 'large' )[0];
		$type 	  = get_post_meta( $post->ID, "ainex_portfolio_type", true );
		switch ($type) {
			case 'image':
				$port_link  = get_post_meta( $post->ID, "ainex_portfolio_image", true );
				$clas_audio = '';
			break;

			case 'slider':
				$clas_audio = '';
				$port_link  = $port_img;
			break;

			case 'video':
				$port_link  = get_post_meta( $post->ID, "ainex_portfolio_video", true );
				$clas_audio = '';
			break;
			case 'soundcloud':
				$link_audio = get_post_meta( $post->ID, "ainex_portfolio_soundcloud", true );
				$clas_audio = ' fancybox.iframe';
				$port_link  = 'http://w.soundcloud.com/player/?url='. $link_audio .'&show_artwork=true';
			break;
			default:
				$port_link  = $port_img;
				$clas_audio = '';
			break;
		}

	?>

		<div class="<?php echo $class_width; ?> <?php if($dem%$columns==0){ echo 'last'; } ?>">
        	<div class="portfolio_image">
	            <i class="icon-search icon-2x"></i>
	            <a class="fancybox fancybox-media<?php echo $clas_audio; ?>" href="<?php echo $port_link; ?>" data-fancybox-group="gallery" title="<?php the_title( ); ?>">
	            	<img src="<?php echo $port_img; ?>" alt="" />
	            </a>
	            <div class="title"><a href="<?php the_permalink(); ?>"><?php the_title( ); ?></a></div>
            </div>
        </div><!-- end section -->
        <?php if ($dem%$columns==0): ?>
        	<div class="clearfix"></div>
			<div class="mar_top5"></div>
        <?php endif ?>
<?php
	$dem++;
	endwhile;
	else :

		/**
		 * Display no posts message if none are found.
		 */
		get_template_part('loop/content','none');

	endif;