<?php
global $smof_data;
	 $querydetails = "
	   SELECT wposts.*
	   FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
	   WHERE wposts.ID = wpostmeta.post_id
	   AND wpostmeta.meta_key = 'lioit_slider5'
	   AND wpostmeta.meta_value = '1'
	   AND wposts.post_status = 'publish'
	   AND wposts.post_type = 'post'
	   ORDER BY wposts.post_date DESC
	 ";

	 $pageposts = $wpdb->get_results($querydetails, OBJECT);
	 
	 
	 if ($pageposts == true){
?>    
            
            <div id="mainSlideshows" class="mainSlideshows clearfix mainBorder">
              <div id="featuredPosts" class="clearfix">
                <div class="preloader"></div><!--End Loading-->
                <div class="slides">
                    <?php 
                
                                $i = 0;
                                if ($pageposts):
                                foreach ($pageposts as $post):
                                setup_postdata($post); 
                                $i++;
                                if ($i <= 12) {
                                ?>
                    <div class="slide">
                        
                        <?php the_post_thumbnail('slider1', array('title' => strip_tags(get_the_title()))); ?>
                      <div class="text">
                        <h3> <a href="<?php the_permalink();?>" ><?php the_title(); ?></a> </h3>
                        <p><?php the_excerpt_max_charlength('200'); ?></p>
                      </div>
                      <div class="overlay"></div>
                    </div><!--End Slide-->
                    <?php } 
                                    endforeach; 	
                                endif; 
                                wp_reset_query();?>                                     
                </div><!--End Slides-->
              </div><!--End featured Posts-->
              <div id="featuredThumbs" class="clearfix">
                <ul class="slides">
					<?php 
                
                                $i = 0;
                                if ($pageposts):
                                foreach ($pageposts as $post):
                                setup_postdata($post); 
                                $i++;
                                if ($i <= 12) {
                                ?>
                    <li>
                    <?php the_post_thumbnail('slider1', array('title' => strip_tags(get_the_title()))); ?>
                    </li>
                    <?php } 
                                    endforeach; 	
                                endif; 
                                wp_reset_query();?>
                </ul>
              </div>
            </div><!--End SlideShow-->
            
            
<script type="text/javascript">
jQuery(document).ready(function($) {
	jQuery('#featuredThumbs').flexslider({
		namespace: "",
		animation: "slide",
		asNavFor: '#featuredPosts',
		slideshow: false,
		controlNav: false,
		itemWidth: 105,
		itemMargin: 11,
		minItems: 2,
		maxItems: 5
	});
	jQuery('#featuredPosts').flexslider({
		namespace: "",
		selector: ".slides > .slide",
		animation: "slide",
		sync: '#featuredThumbs',
		slideshowSpeed: 5000,
		animationSpeed: 900,
		animationLoop: true,
		slideshow: true,
		controlNav: false,
		directionNav: false,
		start: function(slider) {
			jQuery('.preloader').hide();
			jQuery('#featuredThumbs').show();
		},
	});
});
</script> 

<?php }else{ ?>
<?php }?>