<?php
/* 
* Theme: PREMIUMPRESS CORE FRAMEWORK FILE
* Url: www.premiumpress.com
* Author: Mark Fail
*
* THIS FILE WILL BE UPDATED WITH EVERY UPDATE
* IF YOU WANT TO MODIFY THIS FILE, CREATE A CHILD THEME
*
* http://codex.wordpress.org/Child_Themes
*/
if (!defined('THEME_VERSION')) {	header('HTTP/1.0 403 Forbidden'); exit; }

global $CORE;


// GET HOME PAGE CUSTOM DATA
$HDATA = $GLOBALS['CORE_THEME']['hdata'];



			// ADD-ON PLAYER FILES ENCASE WE HAVE VIDEO
			wp_enqueue_script('video', get_template_directory_uri().'/framework/player/mediaelement-and-player.min.js');
			wp_enqueue_script('video');
	 
			// QUERY 
			$querystring = "orderby=rand&post_type=listing_type&posts_per_page=10"; 
 
			// RUN
			$slider_query = new WP_Query( hook_custom_queries($querystring) );

			// The Loop
			if ( $slider_query->have_posts() ) {
	
			// DEFAULTS
			$data_carousel = "";
			$slide_carousel = "";
			
			// LOOP
			while ( $slider_query->have_posts() ) {
			
				// GET DATA
				$slider_query->the_post();
				
				// IMAGE		
				$image = hook_image_display(get_the_post_thumbnail($post->ID, 'thumbnail', array('class'=> "wlt_thumbnail img-responsive")));			
				if($image == ""){$image = hook_fallback_image_display($CORE->FALLBACK_IMAGE($post->ID)); }	
				
				// GET LINK
				$link = get_permalink($post->ID);
				
				// SLIDER DATA
				$slide_carousel .= '<div class="item">
				
				<div class="col-md-5 col-sm-5"><a href="' . $link . '">' . $image . '</a></div>
				<div class="col-md-7 col-sm-7">
				
				<div class="wrap">
				<h1>'.get_the_title().'</h1> 
				
				<hr />
					<a href="'.$link.'" class="btn btn-lg hidden-sm hidden-xs">'.$CORE->_e(array('button','4','flag_noedit')).'</a>
				'.do_shortcode('[RATING style=1 results=1]').'
				<hr class="hidden-sm hidden-xs" />
				 
				<div class="excerptb hidden-sm hidden-xs">'.get_the_excerpt().'</div>
				 
				</div>
				
				</div>
				</div>';
				
				// CAROUSEL DATA
				$data_carousel .= $image . $extra ;
			}
		
		} else {
			// no posts found
			return;
		}
		/* Restore original Post Data */
		wp_reset_postdata();
 
 
// HEADER
get_header($CORE->pageswitch()); 	
?>  

<?php if(isset($GLOBALS['CORE_THEME']['homesliderid']) && $GLOBALS['CORE_THEME']['homesliderid'] != "" && $GLOBALS['CORE_THEME']['homeslider'] == 1 ){  

echo do_shortcode(stripslashes("[rev_slider ".$GLOBALS['CORE_THEME']['homesliderid']."]")); 

}else{ ?>
<?php if(!isset($GLOBALS['CORE_THEME']['home_section1']) || (isset($GLOBALS['CORE_THEME']['home_section1']) && $GLOBALS['CORE_THEME']['home_section1'] == '1' ) ){  ?>
<div class="homevideoslider hidden-xs">

    <div id="slider" class="owl-carousel" style="display:none;">
      <?php echo $slide_carousel; ?>
    </div>    
 
    <div class="homevideoslider_carousel">
       
        <div id="slider-carousel" class="owl-carousel">
         <?php echo $data_carousel; ?>
        </div>
        
    </div>
 
</div>

 
<script>
 
jQuery(window).load(function() {
 
  var sync1 = jQuery("#slider");
  var sync2 = jQuery("#slider-carousel");
 
  sync1.owlCarousel({
    singleItem : true,
    slideSpeed : 1000,
    navigation: false,
    pagination:false,
    afterAction : syncPosition,
    responsiveRefreshRate : 200,
  });
 
  sync2.owlCarousel({
    items : 5,
    itemsDesktop      : [1199,10],
    itemsDesktopSmall     : [979,10],
    itemsTablet       : [768,8],
    itemsMobile       : [479,4],
    pagination:false,
    responsiveRefreshRate : 100,
    afterInit : function(el){
      el.find(".owl-item").eq(0).addClass("synced");
    }
  });
 
  function syncPosition(el){
    var current = this.currentItem;
    jQuery("#slider-carousel")
      .find(".owl-item")
      .removeClass("synced")
      .eq(current)
      .addClass("synced")
    if(jQuery("#slider-carousel").data("owlCarousel") !== undefined){
      center(current)
    }
  }
 
  jQuery("#slider-carousel").on("click", ".owl-item", function(e){
    e.preventDefault();
    var number = jQuery(this).data("owlItem");
    sync1.trigger("owl.goTo",number);
  });
 
  function center(number){
    var sync2visible = sync2.data("owlCarousel").owl.visibleItems;
    var num = number;
    var found = false;
    for(var i in sync2visible){
      if(num === sync2visible[i]){
        var found = true;
      }
    }
 
    if(found===false){
      if(num>sync2visible[sync2visible.length-1]){
        sync2.trigger("owl.goTo", num - sync2visible.length+2)
      }else{
        if(num - 1 === -1){
          num = 0;
        }
        sync2.trigger("owl.goTo", num);
      }
    } else if(num === sync2visible[sync2visible.length-1]){
      sync2.trigger("owl.goTo", sync2visible[1])
    } else if(num === sync2visible[0]){
      sync2.trigger("owl.goTo", num-1)
    }
    
  }
 
});
</script>
<?php } ?>
<?php } ?>


 
<div class="col-md-300 hidden-xs" style="padding-left:0px;">
<?php dynamic_sidebar('Left Column'); ?>
</div>
<div class="col-md-820" style="padding-right:0px;">
    <div class="panel panel-default">
    <div class="panel-body">
    <?php $GLOBALS['item_class_size'] = "col-md-4 col-sm-4 col-xs-6 "; ?> 
        <div class="row wlt_search_results grid_style">
            <?php echo do_shortcode('[LISTINGS dataonly=1 show=9 custom="random"]'); ?> 
        </div>
    <?php unset($GLOBALS['item_class_size']); ?>
    </div>
    </div>
</div>

<div class="clearfix"></div>
 

<script>
jQuery(document).ready(function() { 
	
setTimeout(function(){equalheight('.grid_style .itemdata');  }, 2000); 
 

});
 </script>
<?php get_footer($CORE->pageswitch()); ?>