<?php
//Thumbnails for Gallery [thumbnails]
if ( !function_exists( 'mtheme_Proofing' ) ) {
	function mtheme_Proofing($atts, $content = null) {
		extract(shortcode_atts(array(
			"size" => 'thumbnail',
			"exclude_featured" => 'false',
			"attachment_linking" => 'false',
			"format" => '',
			"start" => '',
			"end" => '',
			"animated" => 'false',
			"gutter" => 'spaced',
			"boxtitle" => '',
			"pb_image_ids" => '',
			"columns" => '4',
			"title" => "true",
			"description" => "false",
			"id" => '1',
			"proofingstatus" => 'active',
			"pageid" => ''
		), $atts));
		
	// Set a default
	$column_type="four";
	$portfolioImage_type="cinnamon-restaurant-image-large";

	if ($columns==4) { 
		$column_type="four";
		$portfolioImage_type="cinnamon-restaurant-image-large";
		}
	if ($columns==3) { 
		$column_type="three";
		$portfolioImage_type="cinnamon-restaurant-image-large";
		}
	if ($columns==2) { 
		$column_type="two";
		$portfolioImage_type="cinnamon-restaurant-image-large";
		}
	if ($columns==1) { 
		$column_type="one";
		$portfolioImage_type="cinnamon-restaurant-image-full";
		}

	if ( $format == "portrait") {
		if ($columns==4) { 
			$portfolioImage_type="cinnamon-restaurant-image-large-portrait";
			}
		if ($columns==3) { 
			$portfolioImage_type="cinnamon-restaurant-image-large-portrait";
			}
		if ($columns==2) {
			$portfolioImage_type="cinnamon-restaurant-image-large-portrait";
			}
		if ($columns==1) {
			$portfolioImage_type="cinnamon-restaurant-image-full";
			}
	}
	$gridblock_is_masonary = "";
	if ( $format == "masonary") {

		$gridblock_is_masonary = " gridblock-masonary";
		if ($columns==4) { 
			$portfolioImage_type="cinnamon-restaurant-image-full-medium";
			}
		if ($columns==3) { 
			$portfolioImage_type="cinnamon-restaurant-image-full-medium";
			}
		if ($columns==2) {
			$portfolioImage_type="cinnamon-restaurant-image-full-medium";
			}
		if ($columns==1) {
			$portfolioImage_type="cinnamon-restaurant-image-full";
			}
	}
	if ( $format == "portrait" ) {
		$protected_placeholder = '/images/blank-grid-portrait.png';
	} else {
		$protected_placeholder = '/images/blank-grid.png';
	}
	$preload_tag = '<div class="preloading-placeholder"><span class="preload-image-animation"></span><img src="'.get_template_directory_uri().$protected_placeholder.'" alt="preloading" /></div>';
		
		$portfolio_count=0;
		$thumbnailcount=0;
		$thepageID=get_the_id();

		$pb_image_ids=trim($pb_image_ids);
		if ( !empty($pb_image_ids) ) {
			$filter_image_ids = explode(',', $pb_image_ids);
		} else {
			if ( $pageid == '') {
				$pageid = get_the_id();
			}
			$filter_image_ids = imaginem_codepack_get_custom_attachments ( $pageid );
		}

		if ($end < $start) {
			$end='';
			$start='';
		}

		$thumbnail_gutter_class='';
		if ($gutter=="nospace") {
			$thumbnail_gutter_class = ' thumnails-gutter-active ';
		}

		$title_desc_class = '';
		if ($title=="false" && $description=="false") {
			$title_desc_class = " no-title-no-desc";
		}

		$proof_edit_enabled = $proofingstatus;

		//$filter_image_ids = imaginem_codepack_get_custom_attachments ( $thepageID );
		
		if ( $filter_image_ids ) {


			
				$thumbnails =  '<div class="proofing-shortcode proofing-status-'.$proofingstatus.' thumbnails-shortcode gridblock-columns-wrap clearfix">';

			// Filterables
		$thumbnails .= '<div class="gridblock-filter-select-wrap">';

			$thumbnails .= '<div id="gridblock-filters">';
				$thumbnails .= '<ul class="gridblock-filter-categories">';
					
					$thumbnails .= '<li class="filter-all-control">';
						$thumbnails .= '<a data-filter="*" data-title="All items" href="#">';
						$thumbnails .= '<span class="filter-seperator filter-seperator-all"></span>All items';
						$thumbnails .= '</a>';
					$thumbnails .= '</li>';

					$thumbnails .= '<li class="filter-control filter-category-control filter-control-selected">';
						$thumbnails .= '<a data-filter=".filter-selected" data-title="Selected" href="#">';
							$thumbnails .= '<span class="filter-seperator filter-seperator-all"></span>Selected';
						$thumbnails .= '</a>';
					$thumbnails .= '</li>';

					$thumbnails .= '<li class="filter-control filter-category-control filter-control-rejected">';
						$thumbnails .= '<a data-filter=".filter-unchecked" data-title="Rejected" href="#">';
							$thumbnails .= '<span class="filter-seperator filter-seperator-all"></span>Rejected';
						$thumbnails .= '</a>';
					$thumbnails .= '</li>';

					$thumbnails .= '</ul>';
				$thumbnails .= '</div>';
			$thumbnails .= '</div>';

				// Selected Count
				$thumbnails .=  '<div class="proofing-status-count-wrap"><div id="proofing-status-count" class="animation-standby animated pulse"><span class="proofing-count-selected">0</span> / <span class="proofing-count-total">0</span> ' . __('Selected','mthemelocal') . '</div></div>';

				$thumbnails .= '<div id="gridblock-container" class="proofing-item-wrap thumbnails-grid-container thumbnail-gutter-'.$gutter.$gridblock_is_masonary.$thumbnail_gutter_class.$title_desc_class.' gridblock-'.$column_type.'"  data-columns="'.$columns.'">';

				$featuredID = get_post_thumbnail_id();

				foreach ( $filter_image_ids as $attachment_id) {
				
				$thumbnailcount++;
				
				if ($start!='') {
					if ($thumbnailcount < $start ) { continue; }
				}
				if ($end!='') {
					if ($thumbnailcount > $end ) { continue; }
				}

				if ( $exclude_featured=='true') {
					if ($featuredID==$attachment_id) continue; // skip rest of the loop
				}

				$imagearray = wp_get_attachment_image_src( $attachment_id , 'fullsize', false);
				$imageURI = $imagearray[0];			
				
				$thumbnail_imagearray = wp_get_attachment_image_src( $attachment_id , $portfolioImage_type, false);
				$thumbnail_imageURI = $thumbnail_imagearray[0];
				
				$imageTitle='';
				$imageDesc='';
				$imageID = get_post($attachment_id);
				if (isSet( $imageID->post_title ) ) {
					$imageTitle = $imageID->post_title;
				}
				if (isSet( $imageID->post_content ) ) {
					$imageDesc= $imageID->post_content;
				}
				
				if ($portfolio_count==$columns) $portfolio_count=0;
				$portfolio_count++;

				// if ($portfolio_count==1) {
				// 	$thumbnails .=   '<li class="clearfix"></li>';
				// }
				$animation_class='';
				if ($animated == "true") {
					//$animation_class=' animation-standby animated rotateInUpRight';
					$animation_class=' animation-standby animated flipInX';
				}

				$mtheme_proofing_status="false";
				$proofing_icon=imaginem_codepack_get_portfolio_icon('check');
				$set_proofing="unchecked";

				$mtheme_proofing_status = get_post_meta($attachment_id,'checked',true);
				if ($mtheme_proofing_status=="true") {
					$set_proofing="selected";
					$proofing_icon=imaginem_codepack_get_portfolio_icon('cross');
				}

				$thumbnails .=  '<div id="mtheme-proofing-item-'.$attachment_id.'" data-proofing_status="'.$set_proofing.'" class="filter-'.$set_proofing.' mtheme-proofing-item proofing-item-'.$set_proofing.' gridblock-element '.$animation_class.' gridblock-thumbnail-id-'.$attachment_id.' gridblock-col-'.$portfolio_count.'">';
				$thumbnails .= '<div class="gridblock-ajax gridblock-grid-element gridblock-element-inner" data-rel="'.get_the_id().'">';
					$thumbnails .= '<i class="proofing-progress-indicator fa fa-circle-o-notch"></i>';
					$thumbnails .= '<span class="proofing-selected-marker"><i class="'.imaginem_codepack_get_portfolio_icon('selected').'"></i></span>';
					if ($proofingstatus<>"active") {
						$thumbnails .= imaginem_codepack_activate_lightbox (
									$lightbox_type="default",
									$ID=get_the_id(),
									$predefined=$imageURI,
									$mediatype="image",
									$imagetitle='ID'.$attachment_id.' '.$imageTitle,
									$class="column-gridblock-lightbox lightbox-image",
									$set="metro-grid",
									$data_name="default"
								);
					}
					$thumbnails .= '<div class="gridblock-background-hover">';
						$thumbnails .= '<div class="gridblock-links-wrap">';
					
						if ($proofingstatus=="active") {
							$thumbnails .=  imaginem_codepack_activate_lightbox (
								$lightbox_type="magnific",
								$ID='',
								$link=$imageURI,
								$mediatype="image",
								$imagetitle='ID'.$attachment_id.' '.$imageTitle,
								$class="column-gridblock-icon column-gridblock-lightbox",
								$navigation="magnific-thumbnails"
								);
								$thumbnails .= '<span class="hover-icon-effect"><i class="'.imaginem_codepack_get_portfolio_icon('lightbox').'"></i></span>';
							$thumbnails .= '</a>';
							
							$thumbnails .= '<a class="column-gridblock-icon mtheme-proofing-choice mtheme-proofing-'.$proof_edit_enabled.'" data-image_id="'.$attachment_id.'">';
								$thumbnails .= '<span class="hover-icon-effect"><i class="proofing-icon-status '.$proofing_icon.'"></i></span>';
							$thumbnails .= '</a>';
							$thumbnails .= '<a download href="'.$imageURI.'" class="column-gridblock-icon column-gridblock-lightbox">';
								$thumbnails .= '<span class="hover-icon-effect"><i class="proofing-icon-download '.imaginem_codepack_get_portfolio_icon('download').'"></i></span>';
							$thumbnails .= '</a>';
						} else {
							$thumbnails .= '<span class="column-gridblock-icon"><span class="hover-icon-effect"><i class="'.imaginem_codepack_get_portfolio_icon('lightbox').'"></i></span></span>';
						}

						$thumbnails .= '</div>';
					$thumbnails .= '</div>';
			if ($proofingstatus<>"active") {
				$thumbnails .= '</a>';
			}
			$thumbnails .= '<img class="preload-image displayed-image" src="'.$thumbnail_imagearray[0].'" alt="'.imaginem_codepack_get_alt_text($featuredID).'">';
			$thumbnails .=  '</div>';
			if ($title=="true" || $description=="true") {
				$portfoliogrid ='<div class="work-details">';
					if ($title=='true') {
						$portfoliogrid .= '<h4>';
						$portfoliogrid .= '#'. $attachment_id;
						$portfoliogrid .= '</h4>';
					}
					if ($description=='true') { $portfoliogrid .= '<p class="entry-content work-description">'.$imageDesc.'</p>'; }
				$portfoliogrid .='</div>';
				$thumbnails .= $portfoliogrid;
			}
			$thumbnails .= '</div>';
		}
		$thumbnails .= '</div>';
		$thumbnails .= '</div>';

		return $thumbnails;

		}	
	}
}
add_shortcode("proofing_gallery", "mtheme_Proofing");
/**
 * Portfolio Grid
 */
if ( !function_exists( 'mClientGrids' ) ) {
	function mClientGrids($atts, $content = null) {
		extract(shortcode_atts(array(
			"client_id" => '',
			"pageid" => '',
			"format" => '',
			"columns" => '4',
			"limit" => '-1',
			"filter_subcats" => "true",
			"category_display" => "true",
			"gutter" => 'spaced',
			"boxtitle" => 'false',
			"title" => 'true',
			"desc" => 'true',
			"worktype_slugs" => '',
			"pagination" => 'false',
			"type" => 'filter'
		), $atts));


	$portfoliogrid ='';
	$subcat_filter_portfoliogrid = '';

	// Set a default
	$column_type="four";
	$portfolioImage_type="cinnamon-restaurant-image-large";

	if ($columns==4) { 
		$column_type="four";
		$portfolioImage_type="cinnamon-restaurant-image-large";
		}
	if ($columns==3) { 
		$column_type="three";
		$portfolioImage_type="cinnamon-restaurant-image-large";
		}
	if ($columns==2) { 
		$column_type="two";
		$portfolioImage_type="cinnamon-restaurant-image-large";
		}
	if ($columns==1) { 
		$column_type="one";
		$portfolioImage_type="cinnamon-restaurant-image-full";
		}

	if ( $format == "portrait") {
		if ($columns==4) { 
			$portfolioImage_type="cinnamon-restaurant-image-large-portrait";
			}
		if ($columns==3) { 
			$portfolioImage_type="cinnamon-restaurant-image-large-portrait";
			}
		if ($columns==2) {
			$portfolioImage_type="cinnamon-restaurant-image-large-portrait";
			}
		if ($columns==1) {
			$portfolioImage_type="cinnamon-restaurant-image-full";
			}
	}
	$gridblock_is_masonary = "";
	if ( $format == "masonary") {

		$gridblock_is_masonary = "gridblock-masonary ";
		if ($columns==4) { 
			$portfolioImage_type="cinnamon-restaurant-image-full-medium";
			}
		if ($columns==3) { 
			$portfolioImage_type="cinnamon-restaurant-image-full-medium";
			}
		if ($columns==2) {
			$portfolioImage_type="cinnamon-restaurant-image-full-medium";
			}
		if ($columns==1) {
			$portfolioImage_type="cinnamon-restaurant-image-full";
			}
	}

	if ( $format == "portrait" ) {
		$protected_placeholder = '/images/blank-grid-portrait.png';
	} else {
		$protected_placeholder = '/images/blank-grid.png';
	}
	//$preload_tag = '<div class="preloading-placeholder"><span class="preload-image-animation"></span><img src="'.get_template_directory_uri().$protected_placeholder.'" alt="preloading" /></div>';
	$thumbnail_gutter_class =  'portfolio-gutter-'.$gutter.' ';
	if ($gutter=="nospace") {
		$thumbnail_gutter_class .=  'thumnails-gutter-active ';
	}
	if ($title<>"true" && $desc<>"true") {
		$thumbnail_gutter_class .=  'no-title-no-desc ';
	}
	$boxtitle_class='';
	if ($boxtitle=="true") {
		$boxtitle_class=" boxtitle-active";
	}
	$flag_new_row=true;


	$portfoliogrid .= '<div id="gridblock-container" class="'.$thumbnail_gutter_class.$gridblock_is_masonary.$boxtitle_class.' gridblock-'.$column_type.' clearfix" data-columns="'.$columns.'">';

	if ( get_query_var('paged') ) {
		$paged = get_query_var('paged');
	} elseif ( get_query_var('page') ) {
		$paged = get_query_var('page');
	} else {
		$paged = 1;
	}

	$count=0;
	$terms=array();
	$work_slug_array=array();

	$current_page_id = get_the_id();

	query_posts(
		array(
			'post_type' => 'mtheme_proofing',
			'orderby' => 'menu_order',
			'order' => 'ASC',
			'paged' => $paged,
			'posts_per_page' => $limit,
			'meta_query' => array(
	            array(
	                'key' => 'pagemeta_client_names',
	                'value' => $client_id,
	                'compare' => '='
	           	)
	        )
        )
    );

	$idCount=1;
	$portfolio_count=0;
	$portfolio_total_count=0;
	$portfoliofilters = array();

	if (have_posts()) : while (have_posts()) : the_post();
			//echo $type, $portfolio_type;
		$custom = get_post_custom(get_the_ID());
		$portfolio_cats = get_the_terms( get_the_ID(), 'types' );
		$lightboxvideo="";
		$thumbnail="";
		$customlink_URL="";
		$description="";
		$portfolio_link_type="";
		$portfolio_thumb_header="Image";
		$the_only_link = false;
		$the_protected_link = false;

		if ( isset($custom['pagemeta_thumbnail_linktype'][0]) ) { $portfolio_link_type=$custom['pagemeta_thumbnail_linktype'][0]; }
		if ( isset($custom['pagemeta_lightbox_video'][0]) ) { $lightboxvideo=$custom['pagemeta_lightbox_video'][0]; }
		if ( isset($custom['pagemeta_customthumbnail'][0]) ) { $thumbnail=$custom['pagemeta_customthumbnail'][0]; }
		if ( isset($custom['pagemeta_thumbnail_desc'][0]) ) { $description=$custom['pagemeta_thumbnail_desc'][0]; }
		if ( isset($custom['pagemeta_customlink'][0]) ) { $customlink_URL=$custom['pagemeta_customlink'][0]; }
		if ( isset($custom['pagemeta_portfoliotype'][0]) ) { $portfolio_thumb_header=$custom['pagemeta_portfoliotype'][0]; }

		if ($portfolio_count==$columns) $portfolio_count=0;

		$add_space_class = '';
		if ( $gutter!='nospace') {
			if ($title=='false' && $desc=='false') {
				$add_space_class = 'gridblock-cell-bottom-space';
			}
		}

		$protected="";
		$icon_class="column-gridblock-icon";
		$portfolio_count++;
		$portfolio_total_count++;

		$gridblock_ajax_class='';
		if ($type=='ajax') {
			$gridblock_ajax_class="gridblock-ajax ";
		}

		// Generate main DIV tag with portfolio information with filterable tags
		$portfoliogrid .= '<div class="gridblock-element isotope-displayed gridblock-element-id-'.get_the_ID().' gridblock-element-order-'.$portfolio_total_count.' '.$add_space_class.' gridblock-filterable ';
		if ( is_array($portfolio_cats) ) {
			foreach ($portfolio_cats as $taxonomy) { 
				$portfoliogrid .=  'filter-' . $taxonomy->slug . ' ';
				if ($pagination=='true') {
					if (in_array($taxonomy->slug, $portfoliofilters)) {
					} else {
						$portfoliofilters[] = $taxonomy->slug;
					}
				}
			}
		}
		$idCount++;
		$portfoliogrid .= '" data-portfolio="portfolio-'. get_the_ID() .'" data-id="id-'. $idCount .'">';
			$portfoliogrid .= '<div class="'.$gridblock_ajax_class.'gridblock-grid-element gridblock-element-inner" data-portfolioid="'.get_the_id().'">';

				$portfoliogrid .= '<div class="gridblock-background-hover">';

				if ( post_password_required() ) {
					$the_only_link = true;
					$the_protected_link = true;
					$portfolio_link_type = "Protected";
					$protected=" gridblock-protected"; $iconclass="";
				}


		//if Password Required

			//Make sure it's not a slideshow
		if ($type !="ajax") {
				//Switch check for Linked Type
			//Switch check for Linked Type
			//
				if ($portfolio_link_type=="Lightbox_DirectURL") {
					$portfoliogrid .= '<div class="gridblock-links-wrap box-title-'.$boxtitle.'">';
				}

				if ( post_password_required() ) {
							$the_only_link = true;
							$portfoliogrid .= '<a class="gridblock-sole-link" href="'.get_permalink() .'">';
							$icon_class='<i class="'.imaginem_codepack_get_portfolio_icon('directlink').'"></i>';					
				} else {

					if ($portfolio_link_type=="Lightbox_DirectURL") {
						$portfoliogrid .= '<a class="column-gridblock-icon" href="'.get_permalink() .'">';
							$portfoliogrid .= '<span class="hover-icon-effect"><i class="'.imaginem_codepack_get_portfolio_icon('directlink').'"></i></span>';
						$portfoliogrid .= '</a>';
					}

					
					switch ($portfolio_link_type) {
						case 'DirectURL':
							$the_only_link = true;
							$portfoliogrid .= '<a class="gridblock-sole-link" href="'.get_permalink() .'">';
							$icon_class='<i class="'.imaginem_codepack_get_portfolio_icon('directlink').'"></i>';
							break;

						case 'Customlink':
							$the_only_link = true;
							$portfoliogrid .= '<a class="gridblock-sole-link" href="'.$customlink_URL.'">';
							$icon_class='<i class="'.imaginem_codepack_get_portfolio_icon('link').'"></i>';
							break;

						case 'Lightbox_DirectURL':
							if ( $lightboxvideo<>"" ) {
								$portfoliogrid .=
								imaginem_codepack_activate_lightbox (
									$lightbox_type="default",
									$ID=get_the_id(),
									$predefined=$lightboxvideo,
									$mediatype="video",
									$imagetitle=get_the_title(),
									$class="column-gridblock-icon column-gridblock-lightbox lightbox-video",
									$set="portfolio-grid",
									$data_name="default"
								);
								$icon_class='<i class="feather-icon-play"></i>';
							} else {
								$portfoliogrid .=
								imaginem_codepack_activate_lightbox (
									$lightbox_type="default",
									$ID=get_the_id(),
									$predefined=imaginem_codepack_featured_image_link( get_the_ID() ),
									$mediatype="image",
									$imagetitle=imaginem_codepack_image_title( get_the_ID() ),
									$class="column-gridblock-icon column-gridblock-lightbox lightbox-image",
									$set="portfolio-grid",
									$data_name="default"
								);
								$icon_class='<i class="'.imaginem_codepack_get_portfolio_icon('lightbox').'"></i>';							
							}
							break;
						case 'Lightbox':
							$the_only_link = true;
							if ( $lightboxvideo<>"" ) {
								$portfoliogrid .=
								imaginem_codepack_activate_lightbox (
									$lightbox_type="default",
									$ID=get_the_id(),
									$predefined=$lightboxvideo,
									$mediatype="video",
									$imagetitle=get_the_title(),
									$class="gridblock-sole-link column-gridblock-lightbox lightbox-video",
									$set="portfolio-grid",
									$data_name="default"
								);
								$icon_class='<i class="feather-icon-play"></i>';
							} else {
								$portfoliogrid .=
								imaginem_codepack_activate_lightbox (
									$lightbox_type="default",
									$ID=get_the_id(),
									$predefined=imaginem_codepack_featured_image_link( get_the_ID() ),
									$mediatype="image",
									$imagetitle=imaginem_codepack_image_title( get_the_ID() ),
									$class="gridblock-sole-link column-gridblock-lightbox lightbox-image",
									$set="portfolio-grid",
									$data_name="default"
								);
								$icon_class='<i class="'.imaginem_codepack_get_portfolio_icon('lightbox').'"></i>';							
							}
							break;
						default:
							$the_only_link = true;
							$portfoliogrid .= '<a class="gridblock-sole-link" href="'.get_permalink() .'">';
							$icon_class='<i class="'.imaginem_codepack_get_portfolio_icon('albums').'"></i>';
							break;
					}

					if ($portfolio_link_type != "Lightbox_DirectURL") {
						$portfoliogrid .= '<div class="gridblock-links-wrap box-title-'.$boxtitle.'">';
					}
					//$portfoliogrid .= '<span class="gridblock-image-hover">';
					if ( isSet($icon_class) ) {
						if ($the_only_link) {
							$portfoliogrid .= '<span class="column-gridblock-icon">';
						}
						$portfoliogrid .= '<span class="hover-icon-effect">'.$icon_class .'</span>';
						if ($the_only_link) {
							$portfoliogrid .= '</span>';
						}
					}
					if ($portfolio_link_type != "Lightbox_DirectURL") {
						$portfoliogrid .= '</div>';
					}
					$portfoliogrid .= '</a>';
				}
				if ($portfolio_link_type == "Lightbox_DirectURL") {
					$portfoliogrid .= '</div>';
				}

				if ( post_password_required() ) {
					$portfoliogrid .= '</a>';
				}
				//$portfoliogrid .= '</span>';
				// If it aint slideshow then display a background. Otherwise one is active in slideshow thumbnails.
				// Custom Thumbnail
		// If AJAX
		} else {
			$portfoliogrid .= '<div class="gridblock-links-wrap box-title-'.$boxtitle.'">';
			$portfoliogrid .= '<span class="column-gridblock-icon">';
			$icon_class='<i class="' . imaginem_codepack_get_portfolio_icon('ajax') . '"></i>';
			$portfoliogrid .= '<span class="hover-icon-effect">'.$icon_class .'</span>';
			$portfoliogrid .= '</span>';
			$portfoliogrid .= '</div>';
		}
				if ($boxtitle=="true") {

					$current_terms = wp_get_object_terms( get_the_ID(), 'types' );
					$current_worktype = '';
					$seperator = ',';
					foreach( $current_terms as $the_term ) {
						if ($the_term === end($current_terms)) {
							$seperator = '';
						}
						$current_worktype .= $the_term->name . $seperator;
					}
				
					$portfoliogrid .= '<span class="boxtitle-hover">';
					$portfoliogrid .= '<a href="'.get_permalink().'">';
					$portfoliogrid .= get_the_title();
					$portfoliogrid .= '</a>';
					$portfoliogrid .= '<span class="boxtitle-worktype">'.$current_worktype.'</span>';
					$portfoliogrid .= '</span>';
				}
		$portfoliogrid .= '</div>';

		$fade_in_class ="";
		if ( post_password_required() ) {

			$portfoliogrid .= '<div class="gridblock-protected">';
			$portfoliogrid .= '<span class="hover-icon-effect"><i class="'.imaginem_codepack_get_portfolio_icon('locked').'"></i></span>';
			if ( $format == "portrait" ) {
				$protected_placeholder = '/images/blank-grid-portrait.png';
			} else {
				$protected_placeholder = '/images/blank-grid.png';
			}
			$portfoliogrid .= '<img class="'.$fade_in_class.'displayed-image" src="'.get_template_directory_uri().$protected_placeholder.'" alt="blank" />';
			$portfoliogrid .= '</div>';

		} else {
			if ($thumbnail<>"") {
				$portfoliogrid .= '<img src="'.$thumbnail.'" class="'.$fade_in_class.'displayed-image" alt="thumbnail" />';
			} else {
				// Slideshow then generate slideshow shortcode
				$portfoliogrid .= imaginem_codepack_display_post_image (
					get_the_ID(),
					$have_image_url="",
					$link=false,
					$imagetype=$portfolioImage_type,
					$imagetitle=imaginem_codepack_image_title( get_the_ID() ),
					$class= $fade_in_class."displayed-image"
				);

			}
		}
	$portfoliogrid .='</div>';
		if ($title=='true' || $desc=='true') {
			$portfoliogrid .='<div class="work-details">';
				$hreflink = get_permalink();
				if ($category_display=='true') {
					$current_terms = wp_get_object_terms( get_the_ID(), 'types' );
					$current_worktype = '';
					$seperator = ' , ';
					foreach( $current_terms as $the_term ) {
						if ($the_term === end($current_terms)) {
							$seperator = '';
						}
						$current_worktype .= $the_term->name . $seperator;
					}

					$portfoliogrid .= '<div class="worktype-categories">'.$current_worktype.'</div>';
				}
				if ($title=='true') {
					if ($type != "ajax") {
						$portfoliogrid .='<h4><a href="'.$hreflink.'">'. get_the_title() .'</a></h4>';
					} else {
						$portfoliogrid .= '<h4>';
						$portfoliogrid .= get_the_title();
						$portfoliogrid .= '</h4>';
					}
				}
				if ($desc=='true') $portfoliogrid .= '<p class="entry-content work-description">'.$description.'</p>';
			$portfoliogrid .='</div>';
		}


	$portfoliogrid .='</div>';

	//if ($portfolio_count==$columns)  $portfoliogrid .='</div>';

	endwhile; endif;
	// if ($format=="masonary") {
	// 	$portfoliogrid .= '</div>';
	// }
	$portfoliogrid .='</div>';

	if ($pagination=='true') { 
		$portfoliogrid .= '<div class="clearfix">';
		$portfoliogrid .= imaginem_codepack_pagination();
		$portfoliogrid .= '</div>';
	}

		wp_reset_query();
		return $portfoliogrid;
	}
}
add_shortcode("clientgrid", "mClientGrids");
?>