{include $el->common('header')}

<div id="{$htmlId}" class="elm-item-organizer {$htmlClass}">

	{customQuery as $query,
		type    => post,
		tax     => category,
		cat     => $el->option(category),
		limit   => $el->option(count),
		orderby => $el->option(orderby),
		order 	=> $el->option(order)
	}

	{if $query->havePosts}
		{var $layout = $el->option->layout}
		{var $textRows = $el->option->textRows}
		{var $addInfo = $el->option->addInfo}
		{var $imagePresent = ''}

		{* Unified variables and data *}
		{if $layout == box}
			{var $enableCarousel  = $el->option->boxEnableCarousel}
			{var $boxAlign 		  = $el->option->boxAlign}
			{var $numOfRows       = $el->option->boxRows}
			{var $numOfColumns    = $el->option->boxColumns}
			{var $imageHeight     = $el->option->boxImageHeight}
			{var $imgWidth = 640}
		{else}
			{var $enableCarousel  = $el->option->listEnableCarousel}
			{var $numOfRows       = $el->option->listRows}
			{var $numOfColumns    = $el->option->listColumns}
			{var $imageHeight     = $el->option->listImageHeight}
			{var $imgWidth = 220}
		{/if}

		{if $enableCarousel}
			<div class="loading"><span class="ait-preloader">{!__ 'Loading&hellip;'}</span></div>
		{/if}

		{if $layout == box}
			<div n:class='elm-item-organizer-container, "column-{$numOfColumns}", "layout-{$layout}", $enableCarousel ? carousel-container : carousel-disabled,' data-cols="{$numOfColumns}" data-first="1" data-last="{= ceil($query->postCount / $numOfRows)}">
			{customLoop from $query as $item}

				{if $item->hasImage  and $imageHeight != 'none'} {var $imagePresent = 'yes'} {else} {var $imagePresent = ''} {/if}

				{if $enableCarousel and $iterator->isFirst($numOfRows)}
					<div n:class="item-box, $enableCarousel ? carousel-item">
				{/if}
				<div n:class='item, "item{$iterator->counter}", $enableCarousel ? carousel-item, $iterator->isFirst($numOfColumns) ? item-first, $iterator->isLast($numOfColumns) ? item-last, $imagePresent ? image-present, $boxAlign ? $boxAlign' data-id="{$iterator->counter}">
					<a href="{$item->permalink}">
						<div class="item-title"><h3>{!$item->title}</h3></div>

						{if $imagePresent}
							{var $ratio = explode(":", $imageHeight)}
							{var $imgHeight = ($imgWidth / $ratio[0]) * $ratio[1]}
							<div class="item-thumbnail">

								<div class="item-date-wrap">
									<div class="item-date">{$item->dateI18n('j F Y')}</div>
								</div>

								<div class="item-thumbnail-wrap">
									<img src="{imageUrl $item->imageUrl, width => $imgWidth, height => $imgHeight, crop => 1}" alt="{!$item->title}">
								</div>
							</div>
						{/if}

					</a>

					{if $addInfo}
					<div class="item-categories">
						{foreach $item->categories as $cat}
							{var $term_link = get_term_link($cat->id, 'category')}
							<a href="{$term_link}"><span class="item-category">{!$cat->title}</span></a>
						{/foreach}
					</div>
					{/if}

					<div class="item-text">
						{if !$imagePresent}
							<div class="item-date-wrap">
								<div class="item-date">{$item->dateI18n('j F Y')}</div>
							</div>
						{/if}
						<div class="item-excerpt txtrows-{$textRows}"><p>{!$item->excerpt(200)|striptags}</p></div>
						{if $addInfo}<a href="{$item->permalink}" class="button">{__ 'Read More'}</a>{/if}
					</div>
				</div>

				{if $enableCarousel and $iterator->isLast($numOfRows)}
					</div>
				{/if}
			{/customLoop}
			</div>
		{else}
			<div n:class='elm-item-organizer-container, "column-{$numOfColumns}", "layout-{$layout}", $enableCarousel ? carousel-container : carousel-disabled,' data-cols="{$numOfColumns}" data-first="1" data-last="{= ceil($query->postCount / $numOfRows)}">
			{customLoop from $query as $item}

				{if $item->hasImage  and $imageHeight != 'none'} {var $imagePresent = 'yes'} {else} {var $imagePresent = ''} {/if}

				{if $enableCarousel and $iterator->isFirst($numOfRows)}
					<div n:class="item-box, $enableCarousel ? carousel-item">
				{/if}

				<div n:class='item, "item{$iterator->counter}", $enableCarousel ? carousel-item, $iterator->isFirst($numOfColumns) ? item-first, $iterator->isLast($numOfColumns) ? item-last, $imagePresent ? image-present'	data-id="{$iterator->counter}">
					<a href="{$item->permalink}">

						<div class="item-thumbnail">
							<div class="item-date">{$item->dateI18n('j M')}</div>
							{if $imagePresent}
								{var $ratio = explode(":", $imageHeight)}
								{var $imgHeight = ($imgWidth / $ratio[0]) * $ratio[1]}

								<div class="item-thumbnail-wrap">
									<img src="{imageUrl $item->imageUrl, width => $imgWidth, height => $imgHeight, crop => 1}" alt="{!$item->title}">
								</div>
							{/if}
						</div>

						<div class="item-title"><h3>{!$item->title}</h3></div>
					</a>

					<div class="item-text">
						<div class="item-excerpt txtrows-{$textRows}"><p>{!$item->excerpt(200)|striptags}</p></div>
					</div>

					{if $addInfo}
					<div class="item-info">
						<!--<div class="item-author">{__ 'posted by '}<a href="{get_author_posts_url( $item->author->id )}">{!$item->author}</a></div>-->
						<div class="item-categories">
							{foreach $item->categories as $cat}
								{var $term_link = get_term_link($cat->id, 'category')}
								<a href="{$term_link}"><span class="item-category">{!$cat->title}</span></a>
							{/foreach}
						</div>
					</div>
					{/if}
				</div>

				{if $enableCarousel and $iterator->isLast($numOfRows)}
					</div>
				{/if}
			{/customLoop}
			</div>
		{/if}
	{else}
		<div class="elm-item-organizer-container">
			<div class="alert alert-info">
				{_x 'Posts', 'name of element'}&nbsp;&nbsp;|&nbsp;&nbsp;{__ 'Info: There are no items created, add some please.'}
			</div>
		</div>
	{/if}
</div>

{includePart "ait-theme/elements/posts/javascript", enableCarousel => $enableCarousel}

{if $el->option->layout == 'icon' && $enableCarousel}
<div class="carousel-icon-arrows">
	<div class="carousel-arrow-left icon-arrow icon-arrow-left" style="cursor: pointer;">&lt;</div>
	<div class="carousel-arrow-right icon-arrow icon-arrow-right" style="cursor: pointer;">&gt;</div>
</div>

</div> <!-- icon-container-content -->
{/if}


{if $el->option->layout != 'icon' && $enableCarousel}
<div class="carousel-standard-arrows">
	<div class="carousel-arrow-left standard-arrow standard-arrow-left" style="cursor: pointer;">&lt;</div>
	<div class="carousel-arrow-right standard-arrow standard-arrow-right" style="cursor: pointer;">&gt;</div>
</div>
<div class="carousel-bottom-arrows">
	<div class="carousel-nav-text">{__ 'Navigation'}</div>
	<div class="carousel-arrow-left bottom-arrow bottom-arrow-left" style="cursor: pointer;">&lt;</div>
	<div class="carousel-arrow-right bottom-arrow bottom-arrow-right" style="cursor: pointer;">&gt;</div>
</div>
{/if}