<?php
/*
Template Name: Portfolio
*/
?>

<div class="row portfolio-list bottom">

<?php
global $theme_options;

$temp = $wp_query;
$wp_query = null;

$data_item = 0;

$wp_query = new WP_Query(array(
  'post_type' => 'portfolio',
  'orderby'=> 'menu_order'
));

$page_slug = get_site_url().'/#'.$post->post_name;

while ($wp_query->have_posts()) : $wp_query->the_post();
  
  $data_item++;
  
  $portfolio_small = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'portfolio-small' );
  $portfolio_large = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'portfolio-large' );
  $portfolio_brand = get_post_meta( $post->ID, '_portfolio_brand_value', true );
  $portfolio_brand_url = get_post_meta( $post->ID, '_portfolio_brand_url_value', true );
  $portfolio_url = get_post_meta( $post->ID, '_portfolio_url_value', true );

  $terms = get_the_terms( $post->ID , 'portfolio_filter' );

  $terms_count = count($terms);

  $terms_counter = 0;

  $categories_html = '';
  
  foreach ( $terms ? $terms : array() as $term ) {

    if($terms_counter  < $terms_count - 1) {
      $categories_html.= $term->name.', ';
    }
    else
    {
      $categories_html .= $term->name;
    }

    $terms_counter++;
  }

  $portfolio_images = array();
  $portfolio_images = get_images_src('portfolio-large',false, $post->ID);

?>
<div class="span4 portfolio-item-block" data-item="<?php echo $data_item; ?>">
        <div class="info"><img src="<?php echo $portfolio_small[0]; ?>" alt="">
          <h4 class="title"><?php the_title(); ?></h4>
          <span class="sub-title"><?php echo $categories_html; ?></span>
          </div>
        <div class="details">
          <div class="container">
            <div class="row">
              <div class="span6">
                <div class="porftolio-slider porftolio-slider-<?php echo $post->ID; ?>">
                <ul class="slides">
                  <li><img src="<?php echo $portfolio_large[0]; ?>" alt="<?php the_title(); ?>"/></li>
                  <?php
                  
                  foreach ( $portfolio_images as $portfolio_image ) {
                    echo '<li><img src="'.$portfolio_image[0].'" alt=""/></li>';
                  }

                  ?>
                </ul>
                </div>
              </div>
              <div class="span6">
              	<div class="line"></div>
                <h1><?php the_title(); ?></h1>
                <ul class="unstyled">
                  <li><?php _e('Category', 'inspiredise'); ?>: <?php echo $categories_html; ?></li>
                  <li><?php _e('Client', 'inspiredise');?>: <a href="<?php echo $portfolio_brand_url; ?>"><?php echo $portfolio_brand; ?></a></li>
                </ul>
                <?php the_content(); ?>
                <?php if($portfolio_url <> ''): ?>
                <a href="<?php echo $portfolio_url; ?>" class="btn" target="_blank"><?php _e('View', 'inspiredise');?> <i class="fa fa-angle-right"></i></a> 
                <?php endif; ?>
                <a href="#" class="btn close-details"><?php _e('Close', 'inspiredise');?> <i class="fa fa-angle-up"></i></a>
                <?php if($theme_options['enable_portfolio_share_buttons']): ?>
                <div class="share">
                <?php _e('Share', 'inspiredise');?>: 
                  <a href="http://www.facebook.com/sharer.php?u=<?php echo $page_slug; ?>" target="_blank"><i class="fa fa-facebook"></i></a>
                  <a href="https://twitter.com/share?url=<?php echo $page_slug; ?>" target="_blank"><i class="fa fa-twitter"></i></a>
                  <a href="https://plus.google.com/share?url=<?php echo $page_slug; ?>" target="_blank"><i class="fa fa-google-plus" ></i></a>
                  <a href="http://pinterest.com/pin/create/button/?url=<?php echo $page_slug; ?>&amp;media=<?php echo $portfolio_large[0]; ?>&amp;description=" target="_blank"><i class="fa fa-pinterest"></i></a>
                </div>
                <?php endif; ?>
              </div>
            </div>
          </div>
        </div>
      </div>

<?php 
if($data_item == 3){
  $data_item = 0;
}

endwhile; // end of the loop. 
?>
         
<?php $wp_query = null; $wp_query = $temp;?>

</div>
    