<?php

/**
 * @package     Joomla.Site
 * @subpackage  Templates.cassiopeia
 *
 * @copyright   (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;

/** @var Joomla\CMS\Document\HtmlDocument $this */

$app   = Factory::getApplication();
$input = $app->getInput();
$wa    = $this->getWebAssetManager();

// Browsers support SVG favicons
$this->addHeadLink(HTMLHelper::_('image', 'joomla-favicon.svg', '', [], true, 1), 'icon', 'rel', ['type' => 'image/svg+xml']);
$this->addHeadLink(HTMLHelper::_('image', 'favicon.ico', '', [], true, 1), 'alternate icon', 'rel', ['type' => 'image/vnd.microsoft.icon']);
$this->addHeadLink(HTMLHelper::_('image', 'joomla-favicon-pinned.svg', '', [], true, 1), 'mask-icon', 'rel', ['color' => '#000']);

// Detecting Active Variables
$option   = $input->getCmd('option', '');
$view     = $input->getCmd('view', '');
$layout   = $input->getCmd('layout', '');
$task     = $input->getCmd('task', '');
$itemid   = $input->getCmd('Itemid', '');
$sitename = htmlspecialchars($app->get('sitename'), ENT_QUOTES, 'UTF-8');
$menu     = $app->getMenu()->getActive();
$pageclass = $menu !== null ? $menu->getParams()->get('pageclass_sfx', '') : '';

// Color Theme
$paramsColorName = $this->params->get('colorName', 'colors_standard');
$assetColorName  = 'theme.' . $paramsColorName;
$wa->registerAndUseStyle($assetColorName, 'media/templates/site/cassiopeia/css/global/' . $paramsColorName . '.css');

// Use a font scheme if set in the template style options
$paramsFontScheme = $this->params->get('useFontScheme', false);
$fontStyles       = '';

if ($paramsFontScheme) {
    if (stripos($paramsFontScheme, 'https://') === 0) {
        $this->getPreloadManager()->preconnect('https://fonts.googleapis.com/', ['crossorigin' => 'anonymous']);
        $this->getPreloadManager()->preconnect('https://fonts.gstatic.com/', ['crossorigin' => 'anonymous']);
        $this->getPreloadManager()->preload($paramsFontScheme, ['as' => 'style', 'crossorigin' => 'anonymous']);
        $wa->registerAndUseStyle('fontscheme.current', $paramsFontScheme, [], ['media' => 'print', 'rel' => 'lazy-stylesheet', 'onload' => 'this.media=\'all\'', 'crossorigin' => 'anonymous']);

        if (preg_match_all('/family=([^?:]*):/i', $paramsFontScheme, $matches) > 0) {
            $fontStyles = '--cassiopeia-font-family-body: "' . str_replace('+', ' ', $matches[1][0]) . '", sans-serif;
			--cassiopeia-font-family-headings: "' . str_replace('+', ' ', isset($matches[1][1]) ? $matches[1][1] : $matches[1][0]) . '", sans-serif;
			--cassiopeia-font-weight-normal: 400;
			--cassiopeia-font-weight-headings: 700;';
        }
    } else {
        $wa->registerAndUseStyle('fontscheme.current', $paramsFontScheme, ['version' => 'auto'], ['media' => 'print', 'rel' => 'lazy-stylesheet', 'onload' => 'this.media=\'all\'']);
        $this->getPreloadManager()->preload($wa->getAsset('style', 'fontscheme.current')->getUri() . '?' . $this->getMediaVersion(), ['as' => 'style']);
    }
}

// Enable assets
$wa->usePreset('template.cassiopeia.' . ($this->direction === 'rtl' ? 'rtl' : 'ltr'))
    ->useStyle('template.active.language')
    ->useStyle('template.user')
    ->useScript('template.user')
    ->addInlineStyle(":root {
		--hue: 214;
		--template-bg-light: #f0f4fb;
		--template-text-dark: #495057;
		--template-text-light: #ffffff;
		--template-link-color: var(--link-color);
		--template-special-color: #001B4C;
		$fontStyles
	}");

// Override 'template.active' asset to set correct ltr/rtl dependency
$wa->registerStyle('template.active', '', [], [], ['template.cassiopeia.' . ($this->direction === 'rtl' ? 'rtl' : 'ltr')]);


$hasClass = '';

if ($this->countModules('sidebar-left', true)) {
    $hasClass .= ' has-sidebar-left';
}

if ($this->countModules('sidebar-right', true)) {
    $hasClass .= ' has-sidebar-right';
}

// Container
$wrapper = $this->params->get('fluidContainer') ? 'wrapper-fluid' : 'wrapper-static';

$this->setMetaData('viewport', 'width=device-width, initial-scale=1');

$stickyHeader = $this->params->get('stickyHeader') ? 'position-sticky sticky-top' : '';

// Defer fontawesome for increased performance. Once the page is loaded javascript changes it to a stylesheet.
$wa->getAsset('style', 'fontawesome')->setAttribute('rel', 'lazy-stylesheet');

$pathTmp = '/media/templates/site/cassiopeia/';
?>
<!DOCTYPE html>
<html lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">
<head>
    <jdoc:include type="metas" />
	<link href="<?php echo $pathTmp?>css/style.css" rel="stylesheet" />
	<link href="<?php echo $pathTmp?>css/grid.css" rel="stylesheet" />
	<link href="<?php echo $pathTmp?>css/slick.css" rel="stylesheet" />
	<link href="<?php echo $pathTmp?>css/jquery.fancybox.min.css" rel="stylesheet" />
	<jdoc:include type="styles" />
	<script src="<?php echo $pathTmp?>js/jquery.js"></script>
	<script src="<?php echo $pathTmp?>js/jquery.fancybox.min.js" defer></script>
	<script src="<?php echo $pathTmp?>js/slick.js" defer></script> 
	<jdoc:include type="scripts" />
</head> 

<body class="site <?php echo $option
    . ' ' . $wrapper
    . ' view-' . $view
    . ($layout ? ' layout-' . $layout : ' no-layout')
    . ($task ? ' task-' . $task : ' no-task')
    . ($itemid ? ' itemid-' . $itemid : '')
    . ($pageclass ? ' ' . $pageclass : '')
    . $hasClass
    . ($this->direction == 'rtl' ? ' rtl' : '');
?>">
	<header class="header container-header full-width<?php echo $stickyHeader ? ' ' . $stickyHeader : ''; ?>">
		<div class="container-header">
			<div class="d-flex hdr-box">
				<div class="hdr-left">
					<a class="d-flex brand-logo" href="<?php echo $this->baseurl; ?>/">
						<img loading="eager" decoding="async" src="<?php echo $this->baseurl; ?>/images/logotype.svg" alt="<?php echo ($sitename); ?>">
					</a>
				</div>
				<div class="hdr-center">
					<?php if ($this->countModules('menu', true) || $this->countModules('city-mail', true)) : ?>
						<div class="hdr-center-top">
							<div class="box_hdr_mobile"></div>
							<?php if ($this->countModules('menu', true)) : ?>
								<jdoc:include type="modules" name="menu" style="none" />
							<?php endif; ?>
							<?php if ($this->countModules('city-mail', true)) : ?>
								<div class="city-mail">
									<jdoc:include type="modules" name="city-mail" style="none" />
								</div>
							<?php endif; ?>
							
						</div>
					<?php endif; ?>
					<?php if ($this->countModules('search', true) || $this->countModules('cat', true)) : ?>
						<div class="hdr-center-bottom">
							<?php if ($this->countModules('cat', true)) : ?>
								<jdoc:include type="modules" name="cat" style="none" />
							<?php endif; ?>
							<?php if ($this->countModules('search', true)) : ?>
								<jdoc:include type="modules" name="search" style="none" />
							<?php endif; ?>
						</div>
					<?php endif; ?>
				</div>
				<div id="default-box" class="hdr-right">
					<div class="box_form">
						<?php if ($this->countModules('topbar')) : ?>
							<div class="hdr-topbar">
								<jdoc:include type="modules" name="topbar" style="none" />
							</div>
						<?php endif; ?>
						<?php if ($this->countModules('below-top')) : ?>
							<div class="hdr-below-top">
								<jdoc:include type="modules" name="below-top" style="none" />
							</div>
						<?php endif; ?>
					</div>
				</div>
			</div>
		</div>
	</header>

    <div class="site-grid">
        <?php if ($this->countModules('banner', true)) : ?>
            <div class="container-banner full-width">
                <jdoc:include type="modules" name="banner" style="none" />
            </div>
        <?php endif; ?>

        <?php if ($this->countModules('top-a', true)) : ?>
        <div class="grid-child container-top-a">
            <jdoc:include type="modules" name="top-a" style="card" />
        </div>
        <?php endif; ?>

        <?php if ($this->countModules('top-b', true)) : ?>
        <div class="grid-child container-top-b">
            <jdoc:include type="modules" name="top-b" style="card" />
        </div>
        <?php endif; ?>

        <?php if ($this->countModules('sidebar-left', true)) : ?>
        <div class="grid-child container-sidebar-left">
            <jdoc:include type="modules" name="sidebar-left" style="card" />
        </div>
        <?php endif; ?>
		
        <div class="grid-child container-component">
            <jdoc:include type="modules" name="main-top" style="card" />
            <jdoc:include type="message" />
            <main>
            <jdoc:include type="component" />
            </main>
            <jdoc:include type="modules" name="main-bottom" style="card" />
        </div>

        <?php if ($this->countModules('sidebar-right', true)) : ?>
        <div class="grid-child container-sidebar-right">
            <jdoc:include type="modules" name="sidebar-right" style="card" />
        </div>
        <?php endif; ?>

        <?php if ($this->countModules('bottom-a', true)) : ?>
        <div class="grid-child container-bottom-a">
            <jdoc:include type="modules" name="bottom-a" style="card" />
        </div>
        <?php endif; ?>

        <?php if ($this->countModules('bottom-b', true)) : ?>
        <div class="grid-child container-bottom-b">
            <jdoc:include type="modules" name="bottom-b" style="card" />
        </div>
        <?php endif; ?>
    </div>
 
    <footer class="footer container-footer custom-width-container">
        <div class="container">
			<div class="row row-ftr">
				<div class="col-12 col-md-4">
					<div class="ftr-item ftr-item-first">
						<?php if ($this->countModules('footer1', true)) : ?>
							<jdoc:include type="modules" name="footer1" style="none" />
						<?php endif; ?>
						<div class="ftr_copiright d-none d-md-block">
							&copy; <?php echo ($sitename); ?>, 2013 - <?php echo date('Y'); ?>
						</div>
					</div>
				</div>
				<div class="d-none d-md-block col-12 col-md-4">
					<?php if ($this->countModules('footer2', true) || $this->countModules('footer3', true)) : ?>
						<div class="ftr-item">
							<div class="row">
								<?php if ($this->countModules('footer2', true)) : ?>
									<div class="col-12 col-xl-6">
										<jdoc:include type="modules" name="footer2" style="none" />
									</div>
								<?php endif; ?>
								<?php if ($this->countModules('footer3', true)) : ?>
									<div class="ftr-double-menu col-12 col-xl-6">
										<jdoc:include type="modules" name="footer3" style="none" />
									</div>
								<?php endif; ?>
							</div>
						</div>
					<?php endif; ?>
				</div>
				<div class="col-12 col-md-4">
					<div class="ftr-item ftr-item-last">
						<?php if ($this->countModules('footer4', true)) : ?>
							<jdoc:include type="modules" name="footer4" style="none" />
						<?php endif; ?>
						<div class="ftr_ip d-block d-md-none">ИП Кивенко Андрей Сергеевич</div>
						<div class="ftr_copiright d-block d-md-none">
							&copy; <?php echo ($sitename); ?>, 2013 - <?php echo date('Y'); ?>
						</div>
						<div class="zbull">
							<a href="https://zbull.ru" target="_blank">Создано с любовью в <span>Zbull.ru</span></a>
						</div>
					</div>
				</div>
			</div>
        </div>
    </footer>
    <jdoc:include type="modules" name="debug" style="none" />
	<jdoc:include type="modules" name="debug-double" style="none" />
	<a href="javascript:void(0);" class="back-to-top-link">
		<span class="icon-arrow-up icon-fw" aria-hidden="true"></span>
	</a>
	<script>
		$(document).ready(function() {
			$("a.topLink").click(function() {
				$("html, body").animate({
					scrollTop: $($(this).attr("href")).offset().top + "px"
				}, {
					duration: 500,
					easing: "swing"
				});
				return false;
			});
		});
		$(document).ready(function(){
			$('.portfolio-link').hover(function(){
				$(this).find('.field-portfolio').slideToggle(300);
				
				return false;
			});
		});
		$(function() {
			$('.back-to-top-link').click(function() {
				$("html, body").animate({
					scrollTop:0
				},1000);
			})
		});
		$(window).scroll(function() {
			if ($(this).scrollTop()>200) {
				$('.back-to-top-link').fadeIn();
			}
			else {
				$('.back-to-top-link').fadeOut();
			}
		});
		function resizeBlock(){
			if(window.matchMedia("screen and (max-width: 1023.98px)").matches) {
				$('.box_hdr_mobile').append($('.box_form'));
			}
			else if (window.matchMedia("screen and (min-width: 1024px)").matches){
				$('.box_form').prependTo($('#default-box'));
			}
		}
		$(window).resize(function() {
			 resizeBlock();
		});
		$(document).ready(function(){
			resizeBlock();
		});
		
		$(document).ready(function(){
			$('.search_button').click(function(){
				$('.hdr-center-bottom').slideToggle(300);
				return false;
			});
		});
	</script>
	
	<script type="text/javascript" src="<?php echo $pathTmp?>js/jquery.touchSwipe.min.js"></script>
	<script type="text/javascript" src="<?php echo $pathTmp?>js/jquery.maskedinput.min.js"></script>
	<script type="text/javascript" src="<?php echo $pathTmp?>js/jquery.spoiler.min.js"></script>
	<script src="<?php echo $pathTmp?>js/core.js" defer></script>
	<script type="text/javascript">
		jQuery(function($){
			$('[type="tel"]').mask('+7(999)999-99-99',{ placeholder: '_' });
		});
		
		$(".cat-menu .dropdown-toggle").click(function(a){
			$(this).next("ul").length&&(a.preventDefault(),
			$(this).parent().toggleClass("opened").siblings("li").children("ul:visible").slideToggle(300).parent().toggleClass("opened"),
			$(this).next("ul").slideToggle(300));
		});

		jQuery('.spoiler').Spoiler({'rows':'6', 'opentext':'Показать текст полностью', 'closetext':'Скрыть'});
		
		document.getElementById("quizz-content-1").style.display = "block";
	</script>
</body>
</html>
