
; /* Start:/style/js/custom/news.js*/
var newsList = {

    init: function(){

        newsList.tabsInit();
        newsList.getMoreNewsInit();

        if ( $('[show_detail_news]').attr('show_detail_news').length ) {
            newsList.showNewsDetailInit();
            $('#newsDetail_' + $('[show_detail_news]').attr('show_detail_news')).click();
            $('[id^="newsDetail_"]').unbind();
        }
    },
    showNewsDetailInit:function(){
        $('[id^="newsDetail_"]').unbind();
        $('[id^="newsDetail_"]').click(function(){



            var data = $(this).attr('id').split('_');
            var newsId = data[1];
            $.post('/ajax/news/detail.php', {'newsId': newsId },
                function( responseHtml ){
                    $('#pop_news').html( responseHtml );
                    centerAndOpenPopUp();
                    if (ie){
                        $('#pop_news').show();
                    } else {
                        $('#pop_news').fadeIn(300);
                    };

                    //закрытие всплывающих окон
                    $('.close').unbind();
                    $('.close').click(function(){
                        if (ie){
                            $('#overlay').hide();
                            $(this).parents('.pop_up, .pop_up_block').hide();
                        } else {
                            $('#overlay').fadeOut(300);
                            $(this).parents('.pop_up, .pop_up_block').fadeOut(300);
                        };
                    });



                });
        });
    },
    tabsInit:function(){
        $('#newsContainer').find('.tab_control>div').unbind();
        $('#newsContainer').find('.tab_control>div').on('click', function(){
            if ($(this).hasClass('sand')){
                return false;
            } else {
                var currentYear = $(this).attr('year');
                $('[id^="moreNews_"]').hide();
                $('#moreNews_' + currentYear).show();

                $(this).addClass('sand').siblings('div').removeClass('sand');
                $('.tab_content>.tab', $(this).parents('.wrapper_tabs')).removeClass('active').eq($(this).index()).addClass('active');
            };
        });
    },
    getMoreNewsInit:function(){
        $('[id^="moreNews_"]').find('.roll_header').click(function(){
            var data = $(this).parents('.width_1').attr('id').split('_');
            var year = data[1];

            var nextPage = parseInt( $('.tab_control').find('[year="'+ year +'"]').attr('page_num') ) + 1;
            $('.tab_control').find('[year="'+ year +'"]').attr('page_num', nextPage );
            var perPage = parseInt( $('.tab_control').find('[year="'+ year +'"]').attr('per_page') );
            var totalCount = parseInt( $('.tab_control').find('[year="'+ year +'"]').attr('total_count') );

            if ( totalCount <= ( nextPage * perPage ) ) {
                $('#moreNews_' + year).remove();
            }

            $.get('/ajax/news/get_more.php?pageNum=' + nextPage + '&currentYear=' + year,
                    function( responseHtml ){
                        $('.tab_content').find('.tab.active').prepend( responseHtml );
                        newsList.showNewsDetailInit();
                    });


        });
    }
};
$(function(){
    newsList.init();
});

/* End */
;; /* /style/js/custom/news.js*/
