<?php
/**
* The main template file.
*
*/

get_header();
?>
<?php
global $enable_home_page;
if ( ('page' == get_option( 'show_on_front' ) && ( '' != get_option( 'page_for_posts' ) ) && $wp_query->get_queried_object_id() == get_option( 'page_for_posts' )) || $enable_home_page =="" ) {

	    $meris_sidebar          = get_post_meta($wp_query->get_queried_object_id(), '_meris_layout', true );
	
		switch($meris_sidebar){
			case "left":
			get_template_part("roop","left-sidebar");
			break;
			case "right":
			get_template_part("roop","right-sidebar");
			break;
			case "both":
			get_template_part("roop","both-sidebar");
			break;
			case "none":
			get_template_part("roop","no-sidebar");
			break;
			default:
			get_template_part("content","blog-list");
			break;
			}
	  
}else{
?>
<div class="homepage-main" role="main">
<?php echo meris_get_default_slider();?>
<?php 
	$home_sections = get_option('_meris_home_page_sections');
    if($home_sections !=""){
    $home_sections_array = json_decode($home_sections, true);
    if(is_array($home_sections_array)){
    $s  = 1;
	foreach($home_sections_array as $secion_item){
 
    $layout           = isset($secion_item["layout"])?$secion_item["layout"]:"boxed";
	$column           = isset($secion_item["column"])?$secion_item["column"]:"1";
	
	$name             = isset($secion_item["name"])?$secion_item["name"]:"";
	$widgets_name     = !empty($secion_item["widgets_name"])?$secion_item["widgets_name"]:array($name);
	$subdivision      = !empty($secion_item["subdivision"])?$secion_item["subdivision"]:array("12");
	
	
	$color            = isset($secion_item["background"]["color"])?$secion_item["background"]["color"]:"";
	$image            = isset($secion_item["background"]["image"])?$secion_item["background"]["image"]:"";
	$repeat           = isset($secion_item["background"]["repeat"])?$secion_item["background"]["repeat"]:"";
	$position         = isset($secion_item["background"]["position"])?$secion_item["background"]["position"]:"";
	$attachment       = isset($secion_item["background"]["attachment"])?$secion_item["background"]["attachment"]:"";
	$background_style = ""; 
	
    if ($image!="") {
	$background_style .= "background-image:url('".$image. "');background-repeat:".$repeat.";background-position:".$position.";background-attachment:".$attachment.";";
	}
	
	if( $color !=""){
	$background_style .= "background-color:".$color.";";
	 }
	
	if($layout == "full"){
		$container = 'full-width';
		}else{
	    $container = 'container';
			}
	
	$column_num       = count($subdivision);
	$i               = 1;
   
		   echo '<section class="home-section '.sanitize_title($name).'" style="'.$background_style.'"><div class="'.$container.'">';
	
						
		   foreach($subdivision as $subdivision_item){
			   if($column_num > 1){
				 $widget_name = $name." Column ".$i;
				 }else{
				 $widget_name = $name;
				 }
			echo '<div class="col-md-'.$subdivision_item.'">';
		   dynamic_sidebar(sanitize_title($widget_name));
		   echo '</div>';
		   $i++;
		   }
		   echo '<div class="clear"></div></div></section>';
	       $s++;
	         }
		   }
	   }
?>
</div>
<?php }?>
<?php get_footer();?>