<?php
/**
 * Copyright © 2015 PlazaThemes.com. All rights reserved.

 * @author PlazaThemes Team <contact@plazathemes.com>
 */
 
if($this->getEnable()):
$banners = $block->getBannerSlider();
?>

<div class="pt-banner-container">
   <ul class="ptowl"> 
   <?php $i = 1; ?>
    <?php foreach ($banners as $banner): ?>
	<?php 
		$store_ids = explode(",",$banner['store_id']);
		if(in_array($this->getIdStore(),$store_ids)): ?>
		<?php $url_image = $this->getMediaFolder().$banner['image']; ?>
            <li>
				<?php if($banner['click_url']): ?>
					<a href="<?php echo $banner['click_url'] ?>" class="pt-url">
				<?php endif; ?>
					<img alt="<?php echo $banner['image_alt'] ?>" src="<?php echo $url_image; ?>"/>
				<?php if($banner['click_url']): ?>
					</a>
				<?php endif; ?>
				
				<div id="pt-banner-caption<?php echo $i; ?>" class="pt-caption pt-banner-caption">
					
					<div class="pt-banner-content ptslider-<?php echo $i?>">
						<?php if($banner['name']): ?><h1 class="pt-title1"><span><?php echo __($banner['name']) ?></span></h1><?php endif; ?>						
						<?php if($banner['title1']): ?><h2 class="pt-title2" ><span><?php echo __($banner['title1']) ?></span></h2><?php endif; ?>
						<?php if($banner['title2']): ?><h3 class="pt-title3"><span><?php echo __($banner['title2']) ?></span></h3><?php endif; ?>
						<?php if($banner['description']): ?><div class="pt-banner-des">
							<p><?php echo __($banner['description']) ?></p>
						</div><?php endif; ?>
						
						<?php if($banner['click_url']): ?>
							<a href="<?php echo $banner['click_url'] ?>" class="pt-url">More details</a>
						<?php endif; ?>
						
					</div>	
				</div>				
            </li>
		<?php $i++; ?>            
    <?php endif; ?>            
    <?php endforeach; ?>            
    </ul>
</div>

<script type="text/javascript">
require([
  "jquery",
  "owlcarousel/minjs"
 ], function($,owlCarousel){
		$(document).ready(function(){
			$(".pt-banner-container .ptowl").owlCarousel({
				singleItem: true,
				autoPlay : 5000,
				//autoPlay : false,
				items : 1,
				itemsDesktop : [1199,1],
				itemsDesktopSmall : [980,1],
				itemsTablet: [768,1],
				itemsMobile : [479,1],
				slideSpeed : 500,
				paginationSpeed : 500,
				rewindSpeed : 500,
				addClassActive: true,
				navigation : true,
				stopOnHover : true,
				pagination : false,
				scrollPerPage:true,
				afterMove: nextslide,
				afterInit: nextslide,
			});
			function nextslide() {
				$(".pt-banner-container .owl-item .pt-banner-caption").css('display','none');
				$(".pt-banner-container .owl-item .pt-banner-caption").removeClass('pt-caption')
				$(".pt-banner-container .owl-item.active .pt-banner-caption").css('display','block');
				
				var heading = $('.pt-banner-container .owl-item.active .pt-banner-caption').clone().removeClass();
				$('.pt-banner-container .owl-item.active .pt-banner-caption').remove();
				$('.pt-banner-container .owl-item.active>li').append(heading);
				$('.pt-banner-container .owl-item.active>li>div').addClass('pt-banner-caption pt-caption');
			};
		});
	});
</script>

<?php endif; ?>