<?php
slot('title', __('Отзывы'));
use_javascript('masonry.pkgd.min.js');
?>
<div class="content__main">
    <?php
    include_partial('main/breadcrumbs');
    echo '<h1 class="content_title">' . __('Отзывы') . '</h1>';
    ?>
    <div class="reviews_wrap">
        <div class="max_width">
            <div class="reviews" style="visibility: visible">
                <div class="reviews_item_gutter" style="width: 100%; text-align: center">
                        <?php
                        if (count($reviews) >= sfConfig::get('app_view_count_tag')) {
                            echo '<a data-tag-id="all" class="reviews_show_tag green_link active ' . (!$tag_id || $tag_id == 'all' ? 'active' : '') . '">Все</a>';
                            foreach ($reviews_tags as $tag) {
                                echo '<a class="reviews_show_tag green_link ' . ($tag_id == $tag['id'] ? 'active' : '') . '" data-tag-id="' . $tag['id'] . '">' . $tag['Translation'][$culture]['title'] . '</a>';
                            }
                        }
                        ?>
                </div>
                <i class="br20 mobile_hide"></i>
                <div class="reviews_index">
                    <?php
                    include_partial('review/review_index', array('reviews' => $reviews));
                    ?>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="reviews_form_wrap">
    <div class="max_width">
        <div class="reviews_form">
            <?php
            include_partial('review/review_form', array('review_form' => $review_form));
            ?>
        </div>
    </div>
</div>
<script type="text/javascript">
    var culture = '<?php echo $culture ?>';
    $('body').on('click', '.reviews_show_tag', function () {
        _this = this;
        $.ajax({
            url: '/' + culture + '/review/',
            type: 'get',
            data: {tag_id : $(this).attr('data-tag-id'), ajax : 1},
            success: function (html) {
                $('.reviews_show_tag').removeClass('active');
                $(_this).addClass('active');
                $('.reviews_index').html(html);
                setUrlHash('?tag_id='+$(_this).attr('data-tag-id'));
            }

        });

        //alert($(this).attr('data-tag-id'));
    });

    var review = {
        submit: function (form) {
            $.post('<?php echo url_for('@review');?>', $(form).serialize(), function (html) {
                $('.reviews_form').html(html).find('input[type="checkbox"]').customizeForm();
                imgUpload.init();
            });
        },
        showFile: function (src, _this) {
            var text = _this.find('.reviews_item__text_for_popup').text();
            var author = _this.find('.reviews_item__author').text();
            // console.log(text);
            // return false;
            $('body')
                .append('<div class="review_file_overlay_review" onclick="review.closeFile();">'
                    + '<div class="review_file_overlay__item_review">'
                    + '<div class="review_file_overlay__item_review_border"> '
                    + '<div class="review_file_overlay__item__img__review" style="background-image: url(' + src + ');" ></div>'
                    + '<div class="review_file_overlay__item__text"> '
                    + '<div class="review_file_overlay__item__text_table">'
                    + '<div class="review_file_overlay__item__text__review">' + text + '</div> '
                    + '<div class="review_file_overlay__item__author__table"> '
                    + '<div class="review_file_overlay__item__author__review">' + author + '</div> '
                    + '</div></div></div></div></div><div class="review_file_overlay__close" onclick="review.closeFile();"></div></div>')
                .addClass('scroll_hidden');
        },
        closeFile: function () {
            var body = $('body');
            $('.review_file_overlay_review').remove();
            if(!body.hasClass('search_active')){
                body.removeClass('scroll_hidden');
            }
        }
    };
    $(document).ready(function () {
        var reviews = $('.reviews');
        // reviews.on( 'layoutComplete', function( event, items ) {
        //     reviews.css('visibility', 'visible')
        // });
        // reviews.masonry({
        //     columnWidth: '.reviews_item',
        //     itemSelector: '.reviews_item',
        //     gutter: '.reviews_item_gutter',
        //     originLeft: true,
        //     percentPosition: true
        // });
        imgUpload.init();
    });
</script>