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

<?php get_header(); 

?>


<div id="mainwrap">

	<div id="main" class="clearfix">
	<?php  $portfolio = get_post_custom($post->ID); ?>
	<?php if(!isset($portfolio['port_category'][0]) || ($portfolio['port_category'][0]==0)){ ?>	
	<div id="remove" class="portfolioremove">
	    <h2><a class="catlink" href="#filter=*" ><?php echo  stripText($data['translation_all']) ?> <span> /</span></a>
		<?php $categories = get_terms("portfoliocategory");
		foreach ($categories as $category) {
			$entrycategory = str_replace(' ', '-', $category->name);
			echo '<a class="catlink" href="#filter=.'.$entrycategory .'" >'.$category->name.' <span class="aftersortingword"> /</span></a>';
		}
		?>
		</h2>
	</div>

	<?php } ?>

	<div class="portfolio defaultport">		
	
		<div id="portitems4">
		<div class="loading"></div>
		<?php	
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		$categport = '';

		$postT = 'portfolioentry';
		$postC = 'portfoliocategory';
		$showposts = $data['port_number'];
		if(getcatslug($portfolio['port_category'][0]) != '')
			$categport='&portfoliocategory='.getcatslug($portfolio['port_category'][0]);

		if($categport != "")
			query_posts("showposts=".$showposts."&post_type=".$postT."&paged=".$paged.$categport);
		else
			query_posts("showposts=".$showposts."&post_type=".$postT."&paged=".$paged);

		$limit_text = 100;
		$currentindex = '';
		$counter = 0;
		$count = 0;
		$temp = '';
		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 echo $catlist ?> " data-category="<?php echo $catlist ?>">
			<?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 echo $catlist ?> " data-category="<?php echo $catlist ?>">

			<?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>
					
		<?php
		include('includes/wp-pagenavi.php');
		if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
		?>
				
	</div>
	
</div>	
</div>
<script>
	   jQuery(function(){
  
      var $container = jQuery('#portitems4'),
          // object that will keep track of options
          isotopeOptions = {},
          // defaults, used if not explicitly set in hash
          defaultOptions = {
            filter: '*',
            sortBy: 'original-order',
            sortAscending: true,
			  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 }
		  });
		});		  

      // ensure no transforms used in Opera
      if ( jQuery.browser.opera ) {
        defaultOptions.transformsEnabled = false;
      }
      
     
  
      var setupOptions = jQuery.extend( {}, defaultOptions, {
        itemSelector : '.item4',
      });
  
      // set up Isotope
      $container.isotope( setupOptions );
  
      var $optionSets = jQuery('#options').find('.option-set'),
          isOptionLinkClicked = false;
  
      // switches selected class on buttons
      function changeSelectedLink( $elem ) {
        // remove selected class on previous item
        $elem.parents('.option-set').find('.selected').removeClass('selected');
        // set selected class on new item
        $elem.addClass('selected');
      }
  
  
      $optionSets.find('a').click(function(){
        var $this = $(this);
        // don't proceed if already selected
        if ( $this.hasClass('selected') ) {
          return;
        }
        changeSelectedLink( $this );
            // get href attr, remove leading #
        var href = $this.attr('href').replace( /^#/, '' ),
            // convert href into object
            // i.e. 'filter=.inner-transition' -> { filter: '.inner-transition' }
            option = $.deparam( href, true );
        // apply new option to previous
        jQuery.extend( isotopeOptions, option );
        // set hash, triggers hashchange on window
        jQuery.bbq.pushState( isotopeOptions );
        isOptionLinkClicked = true;
        return false;
      });

      var hashChanged = false;

      jQuery(window).bind( 'hashchange', function( event ){
        // get options object from hash
        var hashOptions = window.location.hash ? jQuery.deparam.fragment( window.location.hash, true ) : {},
            // do not animate first call
            aniEngine = hashChanged ? 'best-available' : 'none',
            // apply defaults where no option was specified
            options = jQuery.extend( {}, defaultOptions, hashOptions, { animationEngine: aniEngine } );
        // apply options from hash
        $container.isotope( options );
        // save options
        isotopeOptions = hashOptions;
    
        // if option link was not clicked
        // then we'll need to update selected links
        if ( !isOptionLinkClicked ) {
          // iterate over options
          var hrefObj, hrefValue, $selectedLink;
          for ( var key in options ) {
            hrefObj = {};
            hrefObj[ key ] = options[ key ];
            // convert object into parameter string
            // i.e. { filter: '.inner-transition' } -> 'filter=.inner-transition'
            hrefValue = jQuery.param( hrefObj );
            // get matching link
            $selectedLink = $optionSets.find('a[href="#' + hrefValue + '"]');
            changeSelectedLink( $selectedLink );
          }
        }
    
        isOptionLinkClicked = false;
        hashChanged = true;
      })
        // trigger hashchange to capture any hash data on init
        .trigger('hashchange');

    });

</script>

	
<?php get_footer(); ?>