<?php 
/*
Template Name: Portfolio 1 Column
*/

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-1-column">
        
			<div class="portfolio-content"><?php the_content(); ?></div>
            
			<ul class="portfolio-1-column-list clearfix">
            	<?php
					global $post;
                    $my_query = new WP_Query( array( 'post_type' => 'portfolio', 'showposts' => 9999, 'portfolio_category' => get_post_meta($post->ID, "_page_portfolio_cat", $single = true) ) ); 
                    while ($my_query->have_posts()) : $my_query->the_post();
                    
                    $custom = get_post_custom($post->ID);
				?>
				<li class="portfolio-item clearfix">
                	<div class="portfolio-image-container">
						<?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("portfolio2"); ?>
    	                </a>
                    </div>
                    <div class="label-container">
                    	<h3><?php the_title(); ?></h3>
						<div class="description">
                            <?php echo the_excerpt(); ?>
						</div>
                        <a href="<?php echo !empty( $custom['_portfolio_link'][0] ) ? $custom['_portfolio_link'][0] : the_permalink(); ?>" class="read-more button rounded-all"><?php _e('view project &raquo;', 'unisphere'); ?></a>
                    </div>
                </li>
                <?php endwhile; ?>
            </ul>

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

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

<?php get_footer(); ?>