<?php
if ( ! defined( 'ABSPATH' ) ) {
	die( '-1' );
}

/**
 * Shortcode attributes
 * @var $atts
 * @var $el_class
 * @var $full_width
 * @var $full_height
 * @var $equal_height
 * @var $columns_placement
 * @var $content_placement
 * @var $parallax
 * @var $parallax_image
 * @var $css
 * @var $el_id
 * @var $video_bg
 * @var $video_bg_url
 * @var $video_bg_parallax
 * @var $parallax_speed_bg
 * @var $parallax_speed_video
 * @var $content - shortcode content
 * Shortcode class
 * @var $this WPBakeryShortCode_VC_Row
 */
 $el_class = $full_height = $full_width = $content_placement = $parallax = $parallax_image = $css = $el_id = $video_bg = $video_bg_url = $video_bg_parallax = '';
 $output = $after_output = '';
 $atts = vc_map_get_attributes( $this->getShortcode(), $atts );
 extract( $atts );

 wp_enqueue_script( 'wpb_composer_front_js' );

 $el_class = $this->getExtraClass( $el_class );

 $css_classes = array(
 	$el_class,
 	vc_shortcode_custom_css_class( $css ),
 );
 $wrapper_attributes = array();
 // build attributes for wrapper
if ( ! empty( $el_id ) ) {
	$wrapper_attributes[] = 'id="' . esc_attr( $el_id ) . '"';
}
$output = '';

$style = '';

$bg_img = wp_get_attachment_image_src($bg_img, 'full');


$section_style = "vc_section";

if ($background_style == 'color') {
  if ($bg_color != '') {
    $section_style = "bg_section";
	  $style .= " background-color:".$bg_color.";";
		if (empty($border_top)) {
			$border_top = "#e5e5e5";
		}
		if (empty($border_bottom)) {
			$border_bottom = "#e5e5e5";
		}
  }
}elseif($background_style == 'cover_image' || $background_style == 'video') {
  $section_style = "bg_section";
	if (!empty($bg_color)) {
  	$style .= " background-color:".$bg_color.";";
	}
	if (!empty($bg_img) && ($media_src != 'links')) {
  	$style .= " background-size:cover; background-image:url(".$bg_img[0].");";
	} else if (!empty($bg_img_url)) {
		$style .= " background-size:cover; background-image:url(".$bg_img_url.");";
	}
}elseif($background_style == 'repeated_image') {
  $section_style = "bg_section";
	if (!empty($bg_color)) {
  	$style .= " background-color:".$bg_color.";";
	}
	if (!empty($bg_img) && ($media_src != 'links')) {
  	$style .= " background-size:repeat; background-image:url(".$bg_img[0].");";
	} else if (!empty($bg_img_url)) {
		$style .= " background-size:repeat; background-image:url(".$bg_img_url.");";
	}
}

if (!empty($border_top)) {
		$style .= "border-top-color:".$border_top.";";
}
if (!empty($border_bottom)) {
	$style .= "border-bottom-color:".$border_bottom.";";
}
if ($padding_bottom != '') {
	$style .= "padding-bottom:".$padding_bottom."px;";
}
if ($padding_top != '') {
	$style .= "padding-top:".$padding_top."px;";
}
if (isset($margin_top) && $margin_top != '') {
  $style .= " margin-top:".$margin_top."px;";
}
if (isset($margin_bottom) && $margin_bottom != '') {
  $style .= " margin-bottom:".$margin_bottom."px;";
}
$class = "";

if ($parallax == "yes") {
  $class .= " parallax_section";
}

if ($style != '') {
	$style = 'style="'.$style.'"';
}

$output .= "<div class='".$effect." ".$section_style." " .$class. "' ".$style."'>";

if ($background_style == 'video') {

if ($media_src == "links") {
	$bg_img = $bg_img_url;
	$videomv = $videomv_url;
	$videowebm = $videowebm_url;
	$videoogg = $videoogg_url;
	$videomp = $videomp_url;

	if (!empty($bg_img)) {
	$output .= '<video class="video_overlay" preload="auto"  autoplay="autoplay" poster="'. $bg_img .'" loop muted="muted">';
	}
	if (!empty($videomv)) {

	$output .= '<source src="'. $videomv .'" type="video/mp4" />';
	}
	if (!empty($videowebm)) {

	$output .= '<source src="'. $videowebm .'" type="video/webm" />';
	}
	if (!empty($videoogg)) {
	$output .= '<source src="'. $videoogg .'" type="video/ogg" />';
	}
	if (!empty($videomp)) {
	$output .= '<source src="'. $videomp .'" />';
	}
	if (!empty($bg_img)) {
	$output .= '<img alt="Video Background" src="'. $bg_img .'" style="position:absolute;left:0;" width="100%" title="Video playback is not supported by your browser" />';
	$output .= '</video>';
	}
} else {
  $videomv = wp_get_attachment_url($videomv);
  $videowebm = wp_get_attachment_url($videowebm);
  $videoogg = wp_get_attachment_url($videoogg);
  $videomp = wp_get_attachment_url($videomp);

	if (!empty($bg_img)) {
	$output .= '<video class="video_overlay" preload="auto"  autoplay="autoplay" poster="'. $bg_img[0] .'" loop muted="muted">';
	}
	if (!empty($videomv)) {
		$output .= '<source src="'. $videomv .'" type="video/mp4" />';
	}
	if (!empty($videowebm)) {
	$output .= '<source src="'. $videowebm .'" type="video/webm" />';
	}
	if (!empty($videoogg)) {
	$output .= '<source src="'. $videoogg .'" type="video/ogg" />';
	}
	if (!empty($videomp)) {
	$output .= '<source src="'. $videomp .'" />';
	}
	if (!empty($bg_img)) {
	$output .= '<img alt="Video Background" src="'. $bg_img[0] .'" style="position:absolute;left:0;" width="100%" title="Video playback is not supported by your browser" />';
	$output .= '</video>';
	}
}



$output .= '<div class="color_overlay"></div>';

}

if (!empty($container)) {
	if ($container == 'container') {
		$con_style = 'container';
	} else {
		$con_style = 'fluid-container';
	}
} else {
	$con_style = 'fluid-container';
}


$output .= "<div class='row'><div class=' ".$con_style."'>";
if ($title) {
  $output .= '<h3 class="title center_title thin_title">';
	if ($icon) { $output .= '<i class="'.$icon.'"></i>'; }
  $output .= do_shortcode(htmlspecialchars_decode($title));
  $output .= '</h3>';
}
$output .= wpb_js_remove_wpautop( $content );

$output .= '</div></div></div>';


echo $output;