<?php
/**
 * @var $this SaleController
 * @var $contacts Contact[]
 * @var $vehicle Vehicle
 * @var $vehicles Vehicle[]
 */
?>
<?php $this->renderPartial('//snippets/headerGallery'); ?>
<!-- header end-->
<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 ($vehicles as $item) {
                    if ($item->id == $vehicle->id) echo '<li class="active">';
                    else echo '<li>';
                    echo CHtml::link($item->i18n->name, array('sale/view', 'link' => $item->link)), '</li>';
                }?>
            </ul>
        </div>
        <div class="col8">
            <h1><?php echo CHtml::encode($this->pageName)?></h1>

            <div class="text-content">
                <?php echo $vehicle->i18n->content?>
                <?php
                if (isset($vehicle->gallery_id)) {
                    $photos = $vehicle->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>
        <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
var gallery = $("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);
?>