<?php

// no direct access
defined('_JEXEC') or die;
K2HelperUtilities::setDefaultImage($item, 'itemlist', $item->params);
$k2_image_hash = md5("Image".$item->id);
?>

<?php if($item->params->get('catItemImage') && !empty($item->image)): ?>
<!-- Added K2Multiimages -->
<!-- Item Image -->
<style>.catItemBody > .catItemImageBlock { display: none; }</style>
<div class="catItemImageBlockContainer">
	<script>
		var config<?php echo $item->id; ?> = {
			slideshowGroup: 'gallery<?php echo $item->id; ?>',
			wrapperClassName: 'dark',
			dimmingOpacity: 0.7,
			align: 'center',
			transitions: ['expand', 'crossfade'],
			fadeInOut: true,
			wrapperClassName: 'borderless floating-caption',
			marginLeft: 100,
			marginBottom: 80,
			numberPosition: 'caption'
		};

		hs.addSlideshow({
			slideshowGroup: 'gallery<?php echo $item->id; ?>',
			interval: 5000,
			repeat: false,
			useControls: true,
			fixedControls: 'fit',
			overlayOptions: {
				className: 'text-controls',
				opacity: 0.75,
				position: 'bottom center',
				offsetX: 0,
				offsetY: -15,
				hideOnMouseOut: true
			}
		});
	</script>
	<?php 		
	$filecount = 1;
	$bcount = 0;
	
	while(
	JFile::exists(JPATH_SITE.'/media/k2/items/cache/'.$k2_image_hash."_".$filecount."_XL.jpg") ||
	(JFile::exists(JPATH_SITE.'/media/k2/items/cache/'.$k2_image_hash."_XL.jpg") && $filecount == 1)
	) {
		if($filecount == 1) {
			$path_full = JURI::root() . 'media/k2/items/cache/'.$k2_image_hash."_XL.jpg";
			$path_thumb = JURI::root() . 'media/k2/items/cache/'.$k2_image_hash."_S.jpg";
		}
		else {
			$path_full = JURI::root() . 'media/k2/items/cache/'.$k2_image_hash."_".$filecount."_XL.jpg";
			$path_thumb = JURI::root() . 'media/k2/items/cache/'.$k2_image_hash."_".$filecount."_S.jpg";			
		}
	?> 
	
	<?php if($filecount > 1 && $bcount != 1) {
		echo "<div class=\"catItemImageBlock-container\" style=\"text-align: center; display: ;none;\">";
		$bcount = 1;
		}
	?>
	  <div class="catItemImageBlock" <?php if($filecount > 1) : ?>style="display: inline-block;"<?php endif; ?>>
		  <span class="itemImage">
			<a class="highslide" href="<?php echo $path_full; ?>" title="<?php echo K2HelperUtilities::cleanHtml($item->title); ?>" onclick="return hs.expand(this, config<?php echo $item->id; ?>)" rel="<?php echo K2HelperUtilities::cleanHtml($item->title); ?>">
				<?php if($filecount == 1) : ?>
					<img src="<?php echo $path_full; ?>" alt="<?php echo K2HelperUtilities::cleanHtml($item->title); ?>" style="width: <?php echo $item->imageWidth; ?>px; height: auto; max-width: 100%;" />
				<?php else : ?>
					<img src="<?php echo $path_thumb; ?>" alt="<?php echo K2HelperUtilities::cleanHtml($item->title); ?>" style="width:auto; height:100px;" />
				<?php endif; ?>
			</a>
		  </span>
		  <div class="clr"></div>
	  </div>
	  
	  <?php 
		if($filecount > 1 && !JFile::exists(JPATH_SITE.'/media/k2/items/cache/'.$k2_image_hash."_".($filecount+1)."_XL.jpg")) {
			echo "<div class=\"clr\"></div></div>";
		}
	  
		$filecount++;
	  }
	  ?>
	  <div class="clr"></div>
  </div>
 <!--// Added K2Multiimages -->
<?php endif; ?> 