<?php get_header();
get_template_part('portfolio_header'); 
	//global $paged;
 	$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 
	
	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
	if ( get_query_var('paged') ) {
		$paged = get_query_var('paged');
	} elseif ( get_query_var('page') ) {
		$paged = get_query_var('page');
	} else {
		$paged = 1;
	}
	
	$pageId = $_SESSION['Wecare_page_id'];
	if (!$pageId) $pageId = get_page_ID_by_page_template('portfolio-template-3columns.php');
	$get_meta = get_post_custom($pageId);
	$weblusive_sidebar_pos = $get_meta["_weblusive_sidebar_pos"][0];
	get_template_part( 'library/includes/page-head' ); 

	$portfolio_type = get_post_meta($pageId, "_portfolio_type", $single = false);
	$paginationEnabled = (isset($portfolio_type) && !(empty ($portfolio_type))) ? $portfolio_type[0] : 0;
	$page_template_name = get_post_meta($pageId,'_wp_page_template',true); 


	$itemsize = 'column-three';	
	$itemlayout = 'column4';	
	$colnumber = 3;
	$thumbsize = 'portfolio-3-col';
	// Check which layout was selected
	switch($page_template_name)
	{
		case 'portfolio-template-3columns.php':
			$itemsize = 'column-three';	
			$thumbsize = 'portfolio-3-col';
			$itemlayout = 'column4';
			$colnumber = 3;			
		break;
		
		case 'portfolio-template-4columns.php':
			$itemsize = 'column-four';	
			$thumbsize = 'portfolio-4-col';
			$itemlayout = 'column3';	
			$colnumber = 4;
		break;		
	}
?>
<div class="banner">
    <div class="inner-banner">
        <?php if (!weblusive_get_option('hide_titles')):?>
            <div class="note"><?php the_title(); ?></div>
       <?php endif?>
       <?php if (!weblusive_get_option('hide_breadcrumbs')):?>
            <div class="site-map">
                <?php _e('You are here:', 'Wecare');?>
                <?php if(class_exists('the_breadcrumb')){ $albc = new the_breadcrumb; } ?>
            </div>
        <?php endif?>
	<div class="clear"></div>
    </div>
</div>
<div class="wrapper">
	<div id="container">
		<?php echo getPageContent($pageId); ?>
		<ul id="filterOptions" class="filter-items">
			<li><a href="<?php echo get_page_link($pageId) ?>"><?php _e('Show All', 'Wecare')?></a></li>
			<?php 
				$cats = get_post_meta($post->ID, "_page_portfolio_cat", $single = true);
				$MyWalker = new PortfolioWalker2();
				$args = array( 'taxonomy' => 'portfolio_category', 'hide_empty' => '0', 'include' => $cats, 'title_li'=> '', 'walker' => $MyWalker, 'show_count' => '1');
				$categories = wp_list_categories ($args);
			?>
			<!-- End Portfolio Navigation -->
		</ul>		
		<div id="ourHolder"class="projects-container <?php echo $itemsize?>">
			<?php
            $counter=1;
			if ($wp_query->have_posts()):
				while ($wp_query->have_posts()) : 							
					$wp_query->the_post();
					$custom = get_post_custom($post->ID);
					// Get the portfolio item categories
					$cats = wp_get_object_terms($post->ID, 'portfolio_category');
					if ($cats):
						$cat_slugs = '';
						foreach( $cats as $cat ) {$cat_slugs .= $cat->slug . " ";}
					endif;
					$link = ''; $thumbnail = get_the_post_thumbnail($post->ID, $thumbsize);
					?>
						
					<div class="item <?php echo $cat_slugs; ?>">
                                            <div class="view view-two">
                                               <?php if (!empty($thumbnail)): ?>
							<?php the_post_thumbnail($thumbsize, array('class' => 'cover')); ?>
						<?php else :?>
							 <img src="<?php echo get_template_directory_uri()?>/images/picture.jpg" alt="<?php _e ('No preview image', 'Wecare') ?>" />
						<?php endif?>	
                                                <div class="mask">
                                                    <?php if( !empty ( $custom['_portfolio_video'][0] ) ) : $link = $custom['_portfolio_video'][0]; ?>
								<a href="<?php echo $link ?>" class="button btn-icon fancybox-video fancybox.iframe"  data-fancybox-group="gallery1" title="<?php the_title() ?>">
									<i class="fa fa-film fa-3x"></i>
								</a>
							<?php elseif( isset($custom['_portfolio_link'][0]) && $custom['_portfolio_link'][0] != '' ) : ?>
								<a href="<?php echo $custom['_portfolio_link'][0] ?>" class="button btn-icon" data-fancybox-group="gallery1"  title="<?php the_title() ?>">
									<i class="fa fa-external-link fa-3x"></i>
								</a>
							<?php elseif(  isset( $custom['_portfolio_no_lightbox'][0] )  &&  $custom['_portfolio_no_lightbox'][0] !='' ) : $link = get_permalink(get_the_ID());  ?>
								<a href="<?php echo $link; ?>" class="button btn-icon" data-fancybox-group="gallery1" title="<?php the_title() ?>">
									<i class="fa fa-location-arrow fa-3x"></i>
								</a>
							<?php else : ?>
								<?php  
									$full_image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full', false); 
									$link = $full_image[0];
								?>
								<a href="<?php echo $link ?>" class="button btn-icon"  data-fancybox-group="gallery1" title="<?php the_title() ?>">
									<i class="fa fa-plus-circle fa-3x"></i>
								</a>
							<?php   endif; ?>
                                                </div>
                                            </div>
                                            <div class="port-span">
                                                <h3><?php the_title() ?></h3>                                    
						<span><?php echo $cat_slugs; ?></span>
                                            </div>
					</div>	
					<?php $counter++; endwhile; ?>				
				<?php endif?>
			</div>
			<?php if ($paginationEnabled ):?>
				<?php if ( $wp_query->max_num_pages > 1 ): ?>
					<div class="pagination-list blog-pagination">
						<?php include(Wecare_PLUGINS . '/wp-pagenavi.php' ); wp_pagenavi(); ?> 
						<div class="clear"></div>
					</div>
				<?php endif?>
			<?php endif?>		
		<div class="clear"></div>
	</div>
</div>
<?php get_footer() ?>