<?php
	// Metabox
	$confin_id    = ( isset( $post ) ) ? $post->ID : 0;
	$confin_id    = ( is_home() ) ? get_option( 'page_for_posts' ) : $confin_id;
	$confin_meta  = get_post_meta( $confin_id, 'page_type_metabox', true );
	if ($confin_meta && is_page()) {
		$confin_title_bar_padding = $confin_meta['title_area_spacings'];
	} else { $confin_title_bar_padding = ''; }
	// Padding - Theme Options
	if ($confin_title_bar_padding && $confin_title_bar_padding !== 'padding-default') {
		$confin_title_top_spacings = $confin_meta['title_top_spacings'];
		$confin_title_bottom_spacings = $confin_meta['title_bottom_spacings'];
		if ($confin_title_bar_padding === 'padding-custom') {
			$confin_title_top_spacings = $confin_title_top_spacings ? 'padding-top:'. confin_check_px($confin_title_top_spacings) .';' : '';
			$confin_title_bottom_spacings = $confin_title_bottom_spacings ? 'padding-bottom:'. confin_check_px($confin_title_bottom_spacings) .';' : '';
			$confin_custom_padding = $confin_title_top_spacings . $confin_title_bottom_spacings;
		} else {
			$confin_custom_padding = '';
		}
	} else {
		$confin_title_bar_padding = cs_get_option('title_bar_padding');
		$confin_titlebar_top_padding = cs_get_option('titlebar_top_padding');
		$confin_titlebar_bottom_padding = cs_get_option('titlebar_bottom_padding');
		if ($confin_title_bar_padding === 'padding-custom') {
			$confin_titlebar_top_padding = $confin_titlebar_top_padding ? 'padding-top:'. confin_check_px($confin_titlebar_top_padding) .';' : '';
			$confin_titlebar_bottom_padding = $confin_titlebar_bottom_padding ? 'padding-bottom:'. confin_check_px($confin_titlebar_bottom_padding) .';' : '';
			$confin_custom_padding = $confin_titlebar_top_padding . $confin_titlebar_bottom_padding;
		} else {
			$confin_custom_padding = '';
		}
	}
	// Banner Type - Meta Box
	if ($confin_meta && is_page()) {
		$confin_banner_type = $confin_meta['banner_type'];
	} else { $confin_banner_type = ''; }
	// Header Style
	if ($confin_meta) {
	  $confin_header_design  = $confin_meta['select_header_design'];
	  $confin_hide_breadcrumbs  = $confin_meta['hide_breadcrumbs'];
	} else {
	  $confin_header_design  = cs_get_option('select_header_design');
	  $confin_hide_breadcrumbs = cs_get_option('need_breadcrumbs');
	}
	if ( $confin_header_design === 'default') {
	  $confin_header_design_actual  = cs_get_option('select_header_design');
	} else {
	  $confin_header_design_actual = ( $confin_header_design ) ? $confin_header_design : cs_get_option('select_header_design');
	}
	if ( $confin_header_design_actual == 'style_three') {
		$overly_class = ' overly';
	} else {
		$overly_class = ' ';
	}
	// Overlay Color - Theme Options
		if ($confin_meta && is_page()) {
			$confin_bg_overlay_color = $confin_meta['titlebar_bg_overlay_color'];
			$title_color = isset($confin_meta['title_color']) ? $confin_meta['title_color'] : '';
		} else { $confin_bg_overlay_color = ''; }
		if (!empty($confin_bg_overlay_color)) {
			$confin_bg_overlay_color = $confin_bg_overlay_color;
			$title_color = $title_color;
		} else {
			$confin_bg_overlay_color = cs_get_option('titlebar_bg_overlay_color');
			$title_color = cs_get_option('title_color');
		}
		$e_uniqid        = uniqid();
		$inline_style  = '';
		if ( $confin_bg_overlay_color ) {
		 $inline_style .= '.page-title-'.$e_uniqid .'.page-title {';
		 $inline_style .= ( $confin_bg_overlay_color ) ? 'background-color:'. $confin_bg_overlay_color.';' : '';
		 $inline_style .= '}';
		}
		if ( $title_color ) {
		 $inline_style .= '.page-title-'.$e_uniqid .'.page-title h2, .page-title-'.$e_uniqid .'.page-title .breadcrumb li, .page-title-'.$e_uniqid .'.page-title .breadcrumbs ul li a {';
		 $inline_style .= ( $title_color ) ? 'color:'. $title_color.';' : '';
		 $inline_style .= '}';
		}
		// add inline style
		add_inline_style( $inline_style );
		$styled_class  = ' page-title-'.$e_uniqid;
	// Background - Type
	if( $confin_meta ) {
		$title_bar_bg = $confin_meta['title_area_bg'];
	} else {
		$title_bar_bg = '';
	}

	$confin_custom_header = get_custom_header();
	$header_text_color = get_theme_mod( 'header_textcolor' );
	$background_color = get_theme_mod( 'background_color' );
	if( isset( $title_bar_bg['image'] ) && ( $title_bar_bg['image'] ||  $title_bar_bg['color'] ) ) {
	  extract( $title_bar_bg );
	  $confin_background_image       = ( ! empty( $image ) ) ? 'background-image: url(' . esc_url($image) . ');' : '';
	  $confin_background_repeat      = ( ! empty( $image ) && ! empty( $repeat ) ) ? ' background-repeat: ' . esc_attr( $repeat) . ';' : '';
	  $confin_background_position    = ( ! empty( $image ) && ! empty( $position ) ) ? ' background-position: ' . esc_attr($position) . ';' : '';
	  $confin_background_size    = ( ! empty( $image ) && ! empty( $size ) ) ? ' background-size: ' . esc_attr($size) . ';' : '';
	  $confin_background_attachment    = ( ! empty( $image ) && ! empty( $attachment ) ) ? ' background-attachment: ' . esc_attr( $attachment ) . ';' : '';
	  $confin_background_color       = ( ! empty( $color ) ) ? ' background-color: ' . esc_attr( $color ) . ';' : '';
	  $confin_background_style       = ( ! empty( $image ) ) ? $confin_background_image . $confin_background_repeat . $confin_background_position . $confin_background_size . $confin_background_attachment : '';
	  $confin_title_bg = ( ! empty( $confin_background_style ) || ! empty( $confin_background_color ) ) ? $confin_background_style . $confin_background_color : '';
	} elseif( $confin_custom_header->url ) {
		$confin_title_bg = 'background-image:  url('. esc_url( $confin_custom_header->url ) .');';
	} else {
		$confin_title_bg = '';
	}
	if($confin_banner_type === 'hide-title-area') { // Hide Title Area
	} elseif($confin_meta && $confin_banner_type === 'revolution-slider') { // Hide Title Area
		echo do_shortcode($confin_meta['page_revslider']);
	} else {
	?>
 <!-- start page-title -->
  <section class="page-title <?php echo esc_attr( $overly_class.' '.$styled_class.' '.$confin_banner_type ); ?>" style="<?php echo esc_attr( $confin_title_bg ); ?>">
      <div class="container">
          <div class="row">
              <div class="col col-xs-12" style="<?php echo esc_attr( $confin_custom_padding ); ?>" >
                  <div class="title">
                      <h2><?php echo confin_title_area(); ?></h2>
                  </div>
                   <?php if ( !$confin_hide_breadcrumbs && function_exists( 'breadcrumb_trail' )) { breadcrumb_trail();  } ?>
              </div>
          </div> <!-- end row -->
      </div> <!-- end container -->
  </section>
  <!-- end page-title -->
<?php } ?>