<?php 
/*
Template Name: Portfolio 3 Columns
*/

get_header(); ?>

	<?php
	 // Get the sub-header from sub-header.php
	 get_template_part( 'sub-header' );
	?>

	<!--BEGIN #container-->
	<div id="container">

		<?php
		 // Get the sub-header footer from sub-header_footer.php
		 get_template_part( 'sub-header_footer' );
		?>

		<!--BEGIN #content-->
		<div id="content" class="portfolio-page-3-columns">
        
			<span class="portfolio-browse"><?php _e( 'browse:', 'unisphere' ); ?></span>

			<ul class="portfolio-filters">
				<li class="all"><a class="button rounded-all" href="#"><?php _e( 'All', 'unisphere' ); ?></a></li>
                <?php
				//list terms in the portfolio_category taxonomy
				$tax_terms = get_terms( 'portfolio_category' );
				
				foreach ($tax_terms as $tax_term) {
				echo '<li class="' . $tax_term->slug . '">' . '<a class="button-unselected rounded-all" href="#">' . $tax_term->name . '</a></li>';
				} ?>
			</ul>

			<div class="clearfix"></div>

			<ul class="portfolio-3-columns-list clearfix">
				<?php
                    $my_query = new WP_Query( array( 'post_type' => 'portfolio', 'showposts' => 9999 ) ); 
                    while ($my_query->have_posts()) : $my_query->the_post();
                    
                    $custom = get_post_custom($post->ID);
					
					// Get the portfolio item category (if has more than one use the first)
					$cat = wp_get_object_terms($post->ID, 'portfolio_category');
					
					// If no category was assigned, don't show the item
					if ( $cat ) :
						$cat = $cat[0];
				?>
                    <li class="portfolio-item" data-type="<?php echo $cat->slug; ?>" data-id="<?php echo $cat->slug . '-' . $post->ID; ?>">
                        <?php // Lightbox Video takes precedence before the portfolio link
							if( !empty ( $custom['_portfolio_video'][0] ) ) : // Check if there's a video to be displayed in the lightbox when clicking the thumb ?>
                            <a href="<?php echo $custom['_portfolio_video'][0]; ?>" title="<?php the_title(); ?>" rel="lightbox[portfolio]">
                    	<?php elseif( $custom['_portfolio_link'][0] != '' ) : // User has set a custom destination link for this portfolio item ?>
                    		<a href="<?php echo $custom['_portfolio_link'][0]; ?>" title="<?php the_title(); ?>">
                    	<?php elseif( $custom['_portfolio_no_lightbox'][0] == '1' ) : // User has selected to link the thumb directly to the portfolio item detail page or the custom url ?>
                    		<a href="<?php echo the_permalink(); ?>" title="<?php the_title(); ?>">
                        <?php else : // just open the full image in the lightbox ?>
                            <a href="<?php $full_image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full', false); echo $full_image[0]; ?>" title="<?php the_title(); ?>" rel="lightbox[portfolio]">
                        <?php endif; ?>
                        <?php echo unisphere_get_post_image("portfolio1"); ?>
                        </a>                            
						<div class="label-container">
							<span class="label"><?php the_title(); ?></span>
							<a href="<?php echo !empty( $custom['_portfolio_link'][0] ) ? $custom['_portfolio_link'][0] : the_permalink(); ?>" class="read-more"><?php _e('view project &raquo;', 'unisphere'); ?></a>
						</div>
                    </li>
                	<?php endif; ?> 
                <?php endwhile; ?>
            </ul>

		<!--END #content-->
		</div>

	<!--END #container-->
	</div>

<?php get_footer(); ?>