<?php 
if($_REQUEST['action'] == 'doregister') {   
   $ru_result = imwb_zonpress_register_user();
   echo $ru_result;
   die();
}
else if($_REQUEST['action'] == 'dosignin') {      
   $su_result = imwb_zonpress_signin_user();
   echo $su_result;
   die();      
}
else if($_REQUEST['action'] == 'wishlist') {
   include('wish-list.php');
   
   die();
}
else if($_REQUEST['action'] == 'profile') {
   include('profile.php');
   
   die();
}
get_header();  

global $page, $paged;

?>
<div class="container-fluid posts-wrapper">
 
<?php  if(imwb_zonpress_get_option('hiderotator') == 'N') { ?>
  <div class="row-fluid hidden-phone"> 
 <?php if(!is_active_sidebar("sidebar-featured-widget")){ ?>
  <div class="span2"></div>
  <?php } ?>
  <div id="mainCarousel" class="span8 carousel slide">
  <div class="carousel-inner">
  <?php 
     
   if(imwb_zonpress_get_option('fplistorder') == '0') {
     $args = Array('meta_key' => '_imwb_zonpress_post_ctr',
                   'orderby' => 'meta_value_num',
                   'order' => 'DESC',
                   'posts_per_page' => imwb_zonpress_get_option('postsperrotator'));                      
   }
   else {
     $args = Array('posts_per_page' => imwb_zonpress_get_option('postsperrotator'),
                   'orderby' => 'date',
                   'order' => 'DESC');
   }
   $fpexcludecats = imwb_zonpress_get_option('fpexcludecats');
   if(!empty($fpexcludecats)) {
      $cats = explode(",", htmlspecialchars(imwb_zonpress_get_option('fpexcludecats')) );
      foreach ($cats as $key => $value) {
         $cats[$key] = "-".$value;
      }      
      $args = array_merge($args, Array('cat' => implode(',', $cats)));
   }
   $thumnails = '';
   $carousel_query = new WP_Query($args); 

   while ($carousel_query->have_posts()) { $carousel_query->the_post(); ?>
     <div class="<?php echo $carousel_query->current_post == 0 ? 'active' : '';?> item" data-post-item="<?php echo get_the_ID(); ?>">
      <div class="content">
       <div class="title"><a href="<?php echo imwb_zonpress_get_post_permalink('title'); ?>" title="<?php the_title_attribute(); ?>" <?php echo imwb_zonpress_get_post_link_target();?>><?php the_title(); ?></a></div>
       <div class="stats"><?php echo get_the_date('F j, Y'); ?> - <a href="<?php comments_link(); ?>"><?php _e("Comment", "imwb_zonpress");?></a></div>
       <div class="description"><?php  echo do_shortcode(the_excerpt()); ?></div>
       <?php if(imwb_zonpress_is_product()) { ?>
          <div class="actions clearfix">
            <a class="btn btn-success pull-right" href="<?php echo imwb_zonpress_get_post_permalink('button'); ?>" title="<?php the_title_attribute(); ?>" <?php echo imwb_zonpress_get_post_link_target();?>><?php echo imwb_zonpress_get_option('postprdbtntxt');?></a>
            <?php if(imwb_zonpress_get_option('fphideprice') != "Y") imwb_zonpress_post_price();?>
            <?php if(imwb_zonpress_post_onwishlist($user_ID, get_the_ID())) { ?>
              <span class="wishlistlink"><?php echo imwb_zonpress_get_option('onwishlisttext');?></span>
            <?php } else { 
               if (is_user_logged_in()) { ?>
                 <a class="wishlistlink" href="" data-post-item='<?php echo get_the_ID(); ?>'><?php echo imwb_zonpress_get_option('addwishlisttext');?></a>
               <?php } else { ?>
                 <a class="smcf-login wishlistlink" href="<?php bloginfo( 'url' );?>/wp-login.php"><?php echo imwb_zonpress_get_option('addwishlisttext');?></a>
            <?php } } ?>         
          </div>
       <?php } ?>
       </div>
       <a href="<?php echo imwb_zonpress_get_post_permalink('image'); ?>" title="<?php the_title_attribute(); ?>" <?php echo imwb_zonpress_get_post_link_target();?>><?php imwb_zonpress_the_post_thumbnail(get_the_ID(), "300", "250"); ?></a>
     </div>
  <?php 
     $thumnails .= '<li><a href="#'.$carousel_query->current_post.'" data-post-item="'.get_the_ID().'" '.($carousel_query->current_post == 0 ? 'class="active"' : '').'>'.imwb_zonpress_get_post_thumbnail (get_the_ID(), "50", "50", false ).'</a></li>';
     } ?>
  </div>
   <a class="carousel-control left" href="#mainCarousel" data-slide="prev">&lsaquo;</a>
   <a class="carousel-control right" href="#mainCarousel" data-slide="next">&rsaquo;</a>
  </div>
  
  <?php if(is_active_sidebar("sidebar-featured-widget")){ ?>
      <div id="sidebar-featured-widget" class="content_sidebar span4"> 
        <?php dynamic_sidebar("sidebar-featured-widget"); ?>
     </div>
 <?php } ?>
  </div>

  <div class="row-fluid carousel-thumbs-row">
  <?php echo (imwb_zonpress_get_option('hidesocialbtns') == 'Y' && !is_active_sidebar("sidebar-featured-widget"))? '<div class="span2"></div>' : '';?>
   <div id="carousel-thumbs" class="span8 hidden-phone">
    <ul class="carousel-thumbs">
     <?php echo $thumnails; ?>
    </ul>
   </div>
   <?php if(imwb_zonpress_get_option('hidesocialbtns') == 'N') { ?>
      <div class="span4"> 
      <nav id="social-navigation">
        <ul>
      <?php if(imwb_zonpress_get_option('twitteruser') != '') { ?>
        <li><a target="_blank" href="https://twitter.com/<?php echo imwb_zonpress_get_option('twitteruser'); ?>"><img src="<?php echo get_template_directory_uri();?>/images/TwitterBtn.png"></a></li>
      <?php } 
         if(imwb_zonpress_get_option('facebookuser') != '') { ?> 
        <li><a target="_blank" href="https://www.facebook.com/<?php echo imwb_zonpress_get_option('facebookuser'); ?>"><img src="<?php echo get_template_directory_uri();?>/images/FacebookBtn.png"></a></li>
      <?php } 
         if(imwb_zonpress_get_option('googleuser') != '') { ?>    
        <li><a target="_blank" href="https://plus.google.com/<?php echo imwb_zonpress_get_option('googleuser'); ?>/posts"><img src="<?php echo get_template_directory_uri();?>/images/GPlusBtn.png"></a></li>
      <?php } 
         if(imwb_zonpress_get_option('pinterestuser') != '') { ?>    
        <li><a target="_blank" href="http://pinterest.com/<?php echo imwb_zonpress_get_option('pinterestuser'); ?>"><img src="<?php echo get_template_directory_uri();?>/images/PinterestBtn.png"></a></li>
      <?php }
         if(imwb_zonpress_get_option('reddituser') != '') { ?>    
           <li><a target="_blank" href="http://www.reddit.com/user/<?php echo imwb_zonpress_get_option('reddituser'); ?>"><img src="<?php echo get_template_directory_uri();?>/images/RedditBtn.png"></a></li>
         <?php } 
         if(imwb_zonpress_get_option('rssfeedurl') != '') { ?>    
           <li><a target="_blank" href="<?php echo imwb_zonpress_get_option('rssfeedurl'); ?>"><img src="<?php echo get_template_directory_uri();?>/images/RssFeedBtn.png"></a></li>
         <?php } ?>
      
        </ul>
        </nav>
      </div>
   <?php } ?>
  </div>

<?php } 

if(imwb_zonpress_get_option('posthidemenu') == 'N')   { 
?>
<div class="row-fluid post-navigation">
 <div class="span8">
    <nav id="post-navigation">
    <ul>
     <?php if(imwb_zonpress_get_option('postmrsmenu') == 'N')   { ?>
        <li <?php echo (imwb_zonpress_list_order() == 'mrs' && is_home()) ? 'class="current"' : '';?>>
           <a href="<?php bloginfo( 'url' );?>?so=mrs"><?php echo imwb_zonpress_get_option('postmrsmenutxt');?></a>
        </li>
     <?php } 
       if(imwb_zonpress_get_option('posttrsmenu') == 'N')   { ?>
        <li <?php echo (imwb_zonpress_list_order() == 'trs' && is_home()) ? 'class="current"' : '';?>>
           <a href="<?php bloginfo( 'url' );?>?so=trs"><?php echo imwb_zonpress_get_option('posttrsmenutxt');?></a>
        </li>
     <?php } 
       if(imwb_zonpress_get_option('posthpsmenu') == 'N')   { ?>
        <li <?php echo (imwb_zonpress_list_order() == 'hps' && is_home()) ? 'class="current"' : '';?>>
           <a href="<?php bloginfo( 'url' );?>?so=hps"><?php echo imwb_zonpress_get_option('posthpsmenutxt');?></a>
        </li>
     <?php }
       if(imwb_zonpress_get_option('postlpsmenu') == 'N')   { ?>
        <li <?php echo (imwb_zonpress_list_order() == 'lps' && is_home()) ? 'class="current"' : '';?>>
           <a href="<?php bloginfo( 'url' );?>?so=lps"><?php echo imwb_zonpress_get_option('postlpsmenutxt');?></a>
        </li>
     <?php } ?>
    </ul>
    </nav>
 </div>
 <div class="span4">
 <?php if(imwb_zonpress_get_option('hidesearch') == 'N') { ?>
   <div id="search"> <?php get_search_form(); ?> </div>
 <?php } ?>  
 </div>
</div>
<?php 
}

$num_ads_to_show = imwb_zonpress_get_ads_option('numads');
$ads_shown = 0;
$posts_b4_ads = mt_rand(imwb_zonpress_get_ads_option('postsshownfrom'), imwb_zonpress_get_ads_option('postsshownto'));
?>

<div class="row-fluid">
<ul class="post-list">
<?php while(have_posts()): the_post();?> 

<?php 
if($num_ads_to_show && $ads_shown < $num_ads_to_show && $posts_b4_ads == 0) {
   $posts_b4_ads = mt_rand(imwb_zonpress_get_ads_option('postsshownfrom'), imwb_zonpress_get_ads_option('postsshownto'));
   $advert = imwb_zonpress_get_advert($ads_shown++);
?>
<li class="post advert">
<h1 class="title"><?php echo $advert['title'];?></h1>
<div class="content">
<?php echo do_shortcode($advert['content']);?>
</div>
</li>
<?php } 

   $zp_is_product = false;
   $ctr_track_attr = "";
   if(imwb_zonpress_is_product()) {
      $zp_is_product = true;
      $ctr_track_attr = " class='zp-ctr-track' data-post-item='".get_the_ID()."'";  
   }
?>
<li class="post<?php echo $zp_is_product ? " zp-product" : "";?>">
<?php  if(imwb_zonpress_get_option('showtitle') == '1') { ?>
 <h1 class="title">
  <a <?php echo $ctr_track_attr;?> href="<?php echo imwb_zonpress_get_post_permalink('title'); ?>" title="<?php the_title_attribute(); ?>" <?php echo imwb_zonpress_get_post_link_target();?>><?php echo do_shortcode(the_title());?></a>
 </h1>
<?php } ?>
 <div class="post_thumb">
    <a <?php echo $ctr_track_attr;?> href="<?php echo imwb_zonpress_get_post_permalink('image'); ?>" title="<?php the_title_attribute(); ?>" <?php echo imwb_zonpress_get_post_link_target();?>>
  <?php imwb_zonpress_the_post_thumbnail(get_the_ID(), "300", "250"); ?>
  </a>
 </div>
<?php if(imwb_zonpress_get_option('postcontent') != 'N') { ?>
	<div class="description">
	<?php echo do_shortcode(get_the_excerpt()); ?>
	</div>
   <?php if($zp_is_product) { 
      imwb_zonpress_update_imp();
   ?>
   	<div class="actions clearfix">
   	  <a class="btn btn-success pull-right zp-ctr-track" data-post-item='<?php echo get_the_ID(); ?>' href="<?php echo imwb_zonpress_get_post_permalink('button'); ?>" title="<?php the_title_attribute(); ?>" <?php echo imwb_zonpress_get_post_link_target();?>><?php echo imwb_zonpress_get_option('postprdbtntxt');?></a>
   	  <?php if(imwb_zonpress_get_option('fphideprice') != "Y") imwb_zonpress_post_price();?>
   	  <?php if(imwb_zonpress_post_onwishlist($user_ID, get_the_ID())) { ?>
   	    <span class="wishlistlink"><?php echo imwb_zonpress_get_option('onwishlisttext');?></span>
   	  <?php } else { 
          if (is_user_logged_in()) { ?>
     	      <a class="wishlistlink" href="" data-post-item='<?php echo get_the_ID(); ?>'><?php echo imwb_zonpress_get_option('addwishlisttext');?></a>
   	    <?php } else { ?>
   	    <a class="smcf-login wishlistlink" href="<?php bloginfo( 'url' );?>/wp-login.php"><?php echo imwb_zonpress_get_option('addwishlisttext');?></a>
   	  <?php } } ?>         
   	</div>
   <?php } ?>	
<?php } ?> 
</li>

<?php 
$posts_b4_ads--;
endwhile; 

if($num_ads_to_show && $ads_shown < $num_ads_to_show && $posts_b4_ads == 0) {
   $advert = imwb_zonpress_get_advert($ads_shown);
?>
<li class="post advert">
<h1 class="title"><?php echo $advert['title'];?></h1>
<div class="content">
<?php echo do_shortcode($advert['content']);?>
</div>
</li>
<?php } ?>
</ul>
</div>
<div class="row-fluid">
<div class="span12">
<?php imwb_zonpress_page_numbers(); ?>
</div>
</div>
<?php if(is_home() && imwb_zonpress_get_option('homepagescripts') != '') { ?>
<div class="row-fluid">
<div class="span12" style="padding: 3px 0 0 3px;">
<?php echo imwb_zonpress_get_option('homepagescripts'); ?>
</div>
</div>
<?php } ?>
</div>
<?php get_footer(); ?>