<?php
/**
 * This file is used for your portfolio post media and entries.
 * @package Ultra WordPress Theme
 * @since 1.0
 * @author AJ Clarke : http://wpexplorer.com
 * @copyright Copyright (c) 2012, AJ Clarke
 * @link http://wpexplorer.com
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */


/******************************************************
* Portfolio Single Posts
* @since 1.0
*****************************************************/
if ( is_singular('portfolio') ) { ?>

            
    <div id="portfolio-post-media">
        <?php
        /*** Alternative style ***/
        if( get_post_meta( get_the_ID(), 'wpex_portfolio_post_media_alternative', true ) !== '' ){ 
        	echo '<div id="portfolio-post-media-alternative" class="fitvids">'. do_shortcode( htmlspecialchars_decode( get_post_meta( get_the_ID(), 'wpex_portfolio_post_media_alternative', true ) ) ) .'</div>';
        }
		
        /*** Video Style ***/
        elseif( get_post_meta( get_the_ID(), 'wpex_portfolio_post_video', true ) !== '' ){
              echo '<div id="portfolio-post-video" class="fitvids">'. wp_oembed_get( get_post_meta( get_the_ID(), 'wpex_portfolio_post_video', true ) ) .'</div>';
        }
		        
        /*** Flex Slider Style ***/
        elseif( get_post_meta( get_the_ID(), 'wpex_portfolio_post_slider', true ) == 'yes' ) {
        wp_enqueue_script('portfolio-flexslider');
               
        // Get image attachments
        $wpex_portfolio_imgs = get_posts(
            array(
                'orderby' => 'menu_order',
                'order' => 'ASC',
                'post_type' => 'attachment',
                'post_parent' => get_the_ID(),
                'post_mime_type' => 'image',
                'post_status' => null,
                'posts_per_page' => -1
            )
        ); ?>
        <div id="portfolio-post-slider" class="flexslider-container flex-loading">
                <div class="flexslider">
                    <ul class="slides">
                    <?php foreach ( $wpex_portfolio_imgs as $wpex_portfolio_img ) : ?>
                        <li class="slide">
                            <?php if( get_post_meta( get_the_ID(), 'wpex_post_layout', true) !== 'Full Width' ) { ?>
                                <img src="<?php echo aq_resize( wp_get_attachment_url( $wpex_portfolio_img->ID ),  wpex_img( 'port_post_width' ), wpex_img( 'port_post_height' ), wpex_img( 'port_post_crop' ) ); ?>" alt="<?php echo the_title(); ?>" />
                            <?php } else { ?>
                                <img src="<?php echo aq_resize( wp_get_attachment_url( $wpex_portfolio_img->ID ),  wpex_img( 'port_post_full_width' ), wpex_img( 'port_post_full_height' ), wpex_img( 'port_post_full_crop' ) ); ?>" alt="<?php echo the_title(); ?>" />
                            <?php } ?>
                        </li>
                    <?php endforeach; wp_reset_postdata(); ?>
                    </ul><!-- .slides -->
                </div><!-- .flexslider -->
            </div><!-- .flexslider-container -->
    
        <?php }
		
		/*** Featured Image Style ***/
		else {
			if( has_post_thumbnail() ) { ?>
				<div id="portfolio-post-thumbnail">
					<?php if( get_post_meta( get_the_ID(), 'wpex_post_layout', true) !== 'Full Width' ) { ?>
						<img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ),  wpex_img( 'port_post_width' ), wpex_img( 'port_post_height' ), wpex_img( 'port_post_crop' ) ); ?>" alt="<?php echo the_title(); ?>" />
					<?php } else { ?>
						<img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ),  wpex_img( 'port_post_full_width' ), wpex_img( 'port_post_full_height' ), wpex_img( 'port_post_full_crop' ) ); ?>" alt="<?php echo the_title(); ?>" />
					<?php } ?>
				</div><!-- #portfolio-post-thumbnail -->
			<?php }

        } ?>
    </div><!-- #portfolio-post-media -->
	
    
<?php } // end is_singular('portfolio') && is_main_query() check

else {
	

/******************************************************
 * Portfolio Entries
 * @since 1.0
 *****************************************************/
	
	/**
	* Set a few variables
	* @since 1.0
	*/
	
	// Globals
	global $wpex_portfolio_count;
	
	// Columns
	$wpex_grid_class = of_get_option('portfolio_archive_columns','3'); ?> 
   
	<article class="portfolio-entry clearfix grid-<?php echo $wpex_grid_class; if ( $wpex_portfolio_count == $wpex_grid_class ) echo ' remove-margin'; ?>">
    	<?php
		// Display post thumbnail
		if( has_post_thumbnail() ) { ?>
            <div class="portfolio-entry-media">
                <a href="<?php echo wpex_portfolio_url( get_the_ID(), $lightbox_only = false ); ?>" title="<?php the_title(); ?>" class="portfolio-entry-img <?php if( get_post_meta(get_the_ID(), 'wpex_portfolio_post_style', true ) == 'Lightbox' ) echo 'fancybox-media '; if (  of_get_option('portfolio_entry_hover' ) == 'opacity' ) echo 'opacity-hover '; ?>">
                	<img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ), wpex_img( 'port_entry_width' ), wpex_img( 'port_entry_height' ), wpex_img( 'port_entry_crop' ) ); ?>" alt="<?php the_title(); ?>" />
                    <?php if ( of_get_option('portfolio_entry_hover' ) == 'icon_overlay' ) { ?>
                	<div class="portfolio-entry-overlay">
                    	<div class="portfolio-entry-overlay-inner">
                        	<div class="overlay-icon"><span class="icon-<?php echo wpex_portfolio_icon( get_the_ID(), false ); ?>"></span></div>
                    	</div><!-- .portfolio-entry-overlay-inner -->
                	</div><!-- .portfolio-entry-overlay -->
                	<?php } ?>
                </a><!-- .portfolio-entry-img -->      
            </div><!-- .portfolio-entry-media -->
        <?php } //end has_post_thumbnail() check ?>
        
        <?php
        // Show defails if either the title or excerpt are enabled
		if ( of_get_option('portfolio_entry_title','1' ) == '1' || of_get_option('portfolio_entry_excerpt','1' ) == '1' ) { ?>
            <div class="portfolio-entry-details">
            
                <?php
                // Show title if enabled
                if ( of_get_option('portfolio_entry_title','1' ) == '1' ) { ?>
                    <div class="portfolio-entry-title">
                        <h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
                    </div><!-- .portfolio-entry-title -->
                <?php } ?>
                
                <?php
                // Show excerpt if enabled
                if ( of_get_option('portfolio_entry_excerpt','1' ) == '1' ) { ?>
                    <div class="portfolio-entry-excerpt">
                        <?php
                        // Display trimmed content if excerpt is blank
                        echo ( !empty( $post->post_excerpt ) ) ? apply_filters('the_content', get_the_excerpt()) : wp_trim_words( strip_shortcodes( get_the_content() ), of_get_option('portfolio_entry_excerpt_length','20') ); ?>
                        <?php
                        // Display read more link if enabled
                        if ( of_get_option('portfolio_entry_readmore' ) == '1'
                            && get_post_meta(get_the_ID(), 'wpex_portfolio_post_style', true ) !== 'Lightbox' ) { ?>
                            <br />
                            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="portfolio-entry-readmore"><?php _e('read more','wpex'); ?> &rarr;</a>
                        <?php } ?>
                    </div><!-- .portfolio-entry-excerpt -->
                <?php } ?>
                
            </div><!-- .portfolio-entry-details -->
        <?php } ?>
        
	</article><!-- .portfolio-entry -->
<?php
if ( $wpex_portfolio_count == $wpex_grid_class ) {
	echo '<div class="clear"></div>'; // Clear Floats
	$wpex_portfolio_count=0; // Reset post counter
}
$wpex_grid_class = NULL; // Nullify var
}