<?php
/*
Template Name: 4 Column Portfolio Home
*/
?>

<?php get_header(); 

?>

<div id="mainwrap">

	<div id="main" class="clearfix">

	<div class="portfolio defaultport">		
			<div class="loading"></div>
				<div id="portitems4">
					<div id="infscr-loading"></div>
					<?php 
					
						$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
						$showposts = $data['port_number'];  
			
						$args = array(
										'showposts' => $showposts ,
										'post_type' => 'portfolioentry'
									  );
			
						$my_query = new WP_Query($args);
						$wp_query = $my_query;
			
						query_posts("showposts=$showposts&post_type=portfolioentry&paged=$paged");
			
						$limit_text = 100;
						$currentindex = '';
						$counter = 0;
						$count = 0;
		while ( have_posts() ) : the_post();
			$do_not_duplicate = $post->ID; 
			$full_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full', false);
			$entrycategory = get_the_term_list( $post->ID, $postC, '', '_', '' );
			$catstring = $entrycategory;
			$catstring = strip_tags($catstring);
			$catstring = str_replace('_', ', ', $catstring);
			$categoryname = $catstring;							
			$entrycategory = strip_tags($entrycategory);
			$entrycategory = str_replace(' ', '-', $entrycategory);
			$entrycategory = str_replace('_', ' ', $entrycategory);
			
			$catidlist = explode(" ", $entrycategory);
			for($i = 0; $i < sizeof($catidlist); ++$i){
				$catidlist[$i].=$currentindex;
			}
			$catlist = implode(" ", $catidlist);

			$category = get_the_term_list( $post->ID, $postC, '', ', ', '' );	
			
			if(($counter % 2) == 0 ){ 
				if(isset($full_image[0]))
					$img = get_template_directory_uri() .'/js/timthumb.php?src='.$full_image[0] .'&amp;h=200&amp;w=239';
				else
					$img = get_template_directory_uri() .'/js/timthumb.php?src='.get_template_directory_uri() .'/images/placeholder-port.png&amp;h=200&amp;w=239';
			?>	
				<div class="item4 small ">
			<?php } else { 
				if(isset($full_image[0]))
					$img = get_template_directory_uri() .'/js/timthumb.php?src='.$full_image[0] .'&amp;h=400&amp;w=239';
				else
					$img = get_template_directory_uri() .'/js/timthumb.php?src='.get_template_directory_uri() .'/images/placeholder-port.png&amp;h=400&amp;w=239';
				
			?>
				<div class="item4 big ">

			<?php  } ?>
				<a href="<?php the_permalink(); ?>">
					<div class="overdefult">
					
						<div class="viewIcon"><?php echo getPostViews(get_the_ID()); ?></div>
						<div class="likeIcon"><?php echo GetWtiLikeCount($post->ID) ?></div>

					</div>
				</a>
				<div class = "detailsoverdefault">
					<h3><a href="<?php the_permalink(); ?>"><?php $title = substr(the_title('','',FALSE),0,30); echo $title  ?></a></h3>
					<a href="<?php the_permalink(); ?>"><div class = "moreButton">+</div></a>
				</div>
				<div class="image">
					
					<img class="newimage <?php echo $newheight ?>" src="<?php echo  $img ?>" alt="<?php the_title(); ?>">
				</div>

				</div>	
			<?php 
				if((($counter % 3) == 0) && ($counter > 0) && ($temp == '')){
					$counter = 1;
					$temp = 'secund';
				}
				if(($temp == '')){
					$counter++;
				}							
				if(($temp == 'secund')){
					$counter = 1;
					$count++;
					if($count == 3){
						$count = 0;
						$temp = 'third';
						$counter = 2;
					}
				}	
				if(($temp == 'third')){
					$counter = 2;
					$count++;
					if($count == 3){
							$count= 0;
							$temp = '';
							$counter = 0;
						}								
				}							
			
			
			
			endwhile; 
						?>
					
		</div>
					
	
	</div>
	
</div>	
</div>

<script>
	   jQuery(function(){
  
  
		var $container = jQuery('#portitems4')
		// initialize Isotope
		$container.isotope({
		  // options...
		  resizable: false, // disable normal resizing
		  // set columnWidth to a percentage of container width
		  masonry: { columnWidth: $container.width() / 4 }
		});

		// update columnWidth on window resize
		jQuery(window).smartresize(function(){
		  $container.isotope({
			// update columnWidth to a percentage of container width
			masonry: { columnWidth: $container.width() / 4 }
		  });
		});
		

    });

</script>
	
<?php get_footer(); ?>