{* include custom header.php file instead of common/header.latte *}
{includePart ait-theme/elements/google-map/header}

<div id="{$htmlId}" class="{$htmlClass}">

	{var $displayPosts = $el->option(displayPosts)}
	{var $items        = array()}
	{var $myExcerpts   = array()}
	{var $args         = array()}
	{var $categories   = $el->option(category)}
	{var $specialPage  = $el->option(specialPage)}
	{var $themeOptions = $options->theme }

	{if $displayPosts == "yes"}

		{* ******************************************************** *}
		{* for NORMAL PAGE                          			*}
		{* ******************************************************** *}
		{var $args = array(
			'post_type'      => 'post',
			'category__in'   => !(is_array($categories) and sizeof($categories) == 1 and $categories[0] == 0) ? $categories,
			'posts_per_page' => -1,
		)}

		{* ******************************************************** *}
		{* for SINGLE POST PAGE                          			*}
		{* ******************************************************** *}

		{if $wp->isSingular(post)}
			{* disable specialPage settings if post doesn't have specified gps coordinates *}
			{var $meta = $post->meta('post-gps-metabox')->map}
			{if $meta['latitude'] == 0 && $meta['longitude'] == 0}
				{var $specialPage = false}
			{/if}

			{var $args = array(
				'post_type'      => 'post',
				'p'              => $specialPage ? $post->id,
				'posts_per_page' => -1,
			)}
		{/if}


		{* ******************************************************** *}
		{* for SINGLE AUTHOR PAGE                          			*}
		{* ******************************************************** *}

		{if $wp->isAuthor}

			{var $args = array(
				'post_type'      => 'post',
				'author'         => $specialPage ? $author->id,
				'posts_per_page' => -1,
			)}
		{/if}

		{* ******************************************************** *}
		{* for CATEGORY PAGE        	                  			*}
		{* ******************************************************** *}

		{if $wp->isCategory()}

			{var $args = array(
				'post_type'      => 'post',
				'category__in'   => $specialPage ? $category->id,
				'posts_per_page' => -1,
			)}
		{/if}

		{* ******************************************************** *}
		{* for ARCHIVE DATE PAGE        	                  		*}
		{* ******************************************************** *}

		{if is_date()}
			{var $args = array(
				'post_type'      => 'post',
				'date_query' => $specialPage ? array(
					array(
						'year'  => get_the_time('Y'),
						'month' => get_the_time('m'),
					),
				),
				'posts_per_page' => -1,
			)}
		{/if}



		{customQuery as $query, $args}

		{if $query->havePosts}
			{customLoop from $query as $item}
				{? $items[$item->id] = $item}
				{? $myExcerpts[$item->id] = $item->excerpt(15)}
			{/customLoop}
		{/if}

	{/if}

	<div id="{$htmlId}-container" class="google-map-container {if $el->option('mapLoadType') == "request" }on-request{/if}" style="height: {$el->option(height)}px;">
		{if $el->option('mapLoadType') == "request" }
			<div class="request-map">
				{if $themeOptions->google->requestDescriptionText}
					<div class="request-map-description">
						{!$themeOptions->google->requestDescriptionText}
					</div>
				{/if}
				<div class="request-map-button">
					<a href="#" class="ait-sc-button simple">
					      <span class="container">
					            <span class="text">
					                  <span class="title">{if $themeOptions->google->requestButtonText}{!$themeOptions->google->requestButtonText}{else}{__ 'Show the map'}{/if}</span>
					            </span>
					      </span>
					</a>
				</div>
			</div>
		{/if}
	</div>

	{var $addressCode = ""}
	{var $centerCode = ""}

	{if $displayPosts and $wp->isSingular(post)}
		{var $meta = $post->meta('post-gps-metabox')->map}
		{var $latLngCode = $meta['latitude'] == 0 && $meta['longitude'] == 0 ? "" : "latLng:[{$meta['latitude']}, {$meta['longitude']}],"}
		{var $centerCode = $meta['latitude'] == 0 && $meta['longitude'] == 0 ? "" : "center:[{$meta['latitude']}, {$meta['longitude']}],"}
	{else}
		{if $el->option(address) == ''}
			{var $centerCode = ($el->option(latitude) == 0 && $el->option(longitude) == 0 ) ? "" : "center:[{$el->option('latitude')}, {$el->option('longitude')}],"}
		{else}
			{var $addressCode = "address: '{$el->option('address')}',"}
		{/if}



	{/if}

	{var $scrollWheel = $el->option(mousewheelZoom) ? "true" : "false"}

	{includePart "ait-theme/elements/google-map/javascript"}

</div>