<?php
/**
 * @var $this TuningController
 * @var $currentBrand TuningBrand
 * @var $currentModel TuningModel
 * @var $currentSet TuningSet
 * @var $prev TuningSet[]
 * @var $next TuningSet[]
 * @var $contacts Contact[]
 */
?>
<?php $this->renderPartial('//snippets/headerGallery'); ?>

<div class="wrapper content-wrapper">
    <div class="col-wrapper">
        <div class="col2">
            <p class="section-title"><?php echo Yii::t('site', 'Наши услуги');?></p>
            <ul class="sidebar-nav">
                <?php foreach ($this->getServices() as $item): ?>
                <li><?php echo CHtml::link($item->i18n->name, array('tuning/service', 'link' => $item->link));?></li>
                <?php endforeach; ?>
            </ul>
            <p class="section-title"><?php echo Yii::t('site', 'Марки авто');?></p>
            <ul class="sidebar-nav">
                <ul class="sidebar-nav">
                    <?php foreach ($this->getBrands() as $brand): ?>
                    <?php if ($brand->id == $currentBrand->id): ?>
                        <li class="active">
                            <?php echo CHtml::link($brand->i18n->name, array('tuning/brand', 'brand' => $brand->link));?>
                            <ul>
                                <?php foreach ($brand->tuningModels as $model) if (!$model->hidden): ?>
                                <li <?php if ($model->id == $currentModel->id) echo'class="active"' ?>>
                                    <?php
                                    echo CHtml::link($model->i18n->name, array(
                                            'tuning/model',
                                            'brand' => $model->tuningBrand->link,
                                            'model' => $model->link)
                                    );
                                    ?>
                                </li>
                                <?php endif; ?>
                            </ul>
                        </li>
                        <?php else: ?>
                        <li><?php echo CHtml::link($brand->i18n->name, array('tuning/brand', 'brand' => $brand->link));?></li>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </ul>
            </ul>
        </div>
        <div class="col8">
            <ul class="crumbs">
                <li><?php echo CHtml::link(Yii::t('site', 'Тюнинг автомобилей'), array('tuning/index'));?>→</li>
                <li><?php echo CHtml::link($currentBrand->i18n->name, array(
                    'tuning/brand',
                    'brand' => $currentBrand->link,
                ));?>→
                </li>
                <li><?php echo CHtml::link($currentModel->i18n->name, array(
                    'tuning/model',
                    'brand' => $currentBrand->link,
                    'model' => $currentModel->link,
                ));?>→
                </li>
            </ul>
            <h1><?php echo $this->pageName?></h1>

            <div class="catalog-item-full">
                <ul class="catalog-item-nav">

                    <?php

                    if (count($prev) > 0) echo '<li class="catalog-item-prev">', CHtml::link($prev[0]->i18n->name, array(
                        'tuning/view',
                        'brand' => $prev[0]->tuningModel->tuningBrand->link,
                        'model' => $prev[0]->tuningModel->link,
                        'set' => $prev[0]->link,
                    )), '</li>';

                    if (count($next) > 0) echo '<li class="catalog-item-next">', CHtml::link($next[0]->i18n->name, array(
                        'tuning/view',
                        'brand' => $next[0]->tuningModel->tuningBrand->link,
                        'model' => $next[0]->tuningModel->link,
                        'set' => $next[0]->link,
                    )), '</li>';
                    ?>
                </ul>
                <div class="text-content">
                    <?php
                    $big = $currentSet->imageBehavior->getFileUrl('big');
                    $bigger = $currentSet->imageBehavior->getFileUrl('bigger');
                    if (isset($bigger))
                        echo CHtml::image($bigger,'', array('width' => '800'));
                    else
                        echo CHtml::image($big,'', array('width' => '632'));
                    ?>
                    <?php echo $currentSet->i18n->content ?>
                </div>
                <?php
                if (isset($currentSet->gallery_id)) {
                    $photos = $currentSet->galleryBehavior->getGalleryPhotos();
                    if (count($photos) > 0) {
                        ?>
                        <div class="col10">
                            <div class="col8">
                                <h2><?php echo Yii::t('site', 'Фотогалерея');?></h2>

                                <div class="catalog-item-gallery">
                                    <?php
                                    foreach ($photos as $photo) {
                                        echo CHtml::link(
                                            CHtml::image($photo->getUrl('small'), $photo->i18n->name),
                                            $photo->getUrl('medium'),
                                            array(
                                                'rel' => 'gallery',
                                                'data-name' => $photo->i18n->name,
                                                'data-description' => $photo->i18n->description,
                                            )
                                        );
                                    }
                                    ?>
                                </div>
                            </div>
                        </div>
                        <?php
                    }
                }
                ?>
            </div>
            <div class="text-content">
                <h2><?php echo Yii::t('site', 'Узнать стоимость и наличие {tuning_set}',
                    array('{tuning_set}' => $currentSet->i18n->name))?></h2>

                <p><?php echo Yii::t('site', 'Ответ на эти и другие интересующие вас вопросы вы можете получить связавшись с нами:');?>
                </p>
            </div>
            <?php echo $this->tuningRoot->i18n->contact_info?>
            <?php if (count($prev) + count($next) > 0): ?>
            <h2>
                <?php echo Yii::t('site', 'Другие варианты тюнинга {model}',
                array('{model}' => $currentModel->i18n->name))?>:
            </h2>

            <div class="catalog-similar">
                <?php
                foreach (array_reverse($prev) as $item) {
                    $this->renderPartial('_similarSet', array('tuningSet' => $item));
                }
                $this->renderPartial('_similarSet', array('tuningSet' => $currentSet, 'htmlClass' => 'active'));
                foreach ($next as $item) {
                    $this->renderPartial('_similarSet', array('tuningSet' => $item));
                }
                ?>
            </div>
            <?php endif;?>
        </div>
        <div class="col2">
            <p class="section-title"><?php echo Yii::t('site', 'Есть вопросы?');?></p>

            <div class="text-content">
                <?php echo Yii::t('site', 'Обращайтесь к вашему персональному консультанту по тюнингу!');?>
            </div>
            <?php $this->renderPartial('//snippets/sidebarContacts');?>
        </div>
    </div>
</div>


<?php
$cs = Yii::app()->clientScript;
$cs->registerCoreScript('jquery');
//$cs->registerScriptFile(Yii::app()->baseUrl . '/js/fancybox/jquery.mousewheel-3.0.4.pack.js');
$cs->registerScriptFile(Yii::app()->baseUrl . '/js/fancybox/jquery.fancybox-1.3.4.pack.js');
$cs->registerCssFile(Yii::app()->baseUrl . '/js/fancybox/jquery.fancybox-1.3.4.css');
$src = <<<JS
$("a[rel=gallery]").fancybox({
	'transitionIn'	: 'none',
	'transitionOut'	: 'none',
	'titlePosition' : 'over',
	'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) {

	    var name = $(currentArray[currentIndex]).data('name'), r = '';
	    var description = $(currentArray[currentIndex]).data('description');
	    name = name?name:''; description = description?description:'';

	    if(name.length) r+='<b>'+name+'</b> ';
		if(description.length) r+=description;
		if(r.length) return '<span id="fancybox-title-over">'+r+'</span>';
        else return '';
	}
});
JS;

$cs->registerScript('fancybox_gallery', $src);
?>