<?php
/**
 * @var $this NewsController
 * @var $news News
 * @var $contacts Contact[]
 * @var $pages CPagination
 * @var $category NewsCategory
 */
?>
<?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->getNewsCategories() as $item) {
                    if (isset($category) && $category->id == $item->id)
                        echo '<li class="active">';
                    else
                        echo '<li>';
                    if ($item->type == 2)
                        echo CHtml::link($item->i18n->name, array('news/publications', 'link' => $item->link)), '</li>';
                    elseif($item->type == 1 || $item->type == 3)
                        echo CHtml::link($item->i18n->name, array('news/category', 'link' => $item->link)), '</li>';
                    else
                        echo CHtml::link($item->i18n->name, array('news/show', 'link' => $item->link)), '</li>';
                }
                ?>
            </ul>
        </div>
        <div class="col8">
            <h1><?php echo CHtml::encode($this->pageName)?></h1>

            <p class="news-info"><?php
                $timestamp = CDateTimeParser::parse($news->date, 'yyyy-MM-dd hh:mm:ss');
                echo Yii::app()->getDateFormatter()->format('d MMMM yyyy', $timestamp);
                echo ' ', Yii::t('site', 'Рубрика'), ': ';
                echo CHtml::link($news->newsCategory->i18n->name, array('news/category', 'link' => $news->newsCategory->link))
                ?></p>

            <div class="text-content">
                <?php echo $news->i18n->content ?>
            </div>

            <?php
            if (isset($news->gallery_id)) {
                $photos = $news->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
                }
            }
            ?>

            <h2><?php echo Yii::t('site','Понравилась статья?');?></h2>

            <div class="soc-share">
                <!-- Put this div tag to the place, where the Like block will be -->
                <?php
                $this->renderPartial('//snippets/likes', array(
                    'url' => Yii::app()->getBaseUrl(true).Yii::app()->request->getUrl(),
                ));
                ?>
            </div>

            <?php
            /** @var $items News[] */
            $items = News::model()->with('i18n')->findAll(array(
                'condition' => 'hidden=0 and news_category_id=' . $news->news_category_id . ' and t.id <>' . $news->id,
                'order' => 'date desc',
                'limit'=>15,
            ));
            if (!empty($items)) {
                echo '<div class="text-content"><h2>', Yii::t('site', 'Читать далее'), '</h2>';
                echo '<ul>';
                foreach ($items as $item) echo '<li>', CHtml::link($item->i18n->name, array('news/view', 'link' => $item->link, 'node_id'=>Node::idByDataId('newsRoot', $item->newsCategory->news_root_id))), '</li>';
                echo '</ul></div>';
            }
            ?>


            <?php //$this->renderPartial('_newsFooter');?>
        </div>
        <div class="col2">
            <p class="section-title"><?php echo Yii::t('site','Контакты для прессы');?></p>

            <div class="text-content">
                <?php echo Yii::t('site','По всем вопросам связанным с прессой обращайтесь в наш PR-отдел');?>
            </div>
            <?php $this->renderPartial('//snippets/sidebarContacts');?>

            <?php
            if (isset($category)) {
                $this->renderPartial('_photofact', array('galleryIds' => array($category->photofact_gallery_id)));
            } else {
                /** @var $cats NewsCategory[] */
                $cats = NewsCategory::model()->findAll();
                $galleryIds = array();
                foreach($cats as $cat){
                    if(isset($cat->photofact_gallery_id))
                        $galleryIds[]=$cat->photofact_gallery_id;
                }
                $this->renderPartial('_photofact', array('galleryIds' => $galleryIds));
            }
            ?>
        </div>
    </div>
    <div class="col-wrapper">
        <div class="col2">&nbsp;</div>
        <div class="col10">
            <?php $this->renderPartial('_newsFooter');?>
        </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);
?>