<?php
$the_categories = wp_kses_post($instance['categories']);
$post_title = wp_kses_post($instance['title']);
$numberPosts = (!empty($instance['number_of_posts']))? $instance['number_of_posts'] : 3 ;
$read_more_text = wp_kses_post($instance['read_more_text']);
$excerpt_length = wp_kses_post($instance['excerpt_length']);
$order_by = $instance['order_by'];
$order = $instance['order'];
global $imic_options;
?>
<?php query_posts( array ( 'post_type' => 'speaker', 'speaker-category' => $the_categories, 'posts_per_page' => $numberPosts,'orderby' => $order_by,'order' => $order ) );
if(!empty($instance['title'])){ ?>
<h3 class="panel-title">
<?php echo $post_title; ?>
</h3>
<?php }

		if($instance['compact_style']) { 
			echo '<ul class="members-list row">';
			if(have_posts()):while(have_posts()):the_post();
			$staff_position = get_post_meta(get_the_ID(),'imic_staff_position',true);
			$social = imic_social_staff_icon();
			if($instance['link_type']=='modal'){
				$link_type = 'data-toggle="modal" data-target="#team-modal-'.(get_the_ID()+2648).'" href="#"';
			} else {
				$link_type = 'href="'.get_the_permalink().'"';
			}
                    echo '<li class="col-md-'.$instance['column'].' col-sm-4 col-xs-6">';
					if(isset($imic_options['switch_lightbox']) && $imic_options['switch_lightbox']== 0){
						$Lightbox_init = 'data-rel="prettyPhoto" class="media-box"';
					}elseif(isset($imic_options['switch_lightbox']) && $imic_options['switch_lightbox']== 1){
						$Lightbox_init = 'class="media-box magnific-image"';
					}
					$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
					$url_thumb = $thumb['0'];
					if($instance['link_image_title'] && $instance['link_image_lightbox']){
						echo '<a href="'.$url_thumb.'" '.$Lightbox_init.'>'.get_the_post_thumbnail(get_the_ID(),'100x100').'</a>';
					} elseif($instance['link_image_lightbox']){
						echo '<a href="'.$url_thumb.'" '.$Lightbox_init.'>'.get_the_post_thumbnail(get_the_ID(),'100x100').'</a>';
					} elseif($instance['link_image_title']){
						echo '<a '.$link_type.'>'.get_the_post_thumbnail(get_the_ID(),'100x100').'</a>';
					} else {
						echo get_the_post_thumbnail(get_the_ID(),'100x100');	
					}
					if($instance['link_image_title']){
						echo '<h5><a '.$link_type.' class="">'.get_the_title().'</a></h5>';
					} else {
						echo '<h5>'.get_the_title().'</h5>';
					}
					if($instance['show_post_meta']){
						echo '<span class="meta-data">'.$staff_position.'</span>';
					}
                    echo $social.'</li>'; 
					
					echo '<div class="modal fade team-modal" id="team-modal-'.(get_the_ID()+2648).'" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
							  <div class="modal-dialog modal-lg">
								<div class="modal-content">
								  <div class="modal-header">
									<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
									<h4 class="modal-title" id="myModalLabel">'.__('Team Members','framework').'</h4>
								  </div>
									<div class="modal-body">
										<div class="staff-item">
										<div class="row">
											<div class="col-md-5 col-sm-6">
												'.get_the_post_thumbnail(get_the_ID(),'600x400',array('class'=>'img-thumbnail')).'
											</div>
											<div class="col-md-7 col-sm-6">
												<h3 class="short">'.get_the_title().'</h3>
												<span class="meta-data">'.get_post_meta(get_the_ID(),'imic_staff_position',true).'</span><div class="spacer-10"></div>';
												$post_id = get_post(get_the_ID());
													$content = $post_id->post_content;
													$content = apply_filters('the_content', $content);
													$content = str_replace(']]>', ']]>', $content);
													echo $content;
													if(get_post_meta(get_the_ID(),'imic_display_sermon_url',true)==1) {
													
													if($url!='') {
												echo '<a class="btn btn-primary" href="'.add_query_arg('speakers',get_the_ID(),$url).'">'.__('View all Sermons','framework').'</a>'; } }
											echo '</div>
										</div>
									</div>
									</div>
								</div>
							  </div>
							</div>';
			endwhile; endif;
			echo '</ul>';
		}
		else {
           	echo '<div class="row">';
			if(have_posts()):while(have_posts()):the_post();
			$staff_position = get_post_meta(get_the_ID(),'imic_staff_position',true);
			if($instance['link_image_title']){
				$link_type = 'data-toggle="modal" data-target="#team-modal-'.(get_the_ID()+2648).'" href="#"';
			} else {
				$link_type = 'href="'.get_the_permalink().'"';
			}
			$social = imic_social_staff_icon();
				echo '<div class="col-md-'.$instance['column'].' col-sm-6">
                      	<div class="grid-item staff-item format-standard">
                        	<div class="grid-item-inner">';
								if(isset($imic_options['switch_lightbox']) && $imic_options['switch_lightbox']== 0){
									$Lightbox_init = 'data-rel="prettyPhoto" class="media-box"';
								}elseif(isset($imic_options['switch_lightbox']) && $imic_options['switch_lightbox']== 1){
									$Lightbox_init = 'class="media-box magnific-image"';
								}
								$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
								$url_thumb = $thumb['0'];
								if($instance['link_image_title'] && $instance['link_image_lightbox']){
                                    		echo '<a href="'.$url_thumb.'" '.$Lightbox_init.'>'.get_the_post_thumbnail(get_the_ID(),'600x400').'</a>';
										} elseif($instance['link_image_lightbox']){
                                    		echo '<a href="'.$url_thumb.'" '.$Lightbox_init.'>'.get_the_post_thumbnail(get_the_ID(),'600x400').'</a>';
										} elseif($instance['link_image_title']){
                                    		echo '<a '.$link_type.'>'.get_the_post_thumbnail(get_the_ID(),'600x400').'</a>';
										} else {
											echo get_the_post_thumbnail(get_the_ID(),'600x400');	
										}
                          echo'	<div class="grid-content">
                                	<div class="staff-item-name">';
                            		if($instance['link_image_title']){
                                    	echo '<h5><a '.$link_type.' class="">'.get_the_title().'</a></h5>';
									} else {
                                    	echo '<h5>'.get_the_title().'</h5>';
									}
									if($instance['show_post_meta']){
                                    	echo '<span class="meta-data">'.$staff_position.'</span>';
									}
                                   echo '</div>'.$social;
								   if($excerpt_length != ''){
                                                if($instance['strip_html']){
                                                    echo '<p>'.strip_tags(content($excerpt_length)).'</p>';
                                               	} else {
                                                  	echo content($excerpt_length);
                                           		}
                                   			}
											if($read_more_text!=""){
												echo '<a '.$link_type.' class="btn btn-sm btn-default">'.$read_more_text.' <i class="fa fa-long-arrow-right"></i></a>';
											}
                          		echo '</div></div>
                        	</div>
                      	</div>';
				echo '<div class="modal fade team-modal" id="team-modal-'.(get_the_ID()+2648).'" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                      <div class="modal-dialog modal-lg">
                        <div class="modal-content">
                          <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">'.__('Team Members','framework').'</h4>
                          </div>
                            <div class="modal-body">
                                <div class="staff-item">
                                <div class="row">
                                    <div class="col-md-5 col-sm-6">
                                    	'.get_the_post_thumbnail(get_the_ID(),'600x400',array('class'=>'img-thumbnail')).'
                                    </div>
                                    <div class="col-md-7 col-sm-6">
                                    	<h3 class="short">'.get_the_title().'</h3>
                                    	<span class="meta-data">'.get_post_meta(get_the_ID(),'imic_staff_position',true).'</span><div class="spacer-10"></div>';
                                        $post_id = get_post(get_the_ID());
											$content = $post_id->post_content;
											$content = apply_filters('the_content', $content);
											$content = str_replace(']]>', ']]>', $content);
											echo $content;
											if(get_post_meta(get_the_ID(),'imic_display_sermon_url',true)==1) {
											
											if($url!='') {
										echo '<a class="btn btn-primary" href="'.add_query_arg('speakers',get_the_ID(),$url).'">'.__('View all Sermons','framework').'</a>'; } }
                                    echo '</div>
                                </div>
                            </div>
                            </div>
                        </div>
                      </div>
                    </div>';
			endwhile; endif;
           	echo '</div>';
		}
		wp_reset_query();
?>