<?php

// Prevent Direct Access
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$main_background = get_theme_mod('main_background');
$main_slides = get_theme_mod('main_slides', array());
$main_video = get_theme_mod('main_video');
$main_text_color = get_theme_mod('main_text_color', 'white');

// Define variables
$background = '';

// If main background is defined, set background image
if( $main_background ){
	$background = wp_get_attachment_url($main_background);
}

// If there are any slides
if( $main_slides ){

	// If there is only one slide
	if(count($main_slides) == 1){

		// If it has background, dismiss the main background because it is useless
		if($main_slides[0]['background']){
			$background = '';
		}
	}
}
?>

<div id="home" class="rev_slider_wrapper fullwidthbanner-container" <?php if($background){ echo 'style="background-image:url('.$background.');"'; } ?>>

	<?php
	if( $main_video ){
		$ext = pathinfo($main_video, PATHINFO_EXTENSION);

		if($ext == 'webm'){ $mime = 'video/webm'; }
		else if($ext == 'ogg' || $ext == 'ogv'){ $mime = 'video/ogg'; }
		else{ $mime = 'video/mp4'; }
	?>
	<div class="video_container">
		<video class="bg-vid" autoplay="" loop="" muted="">
			<source src="<?php echo $main_video ?>" type="<?php echo $mime ?>" />
		</video>
	</div>
	<?php } ?>

	<div id="maxo-main" class="rev_slider fullwidthabanner" style="display:none;" data-version="5.0.7">

		<?php if( $main_slides ){ ?>
		
		<ul>
		
			<?php
			$slide_index = 0;
			foreach($main_slides as $slide){
				$slide_index++;
			?>
			
			
			<?php if( $slide['content_side'] == 'center' ){ ?>
			<li data-index="rs-<?php echo $slide_index ?>" data-transition="fade" data-slotamount="default" data-easein="Power3.easeInOut" data-easeout="Power3.easeInOut" data-masterspeed="1500" class="text-center">
				
				<?php if($slide['background']){ ?>
				<img src="<?php echo wp_get_attachment_url($slide['background']) ?>" alt="" data-bgposition="center center" data-bgfit="cover" data-bgrepeat="no-repeat" class="rev-slidebg" data-bgparallax="10" data-no-retina>
				<?php } ?>

				<?php if( $slide['top_text'] || $slide['bottom_text'] ){ ?>
				<div class="tp-caption tp-resizeme <?php echo $main_text_color ?>color text-center" data-x="['center','center','center','center']" data-hoffset="['0','0','0','0']" data-y="['180','140','150','95']" data-voffset="['0','0','0','0']" data-whitespace="nowrap" data-transform_idle="o:1;" data-transform_in="z:0;rX:0;rY:0;rZ:0;sX:0.9;sY:0.9;skX:0;skY:0;opacity:0;s:1500;e:Power3.easeInOut;" data-transform_out="y:[100%];s:1000;e:Power2.easeInOut;s:1000;e:Power2.easeInOut;" data-mask_out="x:inherit;y:inherit;s:inherit;e:inherit;" data-start="1000" data-splitin="none" data-splitout="none" data-responsive_offset="on">
					<h1 class="text-center">
						<?php if($slide['top_text']){ echo $slide['top_text']; } ?>
						<?php if($slide['bottom_text']){ echo '<span>'.$slide['bottom_text'].'</span>'; } ?>
					</h1>
				</div>
				<?php } ?>

				<?php if( $slide['button_1_text'] || $slide['button_2_text'] ){ ?>
				<div class="tp-caption tp-resizeme text-center" data-x="['center','center','center','center']" data-hoffset="['0','0','0','0']" data-y="['370','310','320','260']" data-voffset="['0','0','0','0']" data-whitespace="nowrap" data-transform_idle="o:1;" data-transform_in="y:[100%];z:0;rX:0deg;rY:0;rZ:0;sX:1;sY:1;skX:0;skY:0;opacity:0;s:1500;e:Power4.easeInOut;" data-transform_out="s:900;e:Power2.easeInOut;s:900;e:Power2.easeInOut;" data-start="2500" data-splitin="none" data-splitout="none" data-responsive_offset="on">

					<?php if($slide['button_1_text']){ ?>
					<a href="<?php echo $slide['button_1_link'] ?>" class="button <?php echo $slide['button_1_color'] ?> <?php echo $main_text_color ?>_text"><?php echo $slide['button_1_text'] ?></a>
					<?php } ?>

					<?php if($slide['button_2_text']){ ?>
					<a href="<?php echo $slide['button_2_link'] ?>" class="button <?php echo $slide['button_2_color'] ?> <?php echo $main_text_color ?>_text"><?php echo $slide['button_2_text'] ?></a>
					<?php } ?>

				</div>
				<?php } ?>
				
			</li>
			<?php } ?>
			
			
			<?php if( (is_rtl() && $slide['content_side'] == 'left') || (!is_rtl() && $slide['content_side'] == 'right') ){ ?>
			<li data-index="rs-<?php echo $slide_index ?>" data-transition="fade" data-slotamount="default" data-easein="Power3.easeInOut" data-easeout="Power3.easeInOut" data-masterspeed="1500" class="text-left">
				
				<?php if($slide['background']){ ?>
				<img src="<?php echo wp_get_attachment_url($slide['background']) ?>" alt="" data-bgposition="center center" data-bgfit="cover" data-bgrepeat="no-repeat" class="rev-slidebg" data-bgparallax="10" data-no-retina>
				<?php } ?>

				<?php if( $slide['top_text'] || $slide['bottom_text'] ){ ?>
				<div class="tp-caption tp-resizeme <?php echo $main_text_color ?>color" data-x="['left','left','left','left']" data-hoffset="['50','40','30','20']" data-y="['180','140','150','95']" data-voffset="['0','0','0','0']" data-whitespace="nowrap" data-transform_idle="o:1;" data-transform_in="z:0;rX:0;rY:0;rZ:0;sX:0.9;sY:0.9;skX:0;skY:0;opacity:0;s:1500;e:Power3.easeInOut;" data-transform_out="y:[100%];s:1000;e:Power2.easeInOut;s:1000;e:Power2.easeInOut;" data-mask_out="x:inherit;y:inherit;s:inherit;e:inherit;" data-start="1000" data-splitin="none" data-splitout="none" data-responsive_offset="on">
					<h1>
						<?php if($slide['top_text']){ echo $slide['top_text']; } ?>
						<?php if($slide['bottom_text']){ echo '<span>'.$slide['bottom_text'].'</span>'; } ?>
					</h1>
				</div>
				<?php } ?>

				<?php if( $slide['button_1_text'] || $slide['button_2_text'] ){ ?>
				<div class="tp-caption tp-resizeme" data-x="['left','left','left','left']" data-hoffset="['50','40','30','20']" data-y="['370','310','320','260']" data-voffset="['0','0','0','0']" data-whitespace="nowrap" data-transform_idle="o:1;" data-transform_in="y:[100%];z:0;rX:0deg;rY:0;rZ:0;sX:1;sY:1;skX:0;skY:0;opacity:0;s:1500;e:Power4.easeInOut;" data-transform_out="s:900;e:Power2.easeInOut;s:900;e:Power2.easeInOut;" data-start="2500" data-splitin="none" data-splitout="none" data-responsive_offset="on">

					<?php if($slide['button_1_text']){ ?>
					<a href="<?php echo $slide['button_1_link'] ?>" class="button <?php echo $slide['button_1_color'] ?> <?php echo $main_text_color ?>_text"><?php echo $slide['button_1_text'] ?></a>
					<?php } ?>

					<?php if($slide['button_2_text']){ ?>
					<a href="<?php echo $slide['button_2_link'] ?>" class="button <?php echo $slide['button_2_color'] ?> <?php echo $main_text_color ?>_text"><?php echo $slide['button_2_text'] ?></a>
					<?php } ?>

				</div>
				<?php } ?>
				
			</li>
			<?php } ?>
			
			
			<?php if( (is_rtl() && $slide['content_side'] == 'right') || (!is_rtl() && $slide['content_side'] == 'left') ){ ?>
			<li data-index="rs-<?php echo $slide_index ?>" data-transition="fade" data-slotamount="default" data-easein="Power3.easeInOut" data-easeout="Power3.easeInOut" data-masterspeed="1500" class="text-right">
				
				<?php if($slide['background']){ ?>
				<img src="<?php echo wp_get_attachment_url($slide['background']) ?>" alt="" data-bgposition="center center" data-bgfit="cover" data-bgrepeat="no-repeat" class="rev-slidebg" data-bgparallax="10" data-no-retina>
				<?php } ?>

				<?php if( $slide['top_text'] || $slide['bottom_text'] ){ ?>
				<div class="tp-caption tp-resizeme <?php echo $main_text_color ?>color text-left" data-x="['right','right','right','right']" data-hoffset="['50','40','30','20']" data-y="['180','140','150','95']" data-voffset="['0','0','0','0']" data-whitespace="nowrap" data-transform_idle="o:1;" data-transform_in="z:0;rX:0;rY:0;rZ:0;sX:0.9;sY:0.9;skX:0;skY:0;opacity:0;s:1500;e:Power3.easeInOut;" data-transform_out="y:[100%];s:1000;e:Power2.easeInOut;s:1000;e:Power2.easeInOut;" data-mask_out="x:inherit;y:inherit;s:inherit;e:inherit;" data-start="1000" data-splitin="none" data-splitout="none" data-responsive_offset="on">
					<h1>
						<?php if($slide['top_text']){ echo $slide['top_text']; } ?>
						<?php if($slide['bottom_text']){ echo '<span>'.$slide['bottom_text'].'</span>'; } ?>
					</h1>
				</div>
				<?php } ?>

				<?php if( $slide['button_1_text'] || $slide['button_2_text'] ){ ?>
				<div class="tp-caption tp-resizeme" data-x="['right','right','right','right']" data-hoffset="['50','40','30','20']" data-y="['370','310','320','260']" data-voffset="['0','0','0','0']" data-whitespace="nowrap" data-transform_idle="o:1;" data-transform_in="y:[100%];z:0;rX:0deg;rY:0;rZ:0;sX:1;sY:1;skX:0;skY:0;opacity:0;s:1500;e:Power4.easeInOut;" data-transform_out="s:900;e:Power2.easeInOut;s:900;e:Power2.easeInOut;" data-start="2500" data-splitin="none" data-splitout="none" data-responsive_offset="on">
					
					<?php if($slide['button_1_text']){ ?>
					<a href="<?php echo $slide['button_1_link'] ?>" class="button <?php echo $slide['button_1_color'] ?> <?php echo $main_text_color ?>_text"><?php echo $slide['button_1_text'] ?></a>
					<?php } ?>
					
					<?php if($slide['button_2_text']){ ?>
					<a href="<?php echo $slide['button_2_link'] ?>" class="button <?php echo $slide['button_2_color'] ?> <?php echo $main_text_color ?>_text"><?php echo $slide['button_2_text'] ?></a>
					<?php } ?>
					
				</div>
				<?php } ?>
				
			</li>
			<?php } ?>
			
			
			<?php } ?>
			
		</ul>
		
		<?php } ?>
		
	</div>
	
</div>