<?php
/*
 * ------------------------------------------------------------------------
 * JA Property TPL
 * ------------------------------------------------------------------------
 * Copyright (C) 2004-2011 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
 * @license - Copyrighted Commercial Software
 * Author: J.O.O.M Solutions Co., Ltd
 * Websites:  http://www.joomlart.com -  http://www.joomlancers.com
 * This file may not be redistributed in whole or significant part.
 * ------------------------------------------------------------------------
*/


defined('_JEXEC') or die;
$item  			= $displayData;
$context		= '';
$params  		= @ json_decode($item->attribs, true);
$desc 			= '';
$thumbnail = '';

if (!isset($params['ctm_gallery'])) return;
$gallery = $params['ctm_gallery'];

if(!$thumbnail) {
	$images = json_decode($item->images);
	$thumbnail = @$images->image_intro;
}
if($context == 'icon') {
	$galleryId = 'ja-gallery-icon-'.$item->id;
} else {
	$galleryId = 'ja-gallery-list-'.$item->id;
}


// data to show image
$data = array();
$data['item'] = $item;

if (is_array($displayData) && isset($displayData['img-size'])) $data['size'] = $displayData['img-size'];

if (isset($thumbnail) && !empty($thumbnail)) {
	$data['image'] = $thumbnail;
	$data['alt'] = $item->title;
	$data['caption'] = $desc;
}
?>

<div id="<?php echo $galleryId; ?>" class="item-image ja-gallery-list carousel slide" data-ride="carousel">
	<div class="carousel-inner" role="listbox">
		<?php if (isset($thumbnail) && !empty($thumbnail)) : ?>
		<div class="item active">
			<?php echo JLayoutHelper::render('joomla.content.image.image', $data); ?>
		</div>
		<?php endif; ?>

		<?php if(is_array($gallery) && count($gallery['src']) > 1):
			$images = array();
			$count = 0;
			foreach($gallery['src'] as $index => $src) {
				$img = new stdClass();
				$img->href = JUri::root(true).'/'.$src;
				$img->title = $gallery['caption'][$index];
		?>
		<div class="item <?php if ( !(isset($thumbnail) && !empty($thumbnail)) && $count==0) echo 'active'; ?>">	
			<img src="<?php echo $img->href; ?>" alt="<?php echo $img->title; ?>" />
		</div>
		<?php
			$count++; }
		?>
		<?php endif; ?>
	</div>

	<!-- Controls -->
  <a class="left carousel-control" href="#<?php echo $galleryId; ?>" role="button" data-slide="prev">
    <span class="ion-ios-arrow-round-back" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#<?php echo $galleryId; ?>" role="button" data-slide="next">
    <span class="ion-ios-arrow-round-forward" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

<?php if(JFactory::getApplication()->input->get('view') == 'article') :?>
<span style="display: none;" itemprop="image" itemscope itemtype="https://schema.org/ImageObject">
	<img
		src="<?php echo JURI::base(); ?>/templates/<?php echo JFactory::getApplication()->getTemplate() ?>/images/logo.png"
		alt="" itemprop="image"/>
  <meta itemprop="height" content="auto" />
  <meta itemprop="width" content="auto" />
  <meta itemprop="url" content="<?php echo JURI::base(); ?>/templates/<?php echo JFactory::getApplication()->getTemplate() ?>/images/logo.png" />
</span>
<?php endif ;?>