<?php
/**
 * @package twentysixteen
 * @subpackage business-blocks
 * Converts a HEX value to RGB.
 */
function business_blocks_hex2rgb( $color ) {
	$color = trim( $color, '#' );

	if ( strlen( $color ) === 3 ) {
		$r = hexdec( substr( $color, 0, 1 ) . substr( $color, 0, 1 ) );
		$g = hexdec( substr( $color, 1, 1 ) . substr( $color, 1, 1 ) );
		$b = hexdec( substr( $color, 2, 1 ) . substr( $color, 2, 1 ) );
	} elseif ( strlen( $color ) === 6 ) {
		$r = hexdec( substr( $color, 0, 2 ) );
		$g = hexdec( substr( $color, 2, 2 ) );
		$b = hexdec( substr( $color, 4, 2 ) );
	} else {
		return array();
	}

	return array(
		'red'   => $r,
		'green' => $g,
		'blue'  => $b,
	);
}

function business_blocks_do_home_slider(){
	if(is_front_page() && get_theme_mod('slider_in_home_page' , 1)) 
		get_template_part('templates/featured', 'slider' );
}
add_action('business_blocks_home_slider', 'business_blocks_do_home_slider');

function business_blocks_do_before_header(){
	get_template_part( 'templates/top', 'banner' ); 
}

add_action('business_blocks_before_header', 'business_blocks_do_before_header');


function business_blocks_do_header(){

		get_template_part( 'templates/header', 'contacts' );
		
		do_action('business_blocks_before_header');
		
		$business_blocks_header = get_theme_mod('header_layout', 1);
		
		if ($business_blocks_header == 0) {
			echo '<div id="site-header-main" class="site-header-main">';
			get_template_part( 'templates/header', 'default' );
			//woocommerce layout
		} else if($business_blocks_header == 1 && class_exists('WooCommerce')){
			get_template_part( 'templates/woocommerce', 'header' ); 
			//list layout
		} else if ($business_blocks_header == 2){
			get_template_part( 'templates/header', 'list' );
		} else {
			//default layout
			echo '<div id="site-header-main" class="site-header-main">';
			get_template_part( 'templates/header', 'default' );
		}
		
		if(is_front_page()){
			get_template_part( 'templates/header', 'hero' );
			get_template_part( 'templates/header', 'shortcode' );
		}
		
		/* end header div in default header layouts */
		if ($business_blocks_header == 0) {
			echo '</div><!-- .site-header-main -->';
		}

}

add_action('business_blocks_header', 'business_blocks_do_header');

