PageSourceSearch

https://s.prk24.pl/p/js/script.js?v=1790242103

js prk24.pl collected 2026-09-24 09:28:39 UTC 222,428 bytes, 4,925 lines download raw bytes

1var rk = {
2    pageType: 'none',
3    hashParams: {},
4    map: null,
5    mapMarkers: [],
6    mapMarkersByType: [],
7    mapInfoWindow: null,
8    init: function () {
9        var t = this;
10
11        t.pageType = $('body').data('page-type') || 'none';
12
13        $.each(window.location.hash.replace('#', '').split('&'), function (i, value) {
14            value = value.split('=');
15            t.hashParams[value[0]] = value[1];
16        });
17
18        // pages - modules
19        t.pages.all.init();
20        if (t.pageType !== 'none' && t.pageType !== 'all') {
21            t.pages[t.pageType].init();
22        }
23
24        if (!navigator.userAgent.match(/iPhone/i)) {
25            $('body').addClass('noiPhone');
26        }
27    },
28    cookie: {
29        set: function (cName, value, exDays) {
30            var t = this,
31                domain = document.location.hostname.replace(/([a-zA-Z0-9-_.]+)\.([a-zA-Z0-9-_.]+)(?=\.)/g, "$2");
32            tmpDate = new Date(),
33                exDate = tmpDate.setTime(tmpDate.getTime() + (exDays * 24 * 60 * 60 * 1000)),
34                cValue = escape(value) + ((exDays === null) ? '' : '; expires=' + tmpDate.toGMTString()) + '; path=/; domain=' + domain;
35
36            document.cookie = cName + '=' + cValue;
37        },
38        get: function (cName) {
39            var cValue = document.cookie,
40                cStart = cValue.indexOf(' ' + cName + '='),
41                cEnd = cValue.indexOf(';', cStart);
42
43            if (cStart === -1) {
44                cStart = cValue.indexOf(cName + '=');
45            }
46            if (cStart === -1) {
47                cValue = null;
48            } else {
49                cStart = cValue.indexOf('=', cStart) + 1;
50                cEnd = cValue.indexOf(';', cStart);
51                if (cEnd === -1) {
52                    cEnd = cValue.length;
53                }
54                cValue = unescape(cValue.substring(cStart, cEnd));
55            }
56            return cValue;
57        }
58    },
59    pages: {
60        all: {
61            init: function () {
62                rk.modules.cookieOverlay.init();
63                rk.modules.sticky.init();
64                rk.modules.redir.init();
65                rk.modules.embeddedVideoLink.init();
66                rk.modules.topMenu.init();
67                rk.modules.searchForm.init();
68                rk.modules.audioPlayer.init();
69                rk.modules.streamCurrent.init();
70            }
71        },
72        home: {
73            init: function () {
74                rk.modules.mainModule.init();
75                rk.modules.mainNewsShare.init();
76                rk.modules.scrollModule.init();
77                rk.modules.informationsModule.init();
78                rk.modules.videoModule.init();
79                rk.modules.eventsModule.init();
80                rk.modules.playlistModule.init();
81                rk.modules.embeddedVideoLink.init();
82                rk.modules.gallery.init();
83                rk.modules.calendarModule.init();
84            }
85        },
86        directory: {
87            init: function () {
88                rk.modules.mainNewsShare.init();
89                rk.modules.embeddedVideoLink.init();
90                rk.modules.gallery.init();
91                rk.modules.listing.init();
92            }
93        },
94        directory_video: {
95            init: function () {
96                rk.modules.embeddedVideoLink.init();
97                rk.modules.listing.init();
98            }
99        },
100        article: {
101            init: function () {
102                rk.modules.tabs.init();
103                rk.modules.articleShare.init();
104                rk.modules.gallery.init();
105                rk.modules.articlePoll.init();
106            }
107        },
108        editor: {
109            init: function () {
110                rk.modules.expandableContainer.init();
111                rk.modules.listing.init();
112            }
113        },
114        programs_directory: {
115            init: function () {
116                rk.modules.programsDirectory.init();
117            }
118        },
119        programs_archive: {
120            init: function () {
121                rk.modules.programsArchive.init();
122            }
123        },
124        program: {
125            init: function () {
126                rk.modules.listing.init();
127            }
128        },
129        onas_dziennikarze: {
130            init: function () {
131                rk.modules.peopleModule.init();
132            }
133        },
134        onas_ludzie: {
135            init: function () {
136            }
137        },
138        onas_kalendarium: {
139            init: function () {
140                rk.modules.listing.init();
141                rk.modules.gallery.init();
142            }
143        },
144        onas_praca: {
145            init: function () {
146                rk.modules.listing.init();
147            }
148        },
149        onas_wydawnictwo: {
150            init: function () {
151                rk.modules.wydawnictwoShare.init();
152                rk.modules.wydawnictwoListing.init();
153            }
154        },
155        epg: {
156            init: function () {
157                rk.modules.epgModule.init();
158            }
159        },
160        events: {
161            init: function () {
162                rk.modules.embeddedVideoLink.init();
163                rk.modules.gallery.init();
164                rk.modules.calendarModule.init();
165            }
166        },
167        mmr: {
168            init: function () {
169                rk.modules.mmrMap.init();
170                rk.modules.mmrCitiesListing.init();
171                rk.modules.mmrPlacesListing.init();
172                rk.modules.mmrGalleriesListing.init();
173                rk.modules.mmrEventsListing.init();
174            }
175        },
176        mmr_sea: {
177            init: function () {
178                rk.modules.listing.init();
179            }
180        },
181        mmr_city: {
182            init: function () {
183                rk.modules.mmrMap.init();
184                rk.modules.mmrMap.initMarkerButtons();
185                rk.modules.mmrRoutePlanner.init();
186                rk.modules.mmrCitiesListing.init();
187                rk.modules.mmrPlacesListing.init();
188                rk.modules.mmrGalleriesListing.init();
189                rk.modules.mmrEventsListing.init();
190                rk.modules.listing.init();
191            }
192        },
193        place: {
194            init: function () {
195                rk.modules.articleShare.init();
196                rk.modules.gallery.init();
197            }
198        },
199        muzyka_playlista: {
200            init: function () {
201                rk.modules.playlist.init();
202            }
203        },
204        muzyka_plyta_tygodnia: {
205            init: function () {
206                rk.modules.plytaTygodniaShare.init();
207                rk.modules.plytaTygodniaListing.init();
208            }
209        },
210        muzyka_lista_przebojow: {
211            init: function () {
212                rk.modules.listaPrzebojow.init();
213            }
214        },
215        muzyka_lista_przebojow_wyniki: {
216            init: function () {
217            }
218        },
219        muzyka_koncerty: {
220            init: function () {
221                rk.modules.koncertyShare.init();
222                rk.modules.koncertyListing.init();
223            }
224        },
225        muzyka_programs_directory: {
226            init: function () {
227                rk.modules.programsDirectory.init();
228            }
229        },
230        muzyka_dziennikarze: {
231            init: function () {
232                rk.modules.peopleModule.init();
233            }
234        },
235        search_results: {
236            init: function () {
237                rk.modules.searchResults.init();
238            }
239        },
240        weather: {
241            init: function () {
242                rk.modules.weather.init();
243            }
244        },
245        sondy_wyniki: {
246            init: function () {
247            }
248        },
249        rko: {
250            init: function () {
251                rk.modules.listing.init();
252            }
253        },
254        report_news: {
255            init: function () {
256                rk.modules.reportNews.init();
257            }
258        },
259        liveblog: {
260            init: function () {
261                rk.modules.liveblogTimeline.init();
262                rk.modules.articleShare.init();
263                rk.modules.gallery.init();
264            }
265        },
266    },
267    modules: {
268        cookieOverlay: {
269            init: function () {
270                var t = this,
271                    co = $('.rk-covl');
272
273                co.find('.rk-covl__ab').off().on('click', function () {
274                    t.close();
275                });
276                if (rk.cookie.get('__ccRK') !== '1') {
277                    t.show();
278                }
279            },
280            show: function () {
281                var cb = $('.rk-covl-bg'),
282                    co = $('.rk-covl');
283
284                cb.fadeIn('normal');
285                co.fadeIn('normal');
286            },
287            close: function () {
288                var cb = $('.rk-covl-bg'),
289                    co = $('.rk-covl');
290
291                rk.cookie.set('__ccRK', '1', 365);
292                cb.fadeOut('normal');
293                co.fadeOut('normal');
294            }
295        },
296        sticky: {
297            init: function () {
298                var t = this;
299
300                $('.sticky').each(function () {
301                    var el = $(this);
302
303                    if (!el.hasClass('sticky-initialized')) {
304                        $(window).on('scroll.sticky', function () {
305                            t.handle(el);
306                        }).on('resize.sticky', function () {
307                            t.handle(el);
308                        });
309                        t.handle(el);
310                        el.addClass('sticky-initialized');
311                    }
312                });
313            },
314            calculateElementTop: function (el) {
315                var t = this,
316                    elTop = 0;
317
318                el.prevAll().each(function () {
319                    if ($(this).is(':visible') && $(this).css('position') !== 'fixed' && $(this).css('position') !== 'absolute') {
320                        elTop += $(this).outerHeight(true);
321                    }
322                });
323                if (el.parent().length !== 0 && !el.parent().is('body')) {
324                    elTop += t.calculateElementTop(el.parent());
325                }
326                return elTop + parseInt(el.css('margin-top').replace('px', ''));
327            },
328            handle: function (el) {
329                var t = this,
330                    winScroll = $(window).scrollTop(),
331                    elStMargin = el.data('sticky-margin') !== undefined ? el.data('sticky-margin').split(',') : new Array(0, 0, 0, 0, 0, 0),
332                    elTop = t.calculateElementTop(el);
333
334                if ($(document).width() >= 1220) {
335                    elTop -= parseInt(elStMargin[0]);
336                } else if ($(document).width() >= 960) {
337                    elTop -= parseInt(elStMargin[1]);
338                } else if ($(document).width() >= 768) {
339                    elTop -= parseInt(elStMargin[2]);
340                } else if ($(document).width() >= 600) {
341                    elTop -= parseInt(elStMargin[3]);
342                } else if ($(document).width() >= 480) {
343                    elTop -= parseInt(elStMargin[4]);
344                } else {
345                    elTop -= parseInt(elStMargin[5]);
346                }
347
348                el.toggleClass('fixed', winScroll >= elTop);
349            }
350        },
351        redir: {
352            init: function () {
353                $('*[data-redir]').each(function () {
354                    var _item = $(this);
355
356                    if (!_item.hasClass('redir-initialized')) {
357                        _item.off('click.redir').on('click.redir', function () {
358                            document.location.href = _item.data('redir');
359                            return false;
360                        });
361                        _item.addClass('redir-initialized');
362                    }
363                });
364            }
365        },
366        embeddedVideoLink: {
367            init: function () {
368                $('*[data-video-id]').each(function () {
369                    var container = $(this),
370                        videoID = container.data('video-id'),
371                        videoLoaded = container.data('video-loaded'),
372                        videoTT = container.data('with-top-title') === 1 ? 1 : 0;
373
374                    $(this).css('cursor', 'pointer').off('click.videolink').on('click.videolink', function (e) {
375                        e.stopPropagation();
376                        e.stopImmediatePropagation();
377
378                        if (videoLoaded === false) {
379                            $.ajax({
380                                url: '/shared/details.php',
381                                data: {
382                                    'object_id': videoID,
383                                    'tt': videoTT,
384                                    'template': 'shared/embedded-video.html'
385                                },
386                                success: function (r) {
387                                    container.html(r);
388                                    container.attr('data-video-loaded', 'true');
389                                }
390                            });
391                        }
392                        return false;
393                    });
394                });
395            }
396        },
397        gallery: {
398            init: function () {
399                $('.gallery').monumentGallery();
400            }
401        },
402        topMenu: {
403            init: function () {
404                var tm = $('.top-menu'),
405                    btn = tm.find('.mobile-menu-btn');
406
407                if (tm.length > 0) {
408                    tm.off().on('mouseenter', function () {
409                        tm.addClass('hovered');
410                    }).on('mouseleave', function () {
411                        tm.removeClass('hovered');
412                    });
413                    btn.off().on('click', function () {
414                        tm.toggleClass('expanded');
415                    });
416                }
417                $('body').off('click.tm').on('click.tm', function () {
418                    if (!tm.hasClass('hovered')) {
419                        tm.removeClass('expanded');
420                    }
421                });
422                $(window).off('resize.tm').on('resize.tm', function () {
423                    if ($(this).width() >= 960) {
424                        tm.removeClass('expanded');
425                    }
426                });
427            }
428        },
429        searchForm: {
430            init: function () {
431                var searchBtn = $('.search-btn'),
432                    searchForm = $('.search-form'),
433                    closeBtn = searchForm.find('.close');
434
435                searchBtn.off().on('click', function () {
436                    searchForm.addClass('visible');
437                });
438                closeBtn.off().on('click', function () {
439                    searchForm.removeClass('visible');
440                });
441            }
442        },
443        mainNewsShare: {
444            init: function () {
445                $('.main-news-module .share').each(function () {
446                    var container = $(this),
447                        article = container.parents('.main-news-module'),
448                        articleTitle = article.data('title'),
449                        articleUrl = article.data('url'),
450                        btnTW = container.find('span.tw'),
451                        btnFB = container.find('span.fb');
452
453                    if (!btnTW.hasClass('initialized')) {
454                        btnTW.off().on('click', function () {
455                            var text = encodeURIComponent(articleTitle) + ' (radiokoszalin.pl)',
456                                url = encodeURIComponent(articleUrl),
457                                top = $(window).height() / 2 - 225,
458                                left = $(window).width() / 2 - 275;
459
460                            window.open(
461                                'https://twitter.com/share?text=' + text 
461+ '&url=' + url + '&',
462                                'twitterwindow',
463                                'height=450, width=550, top=' + top + ', left=' + left + ', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0'
464                            );
465                        }).addClass('initialized');
466                    }
467                    if (!btnFB.hasClass('initialized')) {
468                        btnFB.off().on('click', function () {
469                            if (FB) {
470                                FB.ui({
471                                    method: 'share',
472                                    href: articleUrl,
473                                }, function (response) {
474                                });
475                            }
476                        }).addClass('initialized');
477                    }
478                });
479            }
480        },
481        articleShare: {
482            init: function () {
483                $('.article-share').each(function () {
484                    var container = $(this),
485                        article = container.parents('article').length !== 0 ? container.parents('article') : container.parents('.liveblog-meta'),
486                        articleTitle = article.find('h1').length !== 0 ? article.find('h1').html() : article.data('title'),
487                        articleUrl = article.data('url'),
488                        btnTW = container.find('span.tw'),
489                        btnFB = container.find('span.fb');
490
491                    if (!btnTW.hasClass('initialized')) {
492                        btnTW.off().on('click', function () {
493                            var text = encodeURIComponent(articleTitle) + ' (radiokoszalin.pl)',
494                                url = encodeURIComponent(articleUrl),
495                                top = $(window).height() / 2 - 225,
496                                left = $(window).width() / 2 - 275;
497
498                            window.open(
499                                'https://twitter.com/share?text=' + text + '&url=' + url + '&',
500                                'twitterwindow',
501                                'height=450, width=550, top=' + top + ', left=' + left + ', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0'
502                            );
503                        }).addClass('initialized');
504                    }
505                    if (!btnFB.hasClass('initialized')) {
506                        btnFB.off().on('click', function () {
507                            if (FB) {
508                                FB.ui({
509                                    method: 'share',
510                                    href: articleUrl,
511                                }, function (response) {
512                                });
513                            }
514                        }).addClass('initialized');
515                    }
516                });
517            }
518        },
519        koncertyShare: {
520            init: function () {
521                $('.koncerty-promo-module .share').each(function () {
522                    var container = $(this),
523                        article = container.parents('.koncerty-promo-module'),
524                        articleTitle = article.data('title'),
525                        articleUrl = article.data('url'),
526                        btnTW = container.find('span.tw'),
527                        btnFB = container.find('span.fb');
528
529                    if (!btnTW.hasClass('initialized')) {
530                        btnTW.off().on('click', function () {
531                            var text = encodeURIComponent(articleTitle) + ' (radiokoszalin.pl)',
532                                url = encodeURIComponent(articleUrl),
533                                top = $(window).height() / 2 - 225,
534                                left = $(window).width() / 2 - 275;
535
536                            window.open(
537                                'https://twitter.com/share?text=' + text + '&url=' + url + '&',
538                                'twitterwindow',
539                                'height=450, width=550, top=' + top + ', left=' + left + ', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0'
540                            );
541                        }).addClass('initialized');
542                    }
543                    if (!btnFB.hasClass('initialized')) {
544                        btnFB.off().on('click', function () {
545                            if (FB) {
546                                FB.ui({
547                                    method: 'share',
548                                    href: articleUrl,
549                                }, function (response) {
550                                });
551                            }
552                        }).addClass('initialized');
553                    }
554                });
555            }
556        },
557        plytaTygodniaShare: {
558            init: function () {
559                $('.plyta-tygodnia-current .share').each(function () {
560                    var container = $(this),
561                        article = container.parents('.plyta-tygodnia-current'),
562                        articleTitle = article.data('title'),
563                        articleUrl = article.data('url'),
564                        btnTW = container.find('span.tw'),
565                        btnFB = container.find('span.fb');
566
567                    if (!btnTW.hasClass('initialized')) {
568                        btnTW.off().on('click', function () {
569                            var text = encodeURIComponent(articleTitle) + ' (radiokoszalin.pl)',
570                                url = encodeURIComponent(articleUrl),
571                                top = $(window).height() / 2 - 225,
572                                left = $(window).width() / 2 - 275;
573
574                            window.open(
575                                'https://twitter.com/share?text=' + text 
575+ '&url=' + url + '&',
576                                'twitterwindow',
577                                'height=450, width=550, top=' + top + ', left=' + left + ', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0'
578                            );
579                        }).addClass('initialized');
580                    }
581                    if (!btnFB.hasClass('initialized')) {
582                        btnFB.off().on('click', function () {
583                            if (FB) {
584                                FB.ui({
585                                    method: 'share',
586                                    href: articleUrl,
587                                }, function (response) {
588                                });
589                            }
590                        }).addClass('initialized');
591                    }
592                });
593            }
594        },
595        wydawnictwoShare: {
596            init: function () {
597                $('.o-nas-wydawnictwo-current .share').each(function () {
598                    var container = $(this),
599                        article = container.parents('.o-nas-wydawnictwo-current'),
600                        articleTitle = article.data('title'),
601                        articleUrl = article.data('url'),
602                        btnTW = container.find('span.tw'),
603                        btnFB = container.find('span.fb');
604
605                    if (!btnTW.hasClass('initialized')) {
606                        btnTW.off().on('click', function () {
607                            var text = encodeURIComponent(articleTitle) + ' (radiokoszalin.pl)',
608                                url = encodeURIComponent(articleUrl),
609                                top = $(window).height() / 2 - 225,
610                                left = $(window).width() / 2 - 275;
611
612                            window.open(
613                                'https://twitter.com/share?text=' + text + '&url=' + url + '&',
614                                'twitterwindow',
615                                'height=450, width=550, top=' + top + ', left=' + left + ', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0'
616                            );
617                        }).addClass('initialized');
618                    }
619                    if (!btnFB.hasClass('initialized')) {
620                        btnFB.off().on('click', function () {
621                            if (FB) {
622                                FB.ui({
623                                    method: 'share',
624                                    href: articleUrl,
625                                }, function (response) {
626                                });
627                            }
628                        }).addClass('initialized');
629                    }
630                });
631            }
632        },
633        scrollModule: {
634            init: function () {
635                var t = this,
636                    _scroll = $('.scroll-module');
637
638                if (_scroll.length !== 0) {
639                    t.initItems(_scroll);
640                }
641            },
642            initItems: function (_scroll) {
643                var t = this,
644                    _cont = _scroll.find('.container'),
645                    _contW = _cont.width(),
646                    _items = _cont.find('.items'),
647                    _itemsW = 0;
648
649                _items.find('*').each(function () {
650                    _itemsW += $(this).outerWidth(true) + 5;
651                });
652                _items.css('width', _itemsW);
653                _items.css('left', _contW + 25);
654                t.startAnimation(_scroll);
655            },
656            startAnimation: function (_scroll) {
657                var t = this,
658                    _cont = _scroll.find('.container'),
659                    _contW = _cont.width(),
660                    _items = _cont.find('.items'),
661                    _itemsW = _items.width(),
662                    _itemsL = parseInt(_items.css('left').replace('px', '')),
663                    _time = (-_itemsW - _itemsL) * 10;
664
665                _items.animate({left: -_itemsW + 'px'}, _time < 0 ? -_time : _time, 'linear', function () {
666                    setTimeout(function () {
667                        t.restartAnimation(_scroll);
668                    }, 10);
669                });
670            },
671            restartAnimation: function (_scroll) {
672                var t = this,
673                    _cont = _scroll.find('.container'),
674                    _contW = _cont.width(),
675                    _items = _cont.find('.items');
676
677                _items.css('left', _contW + 25);
678                t.startAnimation(_scroll);
679            }
680        },
681        mainModule: {
682            timeout: null,
683            currentItem: 0,
684            init: function () {
685                var t = this,
686                    mod = $('.rotable-items'),
687                    items = mod.find('.module-item');
688
689                if (mod.length !== 0) {
690                    if (items.length > 0) {
691                        let maxHeight = 0;
692                        items.each(function() {
693                            const itemHeight = $(this).outerHeight();
694                            maxHeight = itemHeight > maxHeight ? itemHeight : maxHeight;
695                        });
696                        mod.css('height', maxHeight + 30);
697
698                        window.addEventListener('resize', function() {
699                            let maxHeight = 0;
700                            items.each(function(index) {
701                                const itemHeight = $(this).outerHeight();
702                                maxHeight = itemHeight > maxHeight ? itemHeight : maxHeight;
703                                $(this).css('left', index === t.currentItem ? 0 : '100%');
704                            });
705                            mod.css('height', maxHeight + 30);
706                        });
707                    }
708                    if (items.length > 1) {
709                        const nav = $('<div>').addClass('nav');
710                        for (let i = 0; i < items.length; i++) {
711                            const btn = $('<a>').addClass('item').attr('data-item-no', i);
712                            if (i === 0) {
713                                btn.addClass('active');
714                            }
715                            btn.appendTo(nav);
716                            btn.off().on('click', function () {
717                                t.showItem(mod, i, i > t.currentItem ? 'next' : 'prev');
718                            });
719                        }
720                        nav.appendTo(mod);
721
722                        t.timeout = setTimeout(function () {
723                            t.showNext(mod);
724                        }, 5000);
725                    }
726                }
727            },
728            showNext: function (mod) {
729                var t = this,
730                    items = mod.find('.module-item');
731
732                t.showItem(mod, t.currentItem + 1 < items.length ? t.currentItem + 1 : 0, 'next');
733            },
734            showItem: function (mod, nextItemNo, direction) {
735                var t = this,
736                    moveWidth = mod.outerWidth(),
737                    nav = mod.find('.nav'),
738                    activeItem = mod.find('.module-item:eq(' + t.currentItem + ')'),
739                    nextItem = mod.find('.module-item:eq(' + nextItemNo + ')');
740
741                if (!mod.hasClass('animating') && t.currentItem !== nextItemNo) {
742                    clearTimeout(t.to);
743                    t.to = setTimeout(function () {
744                        t.showNext(mod);
745                    }, 5000);
746
747                    mod.addClass('animating');
748                    if (direction === 'next') {
749                        nextItem.css('left', moveWidth);
750                        activeItem.animate({left: '-=' + moveWidth}, 500, 'easeInOutCubic');
751                        nextItem.animate({left: '-=' + moveWidth}, 500, 'easeInOutCubic', function() {
752                            nav.find('.item:eq(' + t.currentItem + ')').removeClass('active');
753                            nav.find('.item:eq(' + nextItemNo + ')').addClass('active');
754                            t.currentItem = nextItemNo;
755                            mod.removeClass('animating');
756                        });
757                    } else {
758                        nextItem.css('left', -moveWidth);
759                        activeItem.animate({left: '+=' + moveWidth}, 500, 'easeInOutCubic');
760                        nextItem.animate({left: '+=' + moveWidth}, 500, 'easeInOutCubic', function() {
761                            nav.find('.item:eq(' + t.currentItem + ')').removeClass('active');
762                            nav.find('.item:eq(' + nextItemNo + ')').addClass('active');
763                            t.currentItem = nextItemNo;
764                            mod.removeClass('animating');
765                        });
766                    }
767                }
768            }
769        },
770        informationsModule: {
771            init: function () {
772                var t = this,
773                    im = $('.informations-module .info-tabs'),
774                    cats = im.find('.category');
775
776                if (im.length > 0) {
777                    cats.each(function () {
778                        var cat = $(this);
779
780                        cat.off().on('click', function () {
781                            t.load(im, cat.data('id'));
782                        });
783                    });
784                }
785            },
786            load: function (im, id) {
787                var items = im.find('.items');
788
789                $.ajax({
790                    url: '/shared/listing.php',
791                    data: {
792                        parent_id: id,
793                        type: 'news',
794                        direct: 'false',
795                        copy: 'false',
796                        mode: 'info-module',
797                        order: 'release_date,-1',
798                        count: 12,
799                        template: 'index/informations-module/info-tabs-items.html'
800                    },
801                    beforeSend: function () {
802                        im.addClass('loading');
803                    },
804                    success: function (r) {
805                        im.find('.category.active').removeClass('active');
806                        im.find('.category[data-id="' + id + '"]').addClass('active');
807                        im.find('.button-more').remove();
808                        items.replaceWith(r);
809                        im.removeClass('loading');
810                    },
811                    error: function () {
812                        im.removeClass('loading');
813                    }
814                });
815            }
816        },
817        videoModule: {
818            timeout: null,
819            currentSlide: 0,
820            init: function () {
821                var t = this,
822                    mod = $('.video-module'),
823                    slides = mod.find('.grid'),
824                    nav = mod.find('.nav');
825
826                if (mod.length !== 0 && slides.length > 1) {
827                    const bullets = $('<div>').addClass('bullets');
828                    for (let i = 0; i < slides.length; i++) {
829                        const btn = $('<a>').addClass('item').attr('data-item-no', i).text(i + 1);
830                        if (i === 0) {
831                            btn.addClass('active');
832                        }
833                        btn.appendTo(bullets);
834                        btn.off().on('click', function () {
835                            t.showSlide(mod, i, i > t.currentSlide ? 'next' : 'prev');
836                        });
837                    }
838                    bullets.prependTo(nav);
839
840                    t.timeout = setTimeout(function () {
841                        t.showNext(mod);
842                    }, 5000);
843                }
844            },
845            showNext: function (mod) {
846                var t = this,
847                    slides = mod.find('.grid');
848
849                t.showSlide(mod, t.currentSlide + 1 < slides.length ? t.currentSlide + 1 : 0, 'next');
850            },
851            showSlide: function (mod, slideNo, direction) {
852                var t = this,
853                    slides = mod.find('.items'),
854                    slidesWidth = slides.outerWidth(),
855                    moveWidth = slidesWidth + 20,
856                    nav = mod.find('.nav'),
857                    currentSlide = slides.find('.grid:eq(' + t.currentSlide + ')'),
858                    nextSlide = slides.find('.grid:eq(' + slideNo + ')');
859
860                if (!mod.hasClass('animating') && t.currentSlide !== slideNo) {
861                    clearTimeout(t.to);
862                    t.to = setTimeout(function () {
863                        t.showNext(mod);
864                    }, 5000);
865
866                    mod.addClass('animating');
867                    if (direction === 'next') {
868                        nextSlide.css('left', moveWidth);
869                        currentSlide.animate({left: '-=' + moveWidth}, 500, 'easeInOutCubic');
870                        nextSlide.animate({left: '-=' + moveWidth}, 500, 'easeInOutCubic', function() {
871                            nav.find('.item:eq(' + t.currentSlide + ')').removeClass('active');
872                            nav.find('.item:eq(' + slideNo + ')').addClass('active');
873                            t.currentSlide = slideNo;
874                            mod.removeClass('animating');
875                        });
876                    } else {
877                        nextSlide.css('left', -moveWidth);
878                        currentSlide.animate({left: '+=' + moveWidth}, 500, 'easeInOutCubic');
879                        nextSlide.animate({left: '+=' + moveWidth}, 500, 'easeInOutCubic', function() {
880                            nav.find('.item:eq(' + t.currentSlide + ')').removeClass('active');
881                            nav.find('.item:eq(' + slideNo + ')').addClass('active');
882                            t.currentSlide = slideNo;
883                            mod.removeClass('animating');
884                        });
885                    }
886                }
887            }
888        },
889        eventsModule: {
890            to: null,
891            init: function () {
892                var t = this,
893                    mod = $('.events-module'),
894                    items = mod.find('.items .item'),
895                    nav = mod.find('.nav .item');
896
897                if (mod.length !== 0 && items.length > 1) {
898                    nav.each(function () {
899                        $(this).off().on('click', function () {
900                            var i = $(this),
901                                a = parseInt(mod.find('.items .active').data('item-no')),
902                                n = 1;
903
904                            if (i.hasClass('prev')) {
905                                n = a === 1 ? items.length : a - 1;
906                                t.showItem(mod, n, 'prev');
907                            } else if (i.hasClass('next')) {
908                                n = a === items.length ? 1 : a + 1;
909                                t.showItem(mod, n, 'next');
910                            } else {
911                                n = parseInt(i.data('item-no'));
912                                t.showItem(mod, n, n < a ? 'prev' : 'next');
913                            }
914                        });
915                    });
916                    t.to = setTimeout(function () {
917                        t.showNext(mod);
918                    }, 5000);
919                }
920            },
921            showNext: function (mod) {
922                var t = this,
923                    items = mod.find('.items .item'),
924                    a = parseInt(mod.find('.items .active').data('item-no')),
925                    n = 1;
926
927                n = a === items.length ? 1 : a + 1;
928                t.showItem(mod, n, 'next');
929            },
930            showItem: function (mod, n, dir) {
931                var t = this,
932                    w = mod.find('.items .active').outerWidth(),
933                    currItem = mod.find('.items .active'),
934                    newItem = mod.find('.items .item[data-item-no="' + n + '"]'),
935                    currNav = mod.find('.nav .active'),
936                    newNav = mod.find('.nav .item[data-item-no="' + n + '"]');
937
938                if (!mod.hasClass('animating') && currItem.attr('data-item-no') !== newItem.attr('data-item-no')) {
939                    clearTimeout(t.to);
940                    t.to = setTimeout(function () {
941                        t.showNext(mod);
942                    }, 5000);
943
944                    mod.addClass('animating');
945                    if (dir === 'prev') {
946                        newItem.css('left', -w);
947                        currItem.animate({left: '+=' + w}, 500, 'easeInOutCubic', function () {
948                            currItem.css('left', '100%').removeClass('active');
949                            currNav.removeClass('active');
950                        });
951                        newItem.animate({left: '+=' + w}, 500, 'easeInOutCubic', function () {
952                            newItem.addClass('active');
953                            newNav.addClass('active');
954                            mod.removeClass('animating');
955                        });
956                    } else {
957                        newItem.css('left', w);
958                        currItem.animate({left: '-=' + w}, 500, 'easeInOutCubic', function () {
959                            currItem.css('left', '100%').removeClass('active');
960                            currNav.removeClass('active');
961                        });
962                        newItem.animate({left: '-=' + w}, 500, 'easeInOutCubic', function () {
963                            newItem.addClass('active');
964                            newNav.addClass('active');
965                            mod.removeClass('animating');
966                        });
967                    }
968                }
969            }
970        },
971        playlistModule: {
972            to: null,
973            init: function () {
974                var t = this,
975                    _pm = $('.playlist-module');
976
977                if (_pm.length > 0) {
978                    t.setActiveItems(_pm);
979                }
980            },
981            setActiveItems: function (_pm) {
982                var t = this,
983                    _currentTS = Math.floor((new Date()).getTime() / 1000),
984                    _activeItems = _pm.find('.audio-item.active'),
985                    _items = _pm.find('.audio-item'),
986                    maxActive = 9;
987
988                clearTimeout(t.to);
989
990                _activeItems.each(function () {
991                    var _item = $(this);
992                    _itemTS = parseInt(0 + _item.data('audio-ts'));
993
994                    if (_itemTS < _currentTS && (_item.hasClass('loading') || _item.hasClass('playing'))) {
995                        maxActive--;
996                    } else {
997                        _item.removeClass('active');
998                    }
999                });
1000                _items.each(function () {
1001                    var _item = $(this),
1002                        _itemTS = parseInt(0 + _item.data('audio-ts'));
1003
1004                    if (_itemTS >= _currentTS && !_item.hasClass('active') && maxActive > 0) {
1005                        _item.addClass('active');
1006                        maxActive--;
1007                    }
1008                });
1009
1010                t.to = setTimeout(function () {
1011                    t.setActiveItems(_pm)
1012                }, 60000);
1013            }
1014        },
1015        facebookModule: {
1016            to: null,
1017            init: function () {
1018                var t = this,
1019                    fm = $('.facebook-module .inner');
1020
1021                $(window).resize(function () {
1022                    if (fm.length !== 0) {
1023                        fm.html('<div class="fb-page" data-href="https://www.facebook.com/radiokoszalin/" data-tabs="timeline" data-height="600" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="false"><blockquote cite="https://www.facebook.com/radiokoszalin/" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/radiokoszalin/">Polskie Radio Koszalin</a></blockquote></div>');
1024
1025                        if (t.to !== null) {
1026                            clearTimeout(t.to);
1027                        }
1028                        t.to = setTimeout(function () {
1029                            t.redraw();
1030                        }, 1000);
1031                    }
1032                });
1033            },
1034            redraw: function () {
1035                FB.XFBML.parse();
1036            }
1037        },
1038        listing: {
1039            init: function () {
1040                var t = this,
1041                    _listing = $('.listing');
1042
1043                _listing.each(function () {
1044                    var listing = $(this),
1045                        categories = listing.find('.categories .category'),
1046                        moreBtn = listing.find('.button-more');
1047
1048                    categories.each(function () {
1049                        var page = listing.find('input[name="page"]');
1050
1051                        $(this).off().on('click', function () {
1052                            if (!listing.hasClass('loading')) {
1053                                listing.attr('data-parent-id', $(this).data('parent-id'));
1054                                page.val(1);
1055                                t.load(listing);
1056                            }
1057                        });
1058                    });
1059                    moreBtn.each(function () {
1060                        var page = listing.find('input[name="page"]');
1061
1062                        $(this).off().on('click', function () {
1063                            if (!listing.hasClass('loading')) {
1064                                page.val(parseInt(page.val()) + 1);
1065                                t.load(listing);
1066                                return false;
1067                            }
1068                        });
1069                    });
1070                    t.initListingEvents(listing);
1071                });
1072            },
1073            initListingEvents: function (listing) {
1074                rk.modules.redir.init();
1075                rk.modules.audioPlayer.init();
1076                rk.modules.gallery.init();
1077            },
1078            load: function (listing) {
1079                var t = this,
1080                    moreBtn = listing.find('.button-more'),
1081                    _parentId = listing.attr('data-parent-id'),
1082                    _type = listing.attr('data-type'),
1083                    _copy = listing.attr('data-copy'),
1084                    _direct = listing.attr('data-direct'),
1085                    _order = listing.attr('data-order'),
1086                    _count = parseInt(listing.attr('data-count')),
1087                    _categories = listing.attr('data-categories'),
1088                    _filter = JSON.parse(listing.attr('data-filter') !== '' ? decodeURIComponent(listing.attr('data-filter')) : '{}'),
1089                    _template = listing.attr('data-template'),
1090                    _page = parseInt(listing.find('input[name="page"]').val()),
1091                    beforeCnt = parseInt(listing.find('.items .item').length);
1092
1093                if (!listing.hasClass('loading')) {
1094                    $.ajax({
1095                        url: '/shared/listing.php',
1096                        data: {
1097                            parent_id: _parentId,
1098                            type: _type,
1099                            copy: _copy === true || _copy === 'true' ? 'true' : 'false',
1100                            direct: _direct === true || _direct === 'true' ? 'true' : 'false',
1101                            order: _order,
1102                            count: listing.hasClass('listing-2-4') ? (_count + 2) * (_page - 1) + _count : _count * _page,
1103                            categories: _categories,
1104                            filter: JSON.stringify(_filter),
1105                            template: _template
1106                        },
1107                        dataType: 'html',
1108                        beforeSend: function () {
1109                            listing.addClass('loading');
1110                            moreBtn.hide();
1111                        },
1112                        success: function (r) {
1113                            listing.find('.categories .active').removeClass('active');
1114                            listing.find('.categories .category[data-parent-id="' + _parentId + '"]').addClass('active');
1115                            listing.find('.items .item').each(function () {
1116                                $(this).remove();
1117                            });
1118
1119                            if (r.trim() !== '') {
1120                                listing.find('.items').html(r);
1121                                t.initListingEvents(listing);
1122                                parseInt(listing.find('.items .item').length) === beforeCnt && _page !== 1 ? moreBtn.hide() : moreBtn.show();
1123                            }
1124                            listing.removeClass('loading');
1125                        },
1126                        error: function () {
1127                            listing.removeClass('loading');
1128                        }
1129                    });
1130                }
1131            }
1132        },
1133        tabs: {
1134            init: function () {
1135                $('.tabs-container').each(function () {
1136                    var _tc = $(this),
1137                        _btns = _tc.find('.tab-button');
1138
1139                    _btns.each(function () {
1140                        var _btn = $(this),
1141                            tabID = _btn.data('tab-id');
1142
1143                        _btn.off().on('click', function () {
1144                            _tc.find('.tab.active').removeClass('active');
1145                            _tc.find('.tab-button.active').removeClass('active');
1146                            _tc.find('.tab[data-tab-id="' + tabID + '"]').addClass('active');
1147                            _tc.find('.tab-button[data-tab-id="' + tabID + '"]').addClass('active');
1148                        });
1149                    });
1150                });
1151            }
1152        },
1153        expandableContainer: {
1154            init: function () {
1155                var t = this,
1156                    _c = $('.expandable-container');
1157
1158                if (_c.length !== 0) {
1159                    t.initContainer(_c);
1160                }
1161            },
1162            initContainer: function (_c) {
1163                var outer = _c.find('.outer'),
1164                    inner = _c.find('.inner'),
1165                    overlay = _c.find('.overlay'),
1166                    btn = _c.find('.btn'),
1167                    innerH = inner.outerHeight(),
1168                    outerH = outer.outerHeight();
1169
1170                if (inner.outerHeight() > outerH) {
1171                    btn.css('display', 'table');
1172                } else {
1173                    overlay.hide();
1174                }
1175                btn.off().on('click', function () {
1176                    var newHeight = _c.hasClass('expanded') ? outerH : innerH;
1177
1178                    if (!_c.hasClass('animating')) {
1179                        _c.addClass('animating');
1180                        outer.animate({'height': newHeight}, 500, function () {
1181                            _c.removeClass('animating');
1182                            _c.hasClass('expanded') ? _c.removeClass('expanded') : _c.addClass('expanded');
1183                        });
1184                    }
1185                });
1186            }
1187        },
1188        peopleModule: {
1189            init: function () {
1190                var t = this,
1191                    im = $('.o-nas-people-dirs'),
1192                    cats = im.find('.directory');
1193
1194                if (im.length > 0) {
1195                    cats.each(function () {
1196                        var cat = $(this);
1197
1198                        cat.off().on('click', function () {
1199                            t.load(im, cat.data('directory-id'));
1200                        });
1201                    });
1202                }
1203            },
1204            load: function (im, id) {
1205                var items = $('.o-nas-people-dir');
1206
1207                $.ajax({
1208                    url: '/shared/listing.php',
1209                    data: {
1210                        parent_id: id,
1211                        type: 'directory_standard',
1212                        direct: 'true',
1213                        order: 'position,1',
1214                        count: -1,
1215                        template: 'o-nas/people-dir-categories.html'
1216                    },
1217                    beforeSend: function () {
1218                        im.addClass('loading');
1219                    },
1220                    success: function (r) {
1221                        im.find('.directory.active').removeClass('active');
1222                        im.find('.directory[data-directory-id="' + id + '"]').addClass('active');
1223                        items.html(r);
1224                        im.removeClass('loading');
1225                    },
1226                    error: function () {
1227                        im.removeClass('loading');
1228                    }
1229                });
1230            }
1231        },
1232        programsDirectory: {
1233            init: function () {
1234                var t = this,
1235                    _pa = $('.programs-directory');
1236
1237                if (_pa.length > 0) {
1238                    t.initFilters(_pa);
1239                }
1240            },
1241            initFilters: function (_pa) {
1242                var t = this,
1243                    _page = _pa.find('input[name="page"]'),
1244                    _fSeries = _pa.find('.filter-series'),
1245                    _items = _pa.find('.items');
1246
1247                if (_fSeries.length !== 0) {
1248                    _fSeries.find('a').off().on('click', function () {
1249                        _fSeries.find('a.active').removeClass('active');
1250                        _items.attr('data-parent-id', $(this).data('parent-id'));
1251                        $(this).addClass('active');
1252                        t.load(_pa);
1253                    });
1254                }
1255                $('body').off('click.pa').on('click.pa', function () {
1256                    if (_fSeries.length !== 0 && !_fSeries.hasClass('hovered')) {
1257                        _fSeries.removeClass('expanded');
1258                    }
1259                });
1260            },
1261            load: function (_pa) {
1262                var t = this,
1263                    _items = _pa.find('.items');
1264
1265                $.ajax({
1266                    url: '/shared/listing.php',
1267                    data: {
1268                        parent_id: _items.attr('data-parent-id'),
1269                        type: 'directory_standard',
1270                        copy: 'true',
1271                        direct: 'false',
1272                        order: 'title,1',
1273                        count: -1,
1274                        template: 'audycje/listing.html'
1275                    },
1276                    dataType: 'html',
1277                    beforeSend: function () {
1278                        _pa.addClass('loading');
1279                    },
1280                    success: function (r) {
1281                        _items.html(r);
1282                        _pa.removeClass('loading');
1283                    },
1284                    error: function (e) {
1285                        _pa.removeClass('loading');
1286                    }
1287                });
1288            }
1289        },
1290        programsArchive: {
1291            init: function () {
1292                var t = this,
1293                    _pa = $('.programs-archive');
1294
1295                if (_pa.length > 0) {
1296                    t.initFilters(_pa);
1297                    t.initMoreButton(_pa);
1298                    t.initListingEvents(_pa);
1299                }
1300            },
1301            initFilters: function (_pa) {
1302                var t = this,
1303                    _page = _pa.find('input[name="page"]'),
1304                    _aType = _pa.find('.archive-type'),
1305                    _fSeries = _pa.find('.filter-series'),
1306                    _fYear = _pa.find('.filter-year'),
1307                    _items = _pa.find('.items');
1308
1309                if (_aType.length !== 0) {
1310                    _aType.find('.item').off().on('click', function () {
1311                        _aType.find('.active').removeClass('active');
1312                        _items.attr('data-parent-id', $(this).data('parent-id'));
1313                        _items.attr('data-ts', '0,0');
1314                        $(this).addClass('active');
1315                        _page.val(1);
1316                        t.reloadSeriesFilter(_pa);
1317                        t.reloadYearFilter(_pa);
1318                        t.load(_pa);
1319                    });
1320                }
1321                if (_fSeries.length !== 0) {
1322                    _fSeries.off().on('mouseenter', function () {
1323                        _fSeries.addClass('hovered');
1324                    }).on('mouseleave', function () {
1325                        _fSeries.removeClass('hovered');
1326                    });
1327                    _fSeries.find('.current').off().on('click', function () {
1328                        _fSeries.toggleClass('expanded');
1329                    });
1330                    _fSeries.find('li').off().on('click', function () {
1331                        _fSeries.find('li.selected').removeClass('selected');
1332                        _fSeries.removeClass('expanded');
1333                        _fSeries.find('.current span').html($(this).index() === 0 ? _fSeries.find('.current span').data('placeholder') : $(this).html());
1334                        _items.attr('data-parent-id', $(this).data('parent-id'));
1335                        _items.attr('data-filter', '{}');
1336                        $(this).addClass('selected');
1337                        _page.val(1);
1338                        t.reloadYearFilter(_pa);
1339                        t.load(_pa);
1340                    });
1341                }
1342                if (_fYear.length !== 0) {
1343                    _fYear.off().on('mouseenter', function () {
1344                        _fYear.addClass('hovered');
1345                    }).on('mouseleave', function () {
1346                        _fYear.removeClass('hovered');
1347                    });
1348                    _fYear.find('.current').off().on('click', function () {
1349                        _fYear.toggleClass('expanded');
1350                    });
1351                    _fYear.find('li').off().on('click', function () {
1352                        _fYear.find('li.selected').removeClass('selected');
1353                        _fYear.removeClass('expanded');
1354                        _fYear.find('.current span').html($(this).index() === 0 ? _fYear.find('.current span').data('placeholder') : $(this).html());
1355                        _items.attr('data-ts', $(this).data('ts'));
1356                        $(this).addClass('selected');
1357                        _page.val(1);
1358                        t.load(_pa);
1359                    });
1360                }
1361                $('body').off('click.pa').on('click.pa', function () {
1362                    if (_fSeries.length !== 0 && !_fSeries.hasClass('hovered')) {
1363                        _fSeries.removeClass('expanded');
1364                    }
1365                    if (_fYear.length !== 0 && !_fYear.hasClass('hovered')) {
1366                        _fYear.removeClass('expanded');
1367                    }
1368                });
1369            },
1370            initMoreButton: function (_pa) {
1371                var t = this,
1372                    _page = _pa.find('input[name="page"]'),
1373                    _btn = _pa.find('.button-more');
1374
1375                if (_btn.length !== 0) {
1376                    _btn.off().on('click', function () {
1377                        _page.val(parseInt(0 + _page.val()) + 1);
1378                        t.load(_pa);
1379                    });
1380                }
1381            },
1382            initListingEvents: function (_pa) {
1383                rk.modules.redir.init();
1384                rk.modules.audioPlayer.init();
1385                rk.modules.gallery.init();
1386            },
1387            reloadSeriesFilter: function (_pa) {
1388                var t = this,
1389                    _fSeries = _pa.find('.filter-series'),
1390                    _items = _pa.find('.items');
1391
1392                $.ajax({
1393                    url: '/shared/listing.php',
1394                    data: {
1395                        parent_id: _items.attr('data-parent-id'),
1396                        type: 'directory_standard',
1397                        copy: 'true',
1398                        direct: 'true',
1399                        order: 'title,1',
1400                        count: -1,
1401                        template: 'audycje-archiwum/filter-series.html'
1402                    },
1403                    dataType: 'html',
1404                    success: function (r) {
1405                        _fSeries.replaceWith(r);
1406                        t.initFilters(_pa);
1407                    }
1408                });
1409            },
1410            reloadYearFilter: function (_pa) {
1411                var t = this,
1412                    _fYear = _pa.find('.filter-year'),
1413                    _items = _pa.find('.items');
1414
1415                $.ajax({
1416                    url: '/shared/listing_archive_year.php',
1417                    data: {
1418                        parent_id: _items.attr('data-parent-id'),
1419                        template: 'audycje-archiwum/filter-year.html'
1420                    },
1421                    dataType: 'html',
1422                    success: function (r) {
1423                        _fYear.replaceWith(r);
1424                        t.initFilters(_pa);
1425                    }
1426                });
1427            },
1428            load: function (_pa) {
1429                var t = this,
1430                    _items = _pa.find('.items'),
1431                    _btn = _pa.find('.button-more'),
1432                    _page = _pa.find('input[name="page"]').val(),
1433                    _iCnt = _items.find('.item').length,
1434                    _ts = _items.attr('data-ts').split(','),
1435                    _tsStart = parseInt(_ts[0]),
1436                    _tsEnd = parseInt(_ts[1]),
1437                    _tsNow = parseInt(_items.attr('data-t')),
1438                    _filter = _tsStart !== 0 && _tsEnd !== 0 ? '{"$and9":[{"object_timeline_ts":{"$gte":' + _tsStart + '}},{"object_timeline_ts":{"$lte":' + _tsEnd + '}}]}' : '{"object_timeline_ts":{"$lte":' + _tsNow + '}}',
1439                    _order = _tsStart !== 0 && _tsEnd !== 0 ? 'timeline_date,-1' : _items.attr('data-order');
1440
1441                $.ajax({
1442                    url: '/shared/listing.php',
1443                    data: {
1444                        parent_id: _items.attr('data-parent-id'),
1445                        type: _items.attr('data-type'),
1446                        copy: _items.attr('data-copy'),
1447                        direct: _items.attr('data-direct'),
1448                        order: _order,
1449                        count: parseInt(0 + _items.attr('data-count')) * _page,
1450                        filter: _filter,
1451                        template: _items.attr('data-template')
1452                    },
1453                    dataType: 'html',
1454                    beforeSend: function () {
1455                        _pa.addClass('loading');
1456                    },
1457                    success: function (r) {
1458                        _items.html(r);
1459                        _pa.removeClass('loading');
1460                        t.initMoreButton(_pa);
1461                        t.initListingEvents(_pa);
1462                    },
1463                    error: function (e) {
1464                        _pa.removeClass('loading');
1465                    }
1466                });
1467            }
1468        },
1469        calendarModule: {
1470            init: function () {
1471                var t = this,
1472                    _navigation = $('.events-navigation'),
1473                    _container = $('.events-container');
1474
1475                if (_navigation.length !== 0 & _container.length !== 0) {
1476                    t.initNavigation(_navigation, _container);
1477                    t.initCalendarMonth(_navigation, _container);
1478                    t.initCalendarDays(_navigation, _container);
1479                    t.initCalendarEvents(_navigation, _container);
1480                }
1481            },
1482            initNavigation: function (_navigation, _container) {
1483                var t = this,
1484                    _parentNav = _navigation.find('.listing-parent li'),
1485                    _typeNav = _navigation.find('.listing-type li');
1486
1487                _parentNav.each(function () {
1488                    var _btn = $(this);
1489
1490                    _btn.off().on('click', function () {
1491                        _container.attr('data-parent-id', _btn.data('parent-id'));
1492                        t.load(_navigation, _container);
1493                    });
1494                });
1495                _typeNav.each(function () {
1496                    var _btn = $(this);
1497
1498                    _btn.off().on('click', function () {
1499                        _container.removeClass('type-calendar type-listing').addClass(_btn.data('listing-type'));
1500                        _navigation.find('.listing-type li.active').removeClass('active');
1501                        _btn.addClass('active');
1502                    });
1503                });
1504            },
1505            initCalendarMonth: function (_navigation, _container) {
1506                var t = this,
1507                    _prevM = _container.find('.month .prev'),
1508                    _nextM = _container.find('.month .next'),
1509                    _currM = _container.find('.month .today');
1510
1511                _prevM.off().on('click', function () {
1512                    var _currMS = parseInt(_container.attr('data-ms')),
1513                        _currME = parseInt(_container.attr('data-me')),
1514                        _filter = _container.attr('data-filter');
1515
1516                    _container.attr('data-filter', _filter.replace(_currMS, $(this).data('ms')).replace(_currMS, $(this).data('ms')).replace(_currME, $(this).data('me')).replace(_currME, $(this).data('me')));
1517                    _container.attr('data-ms', $(this).data('ms'));
1518                    _container.attr('data-me', $(this).data('me'));
1519                    t.load(_navigation, _container);
1520                });
1521                _nextM.off().on('click', function () {
1522                    var _currMS = parseInt(_container.attr('data-ms')),
1523                        _currME = parseInt(_container.attr('data-me')),
1524                        _filter = _container.attr('data-filter');
1525
1526                    _container.attr('data-filter', _filter.replace(_currMS, $(this).data('ms')).replace(_currMS, $(this).data('ms')).replace(_currME, $(this).data('me')).replace(_currME, $(this).data('me')));
1527                    _container.attr('data-ms', $(this).data('ms'));
1528                    _container.attr('data-me', $(this).data('me'));
1529                    t.load(_navigation, _container);
1530                });
1531                if (_currM.length !== 0) {
1532                    _currM.off().on('click', function () {
1533                        var _currMS = parseInt(_container.attr('data-ms')),
1534                            _currME = parseInt(_container.attr('data-me')),
1535                            _filter = _container.attr('data-filter');
1536
1537                        _container.attr('data-filter', _filter.replace(_currMS, $(this).data('ms')).replace(_currMS, $(this).data('ms')).replace(_currME, $(this).data('me')).replace(_currME, $(this).data('me')));
1538                        _container.attr('data-ms', $(this).data('ms'));
1539                        _container.attr('data-me', $(this).data('me'));
1540                        t.load(_navigation, _container);
1541                    });
1542                }
1543            },
1544            initCalendarDays: function (_navigation, _container) {
1545                var t = this,
1546                    _days = _container.find('.events-calendar .calendar .day');
1547                _dContainer = _container.find('.events-calendar .calendar .events .inner');
1548                _parentId = _container.attr('data-parent-id'),
1549                    _type = _container.attr('data-type'),
1550                    _copy = _container.attr('data-copy'),
1551                    _direct = _container.attr('data-direct'),
1552                    _order = _container.attr('data-order'),
1553                    _count = parseInt(_container.attr('data-count')),
1554                    _template = _container.attr('data-template').replace('events.html', 'day-details.html'),
1555                    _page = 1;
1556
1557                _days.each(function () {
1558                    var _day = $(this),
1559                        _dayS = _day.data('ds'),
1560                        _dayE = _day.data('de'),
1561                        _filter = '{"$or9":[{"$and":[{"object_start_ts":{"$gte":' + _dayS + '}},{"object_start_ts":{"$lte":' + _dayE + '}}]},{"$and":[{"object_end_ts":{"$gte":' + _dayS + '}},{"object_end_ts":{"$lte":' + _dayE + '}}]},{"$and":[{"object_start_ts":{"$lte":' + _dayS + '}},{"object_end_ts":{"$gte":' + _dayE + '}}]}]}';
1562
1563                    _day.off().on('click', function () {
1564                        if (!_day.hasClass('empty')) {
1565                            $.ajax({
1566                                url: '/shared/listing.php',
1567                                data: {
1568                                    parent_id: _parentId,
1569                                    type: _type,
1570                                    copy: _copy === true ? 'true' : 'false',
1571                                    direct: _direct === true ? 'true' : 'false',
1572                                    order: _order,
1573                                    count: _count * _page,
1574                                    filter: _filter,
1575                                    ds: _dayS,
1576                                    template: _template
1577                                },
1578                                dataType: 'html',
1579                                beforeSend: function () {
1580                                },
1581                                success: function (r) {
1582                                    _container.find('.events-calendar .calendar .current').removeClass('current');
1583                                    _day.addClass('current');
1584                                    _dContainer.html(r);
1585                                    t.initCalendarEvents(_navigation, _container);
1586                                },
1587                                error: function () {
1588                                }
1589                            });
1590                        }
1591                    });
1592                });
1593            },
1594            initCalendarEvents: function (_navigation, _container) {
1595                var _events = _container.find('.events-calendar .calendar .events .item');
1596
1597                _events.each(function () {
1598                    var _event = $(this);
1599
1600                    _event.find('.item-title').off().on('click', function () {
1601                        if (!_container.hasClass('animating')) {
1602                            _container.addClass('animating');
1603
1604                            if (_event.hasClass('expanded')) {
1605                                _event.find('.item-data').slideUp(300, function () {
1606                                    _event.removeClass('expanded');
1607                                    _container.removeClass('animating');
1608                                });
1609                            } else {
1610                                var _expEvent = _container.find('.events-calendar .calendar .events .expanded')
1611                                if (_expEvent.length !== 0) {
1612                                    _expEvent.find('.item-data').slideUp(300, function () {
1613                                        _expEvent.removeClass('expanded');
1614                                        _event.find('.item-data').slideDown(300, function () {
1615                                            _event.addClass('expanded');
1616                                            _container.removeClass('animating');
1617                                        });
1618                                    });
1619                                } else {
1620                                    _event.find('.item-data').slideDown(300, function () {
1621                                        _event.addClass('expanded');
1622                                        _container.removeClass('animating');
1623                                    });
1624                                }
1625                            }
1626                        }
1627                    });
1628                });
1629            },
1630            load: function (_navigation, _container) {
1631                var t = this,
1632                    _parentId = _container.attr('data-parent-id'),
1633                    _type = _container.attr('data-type'),
1634                    _copy = _container.attr('data-copy'),
1635                    _direct = _container.attr('data-direct'),
1636                    _order = _container.attr('data-order'),
1637                    _count = parseInt(_container.attr('data-count')),
1638                    _categories = _container.attr('data-categories'),
1639                    _filter = JSON.parse(_container.attr('data-filter') !== '' ? decodeURIComponent(_container.attr('data-filter')) : '{}'),
1640                    _ms = _container.attr('data-ms'),
1641                    _me = _container.attr('data-me'),
1642                    _template = _container.attr('data-template'),
1643                    _page = 1;
1644
1645                if (!_container.hasClass('loading')) {
1646                    $.ajax({
1647                        url: '/shared/listing.php',
1648                        data: {
1649                            parent_id: _parentId,
1650                            type: _type,
1651                            copy: _copy === true ? 'true' : 'false',
1652                            direct: _direct === true ? 'true' : 'false',
1653                            order: _order,
1654                            count: _count * _page,
1655                            categories: _categories,
1656                            ms: _ms,
1657                            me: _me,
1658                            filter: JSON.stringify(_filter),
1659                            template: _template
1660                        },
1661                        dataType: 'html',
1662                        beforeSend: function () {
1663                            _container.addClass('loading');
1664                        },
1665                        success: function (r) {
1666                            _navigation.find('.listing-parent li.active').removeClass('active');
1667                            _navigation.find('.listing-parent li[data-parent-id="' + _parentId + '"]').addClass('active');
1668                            _container.html(r);
1669                            t.initCalendarEvents(_navigation, _container);
1670                            t.initCalendarMonth(_navigation, _container);
1671                            t.initCalendarDays(_navigation, _container);
1672                            _container.removeClass('loading');
1673                        },
1674                        error: function () {
1675                            _container.removeClass('loading');
1676                        }
1677                    });
1678                }
1679            }
1680        },
1681        streamCurrent: {
1682            to: null,
1683            init: function () {
1684                var t = this,
1685                    _streamCurrent = $('.top-audio-stream');
1686
1687                if (_streamCurrent.length !== 0) {
1688                    t.setActiveItem(_streamCurrent);
1689                }
1690            },
1691            setActiveItem: function (_streamCurrent) {
1692                var t = this,
1693                    _currentTS = Math.floor((new Date()).getTime() / 1000),
1694                    _activeItem = _streamCurrent.find('.item.active'),
1695                    _items = _streamCurrent.find('.item'),
1696                    _streamBroadcast = $('.top-audio-stream .stream-broadcast');
1697
1698                clearTimeout(t.to);
1699
1700                _items.each(function () {
1701                    var _item = $(this),
1702                        _startTS = parseInt(0 + _item.data('broadcast-start')),
1703                        _endTS = parseInt(0 + _item.data('broadcast-end'));
1704
1705                    if (_startTS < _currentTS && _endTS > _currentTS) {
1706                        if (!_item.hasClass('active')) {
1707                            _activeItem.removeClass('active');
1708                            _item.addClass('active');
1709                        }
1710                    }
1711                });
1712
1713                t.to = setTimeout(function () {
1714                    t.setActiveItem(_streamCurrent)
1715                }, 60000);
1716            }
1717        },
1718        epgToday: {
1719            to: null,
1720            init: function () {
1721                var t = this,
1722                    _epgToday = $('.epg-today-module');
1723
1724                if (_epgToday.length !== 0) {
1725                    t.setActiveItem(_epgToday);
1726                }
1727            },
1728            setActiveItem: function (_epgToday) {
1729                var t = this,
1730                    _currentTS = (new Date()),
1731                    _currentDate = _currentTS.getFullYear() + (_currentTS.getMonth() < 10 ? '-0' : '-') + _currentTS.getMonth() + (_currentTS.getDate() < 10 ? '-0' : '-') + _currentTS.getDate(),
1732                    _activeItem = _epgToday.find('.item.active'),
1733                    _items = _epgToday.find('.item');
1734
1735                clearTimeout(t.to);
1736
1737                _items.each(function () {
1738                    var _item = $(this),
1739                        _itemDate = _item.data('date');
1740
1741                    if (_itemDate === _currentDate) {
1742                        if (!_item.hasClass('active')) {
1743                            _activeItem.removeClass('active');
1744                            _item.addClass('active');
1745                        }
1746                    }
1747                });
1748
1749                t.to = setTimeout(function () {
1750                    t.setActiveItem(_epgToday)
1751                }, 60000);
1752            }
1753        },
1754        epgCurrent: {
1755            to: null,
1756            init: function () {
1757                var t = this,
1758                    _epgCurrent = $('.epg-current').length !== 0 ? $('.epg-current') : $('.epg-current-module');
1759
1760                if (_epgCurrent.length !== 0) {
1761                    t.setActiveItem(_epgCurrent);
1762                    t.initItems(_epgCurrent);
1763                }
1764            },
1765            setActiveItem: function (_epgCurrent) {
1766                var t = this,
1767                    _currentTS = Math.floor((new Date()).getTime() / 1000),
1768                    _activeItem = _epgCurrent.find('.item.active'),
1769                    _items = _epgCurrent.find('.item'),
1770                    _noItems = _epgCurrent.find('.no-items');
1771                clearTimeout(t.to);
1772
1773                _items.each(function () {
1774                    var _item = $(this),
1775                        _itemTime = _item.find('.item-time').html(),
1776                        _itemTitle = _item.find('.item-title').html(),
1777                        _startTS = parseInt(0 + _item.data('broadcast-start')),
1778                        _endTS = parseInt(0 + _item.data('broadcast-end'));
1779
1780                    if (_startTS <= _currentTS && _endTS >= _currentTS) {
1781                        if (!_item.hasClass('active')) {
1782                            _activeItem.removeClass('active');
1783                            _item.addClass('active');
1784                        }
1785                    }
1786                });
1787
1788                _epgCurrent.find('.item.active').length === 0 ? _noItems.show() : _noItems.hide();
1789                t.to = setTimeout(function () {
1790                    t.setActiveItem(_epgCurrent)
1791                }, 60000);
1792            },
1793            initItems: function (_epgCurrent) {
1794                _epgCurrent.find('.item').each(function () {
1795                    var _item = $(this),
1796                        _expand = _item.find('.item-expand'),
1797                        _collapse = _item.find('.item-collapse'),
1798                        _more = _item.find('.item-more');
1799
1800                    if (_expand.length !== 0 && _collapse.length !== 0 && _more.length !== 0) {
1801                        _expand.off().on('click', function () {
1802                            if (!_item.hasClass('animating')) {
1803                                _item.addClass('animating');
1804                                _more.slideDown(250, function () {
1805                                    _item.removeClass('animating');
1806                                    _item.addClass('expanded');
1807                                });
1808                            }
1809                        });
1810                        _collapse.off().on('click', function () {
1811                            if (!_item.hasClass('animating')) {
1812                                _item.addClass('animating');
1813                                _more.slideUp(250, function () {
1814                                    _item.removeClass('animating');
1815                                    _item.removeClass('expanded');
1816                                });
1817                            }
1818                        });
1819                    }
1820                });
1821            },
1822            load: function (channelId, day) {
1823                var t = this,
1824                    _epgCurrent = $('.epg-current');
1825
1826                clearTimeout(t.to);
1827                $.ajax({
1828                    url: '/shared/listing.php',
1829                    data: {
1830                        parent_id: channelId,
1831                        type: 'directory_epg',
1832                        copy: 'false',
1833                        direct: 'true',
1834                        order: 'position,1',
1835                        count: -1,
1836                        d: day,
1837                        template: 'epg/epg-current.html'
1838                    },
1839                    dataType: 'html',
1840                    beforeSend: function () {
1841                        _epgCurrent.addClass('loading');
1842                    },
1843                    success: function (r) {
1844                        _epgCurrent.parent().replaceWith(r);
1845                        t.init();
1846                    },
1847                    error: function () {
1848                        _epgCurrent.removeClass('loading');
1849                    }
1850                });
1851            }
1852        },
1853        epgNext: {
1854            to: null,
1855            init: function () {
1856                var t = this,
1857                    _epgNext = $('.epg-next-module');
1858
1859                if (_epgNext.length !== 0) {
1860                    t.setActiveItem(_epgNext);
1861                    t.initItems(_epgNext);
1862                }
1863            },
1864            setActiveItem: function (_epgNext) {
1865                var t = this,
1866                    _currentTS = Math.floor((new Date()).getTime() / 1000),
1867                    _activeItem = _epgNext.find('.item.active'),
1868                    _items = _epgNext.find('.item'),
1869                    _nextFound = false;
1870
1871                clearTimeout(t.to);
1872
1873                _items.each(function () {
1874                    var _item = $(this),
1875                        _startTS = parseInt(0 + _item.data('broadcast-start'));
1876
1877                    if (_nextFound === false && _startTS > _currentTS) {
1878                        _activeItem.removeClass('active');
1879                        _item.addClass('active');
1880                        _nextFound = true;
1881                    }
1882                });
1883
1884                t.to = setTimeout(function () {
1885                    t.setActiveItem(_epgNext)
1886                }, 60000);
1887            },
1888            initItems: function (_epgNext) {
1889                _epgNext.find('.item').each(function () {
1890                    var _item = $(this),
1891                        _expand = _item.find('.item-expand'),
1892                        _collapse = _item.find('.item-collapse'),
1893                        _more = _item.find('.item-more');
1894
1895                    if (_expand.length !== 0 && _collapse.length !== 0 && _more.length !== 0) {
1896                        _expand.off().on('click', function () {
1897                            if (!_item.hasClass('animating')) {
1898                                _item.addClass('animating');
1899                                _more.slideDown(250, function () {
1900                                    _item.removeClass('animating');
1901                                    _item.addClass('expanded');
1902                                });
1903                            }
1904                        });
1905                        _collapse.off().on('click', function () {
1906                            if (!_item.hasClass('animating')) {
1907                                _item.addClass('animating');
1908                                _more.slideUp(250, function () {
1909                                    _item.removeClass('animating');
1910                                    _item.removeClass('expanded');
1911                                });
1912                            }
1913                        });
1914                    }
1915                });
1916            }
1917        },
1918        epgModule: {
1919            init: function () {
1920                var t = this,
1921                    _epgNav = $('.epg-navigation'),
1922                    _epgItems = $('.epg-items');
1923
1924                if (_epgNav.length !== 0 && _epgItems.length !== 0) {
1925                    t.initSlider(_epgNav);
1926                    t.initChannels(_epgNav, _epgItems);
1927                    t.initDays(_epgNav, _epgItems);
1928                    t.initItems(_epgItems);
1929                }
1930            },
1931            initSlider: function (_epgNav) {
1932                var t = this,
1933                    container = _epgNav.find('.container'),
1934                    ul = container.find('ul'),
1935                    li = container.find('li'),
1936                    prevBtn = _epgNav.find('.prev'),
1937                    nextBtn = _epgNav.find('.next'),
1938                    contW = container.width(),
1939                    liW = 0,
1940                    ulW = 0,
1941                    liPerCont = 0,
1942                    moveFactor = 0,
1943                    currentPos = 0,
1944                    currentL = 0;
1945
1946                li.each(function () {
1947                    liW = $(this).outerWidth(true);
1948                    ulW += liW;
1949
1950                    if ($(this).hasClass('active')) {
1951                        currentPos = $(this).index() + 1;
1952                    }
1953                });
1954
1955                liW = li.first().outerWidth(true);
1956
1957                liPerCont = Math.ceil(contW / liW);
1958                moveFactor = liPerCont * liW;
1959                if (currentPos > liPerCont / 2) {
1960                    currentL = (currentPos - Math.ceil(liPerCont / 2)) * liW;
1961                }
1962                ul.css('width', ulW);
1963                if (ulW <= contW) {
1964                    ul.css('left', (contW - ulW) / 2);
1965                } else {
1966                    ul.css('left', ulW - currentL >= contW ? -currentL : (contW - ulW > 0 ? 0 : contW - ulW));
1967                }
1968                t.toggleButtons(_epgNav);
1969
1970                $(window).off('resize.epg').on('resize.epg', function () {
1971                    t.positionUL(_epgNav);
1972                });
1973                prevBtn.off().on('click', function () {
1974                    var _container = _epgNav.find('.container'),
1975                        _ul = _container.find('ul'),
1976                        _contW = _container.width(),
1977                        _ulW = _ul.width(),
1978                        _ulLeft = parseInt(_ul.css('left').replace('px', '')),
1979                        _liW = _ul.find('li').first().outerWidth(true),
1980                        _liPerCont = Math.ceil(_contW / _liW),
1981                        _moveFactor = _liPerCont * liW,
1982                        _newLeft = _ulLeft + _moveFactor <= 0 ? _ulLeft + _moveFactor : 0;
1983
1984                    if ($(this).hasClass('active')) {
1985                        ul.animate({'left': _newLeft}, 500, function () {
1986                            t.toggleButtons(_epgNav);
1987                        });
1988                    }
1989                });
1990                nextBtn.off().on('click', function () {
1991                    var _container = _epgNav.find('.container'),
1992                        _ul = _container.find('ul'),
1993                        _contW = _container.width(),
1994                        _ulW = _ul.width(),
1995                        _ulLeft = parseInt(_ul.css('left').replace('px', '')),
1996                        _liW = _ul.find('li').first().outerWidth(true),
1997                        _liPerCont = Math.ceil(_contW / _liW),
1998                        _moveFactor = _liPerCont * liW,
1999                        _newLeft = _ulLeft - _moveFactor >= _contW - _ulW ? _ulLeft - _moveFactor : _contW - _ulW;
2000
2001                    if ($(this).hasClass('active')) {
2002                        ul.animate({'left': _newLeft}, 500, function () {
2003                            t.toggleButtons(_epgNav);
2004                        });
2005                    }
2006                });
2007            },
2008            positionUL: function (_epgNav) {
2009                var t = this,
2010                    container = _epgNav.find('.container'),
2011                    ul = container.find('ul'),
2012                    li = container.find('li'),
2013                    contW = container.width(),
2014                    liW = 0,
2015                    ulW = 0,
2016                    liPerCont = 0,
2017                    moveFactor = 0,
2018                    currentPos = 0,
2019                    currentL = 0;
2020
2021                li.each(function () {
2022                    liW = $(this).outerWidth(true);
2023                    ulW += liW;
2024
2025                    if ($(this).hasClass('active')) {
2026                        currentPos = $(this).index() + 1;
2027                    }
2028                });
2029
2030                liW = li.first().outerWidth(true);
2031
2032                liPerCont = Math.ceil(contW / liW);
2033                moveFactor = liPerCont * liW;
2034                if (currentPos > liPerCont / 2) {
2035                    currentL = (currentPos - Math.ceil(liPerCont / 2)) * liW;
2036                }
2037                ul.css('width', ulW);
2038                if (ulW <= contW) {
2039                    ul.css('left', (contW - ulW) / 2);
2040                } else {
2041                    ul.css('left', ulW - currentL >= contW ? -currentL : (contW - ulW > 0 ? 0 : contW - ulW));
2042                }
2043                t.toggleButtons(_epgNav);
2044            },
2045            toggleButtons: function (_epgNav) {
2046                var container = _epgNav.find('.container'),
2047                    ul = container.find('ul'),
2048                    prevBtn = _epgNav.find('.prev'),
2049                    nextBtn = _epgNav.find('.next'),
2050                    contW = container.width(),
2051                    ulW = ul.width(),
2052                    ulLeft = parseInt(ul.css('left').replace('px', ''));
2053
2054                if (ulW > contW && ulLeft < 0) {
2055                    prevBtn.addClass('active');
2056                } else {
2057                    prevBtn.removeClass('active');
2058                }
2059                if (ulW > contW && ulLeft > contW - ulW) {
2060                    nextBtn.addClass('active');
2061                } else {
2062                    nextBtn.removeClass('active');
2063                }
2064            },
2065            initChannels: function (_epgNav, _epgItems) {
2066                var t = this,
2067                    _channels = _epgNav.find('.epg-channels li');
2068
2069                _channels.each(function () {
2070                    var _channel = $(this);
2071
2072                    _channel.off().on('click', function () {
2073                        _epgNav.find('.epg-channels li.active').removeClass('active');
2074                        _channel.addClass('active');
2075                        t.loadNavigation(_epgNav, _epgItems);
2076                    });
2077                });
2078            },
2079            initDays: function (_epgNav, _epgItems) {
2080                var t = this,
2081                    _days = _epgNav.find('.epg-days li');
2082
2083                _days.each(function () {
2084                    var _day = $(this);
2085
2086                    _day.off().on('click', function () {
2087                        _epgNav.find('.epg-days li.active').removeClass('active');
2088                        _day.addClass('active');
2089                        t.loadItems(_epgNav, _epgItems);
2090                    });
2091                });
2092            },
2093            initItems: function (_epgItems) {
2094                _epgItems.find('.item').each(function () {
2095                    var _item = $(this),
2096                        _expand = _item.find('.item-expand'),
2097                        _collapse = _item.find('.item-collapse'),
2098                        _more = _item.find('.item-more');
2099
2100                    if (_expand.length !== 0 && _collapse.length !== 0 && _more.length !== 0) {
2101                        _expand.off().on('click', function () {
2102                            if (!_item.hasClass('animating')) {
2103                                _item.addClass('animating');
2104                                _more.slideDown(250, function () {
2105                                    _item.removeClass('animating');
2106                                    _item.addClass('expanded');
2107                                });
2108                            }
2109                        });
2110                        _collapse.off().on('click', function () {
2111                            if (!_item.hasClass('animating')) {
2112                                _item.addClass('animating');
2113                                _more.slideUp(250, function () {
2114                                    _item.removeClass('animating');
2115                                    _item.removeClass('expanded');
2116                                });
2117                            }
2118                        });
2119                    }
2120                });
2121            },
2122            loadNavigation: function (_epgNav, _epgItems) {
2123                var t = this,
2124                    _days = _epgNav.find('.epg-days');
2125                _channelId = _epgNav.find('.epg-channels li.active').attr('data-channel-id');
2126
2127                if (!_epgNav.hasClass('loading') && !_epgItems.hasClass('loading')) {
2128                    $.ajax({
2129                        url: '/shared/listing.php',
2130                        data: {
2131                            parent_id: _channelId,
2132                            type: 'directory_epg',
2133                            copy: 'true',
2134                            direct: 'true',
2135                            order: 'position,1',
2136                            count: -1,
2137                            d: _epgNav.find('.epg-days li.active').index() + 1,
2138                            template: 'epg/epg-days.html'
2139                        },
2140                        dataType: 'html',
2141                        beforeSend: function () {
2142                            _epgItems.addClass('loading');
2143                            _epgNav.addClass('loading');
2144                        },
2145                        success: function (r) {
2146                            _days.replaceWith(r);
2147                            _epgItems.removeClass('loading');
2148                            _epgNav.removeClass('loading');
2149
2150                            t.positionUL(_epgNav);
2151                            t.initDays(_epgNav, _epgItems);
2152                            t.loadItems(_epgNav, _epgItems);
2153                        },
2154                        error: function () {
2155                            _epgItems.removeClass('loading');
2156                            _epgNav.removeClass('loading');
2157                        }
2158                    });
2159                }
2160            },
2161            loadItems: function (_epgNav, _epgItems) {
2162                var t = this,
2163                    _directoryId = _epgNav.find('.epg-days li.active').attr('data-directory-id');
2164
2165                if (!_epgNav.hasClass('loading') && !_epgItems.hasClass('loading')) {
2166                    $.ajax({
2167                        url: '/shared/listing.php',
2168                        data: {
2169                            parent_id: _directoryId,
2170                            type: 'epg_item',
2171                            copy: 'true',
2172                            direct: 'true',
2173                            order: 'release_date,1',
2174                            count: -1,
2175                            template: 'epg/epg-items.html'
2176                        },
2177                        dataType: 'html',
2178                        beforeSend: function () {
2179                            _epgItems.addClass('loading');
2180                            _epgNav.addClass('loading');
2181                        },
2182                        success: function (r) {
2183                            _epgItems.find('.items').html(r);
2184                            t.initItems(_epgItems);
2185                            _epgItems.removeClass('loading');
2186                            _epgNav.removeClass('loading');
2187                        },
2188                        error: function () {
2189                            _epgItems.removeClass('loading');
2190                            _epgNav.removeClass('loading');
2191                        }
2192                    });
2193                }
2194            }
2195        },
2196        mmrMap: {
2197            errCnt: 0,
2198            init: function () {
2199                var t = this,
2200                    mapConfig = {
2201                        center: {lat: 54.2397005, lng: 15.8673641},
2202                        zoom: 11,
2203                        mapTypeControl: false,
2204                        mapTypeControlOptions: {
2205                            style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
2206                            position: google.maps.ControlPosition.LEFT_TOP
2207                        },
2208                        zoomControl: true,
2209                        zoomControlOptions: {
2210                            position: google.maps.ControlPosition.RIGHT_BOTTOM
2211                        },
2212                        scrollwheel: false,
2213                        scaleControl: true,
2214                        streetViewControl: false,
2215                        streetViewControlOptions: {
2216                            position: google.maps.ControlPosition.RIGHT_BOTTOM
2217                        },
2218                        fullscreenControl: true
2219                    };
2220
2221                rk.map = new google.maps.Map(document.getElementById('mmr-map'), mapConfig);
2222                rk.mapInfoWindow = new google.maps.InfoWindow({content: '', zIndex: 9999999});
2223                t.addMapControlls();
2224                t.loadMarkers();
2225            },
2226            addMapControlls: function () {
2227                var t = this,
2228                    _mcCtrl = $('.marker-choice-ctrl'),
2229                    mcCtrl = document.getElementById('mmr-map-mc-ctrl');
2230
2231                _mcCtrl.find('.current').off().on('click', function () {
2232                    if (!_mcCtrl.hasClass('animating')) {
2233                        _mcCtrl.addClass('animating');
2234
2235                        if (_mcCtrl.hasClass('expanded')) {
2236                            _mcCtrl.find('.options').slideUp(250, function () {
2237                                _mcCtrl.removeClass('expanded');
2238                                _mcCtrl.removeClass('animating');
2239                            });
2240                        } else {
2241                            _mcCtrl.find('.options').slideDown(250, function () {
2242                                _mcCtrl.addClass('expanded');
2243                                _mcCtrl.removeClass('animating');
2244                            });
2245                        }
2246                    }
2247                });
2248                _mcCtrl.find('input[type="checkbox"]').each(function () {
2249                    var cb = $(this),
2250                        markerType = cb.val();
2251
2252                    cb.off().on('change', function () {
2253                        if ($(this).is(':checked')) {
2254                            t.showMarkers(markerType);
2255                        } else {
2256                            t.hideMarkers(markerType);
2257                        }
2258                    });
2259                });
2260                rk.map.controls[google.maps.ControlPosition.LEFT_TOP].push(mcCtrl);
2261            },
2262            loadMarkers: function () {
2263                var t = this,
2264                    visibleTypes = $('.marker-choice-ctrl input[type="checkbox"]:checked');
2265
2266                $.ajax({
2267                    url: '/shared/listing.php',
2268                    data: {
2269                        parent_id: 27186393,
2270                        type: 'place',
2271                        direct: 'false',
2272                        copy: 'false',
2273                        count: -1,
2274                        order: 'position,1',
2275                        template: 'mmr/markers-json.html'
2276                    },
2277                    dataType: 'json',
2278                    success: function (r) {
2279                        var marker = $('.city-marker'),
2280                            id = 0;
2281
2282                        for (i in r) {
2283                            t.addMarker(r[i]);
2284                        }
2285                        visibleTypes.each(function () {
2286                            t.showMarkers($(this).val());
2287                        });
2288                        if (marker.length !== 0) {
2289                            id = marker.data('id');
2290                            if (rk.mapMarkers[id]) {
2291                                rk.map.setCenter(rk.mapMarkers[id].getPosition());
2292                                rk.map.setZoom(rk.mapMarkers[id]._zoom);
2293                                setTimeout(function () {
2294                                    t.showInfoWindow(rk.mapMarkers[id])
2295                                }, 200);
2296                            }
2297                        }
2298                    },
2299                    error: function () {
2300                        if (t.errCnt < 3) {
2301                            t.loadMarkers();
2302                            t.errCnt++;
2303                        } else {
2304                            t.hideMarkerButtons();
2305                        }
2306                    }
2307                });
2308            },
2309            addMarker: function (marker) {
2310                var t = this;
2311
2312                rk.mapMarkers[marker.id] = new google.maps.Marker({
2313                    _id: marker.id,
2314                    _name: marker.name,
2315                    _type: marker.type,
2316                    _img: marker.img,
2317                    _url: marker.url,
2318                    _zoom: marker.zoom,
2319                    icon: 'https://s.prk24.pl/p/gfx/sprites/map-icon-' + marker.type + '.png',
2320                    position: {
2321                        lat: marker.lat,
2322                        lng: marker.lng
2323                    },
2324                    draggable: true,
2325                    map: rk.map,
2326                    visible: false
2327                });
2328                rk.mapMarkers[marker.id].addListener('click', function () {
2329                    t.showInfoWindow(this);
2330                    console.log(this.getPosition());
2331                });
2332                if (!rk.mapMarkersByType[marker.type]) {
2333                    rk.mapMarkersByType[marker.type] = [];
2334                }
2335                rk.mapMarkersByType[marker.type].push(marker.id);
2336            },
2337            showInfoWindow: function (m) {
2338                var mInfo = $('<div class="marker-info"></div>');
2339                content = $('<div></div>');
2340
2341                if (typeof m._name !== 'undefined' && m._name.trim() !== '') {
2342                    mInfo.append($('<div class="name">' + m._name.trim() + '</div>'));
2343                }
2344                if (typeof m._img !== 'undefined' && m._img.trim() !== '') {
2345                    mInfo.append($('<div class="img"><img src="' + m._img.trim() + '"/></div>'));
2346                }
2347                if (typeof m._url !== 'undefined' && m._url.trim() !== '') {
2348                    mInfo.append($('<a class="btn" href="' + m._url.trim() + '">więcej <i>&raquo;</i></a>'));
2349                }
2350                if (!m.getVisible()) {
2351                    m.setVisible(true);
2352                }
2353                rk.mapInfoWindow.setContent(content.append(mInfo).html());
2354                rk.mapInfoWindow.open(rk.map, m);
2355            },
2356            hideMarkers: function (type) {
2357                if (typeof type === 'undefined' || type === 'all') {
2358                    for (id in rk.mapMarkers) {
2359                        rk.mapMarkers[id].setVisible(false);
2360                    }
2361                } else if (rk.mapMarkersByType[type]) {
2362                    for (i in rk.mapMarkersByType[type]) {
2363                        rk.mapMarkers[rk.mapMarkersByType[type][i]].setVisible(false);
2364                    }
2365                }
2366            },
2367            showMarkers: function (type) {
2368                if (typeof type === 'undefined' || type === 'all') {
2369                    for (id in rk.mapMarkers) {
2370                        rk.mapMarkers[id].setVisible(true);
2371                    }
2372                } else if (rk.mapMarkersByType[type]) {
2373                    for (i in rk.mapMarkersByType[type]) {
2374                        rk.mapMarkers[rk.mapMarkersByType[type][i]].setVisible(true);
2375                    }
2376                }
2377            },
2378            initMarkerButtons: function () {
2379                var t = this,
2380                    _btns = $('*[data-marker-id]');
2381
2382                _btns.each(function () {
2383                    var btn = $(this),
2384                        id = btn.data('marker-id');
2385
2386                    btn.off().on('click', function (e) {
2387                        e.preventDefault();
2388                        e.stopPropagation();
2389                        e.stopImmediatePropagation();
2390
2391                        if (rk.mapMarkers[id]) {
2392                            $('html,body').animate({'scrollTop': ($('.mmr-map').offset().top - 75) + 'px'}, 500, function () {
2393                                rk.map.setCenter(rk.mapMarkers[id].getPosition());
2394                                rk.map.setZoom(rk.mapMarkers[id]._zoom);
2395                                setTimeout(function () {
2396                                    t.showInfoWindow(rk.mapMarkers[id])
2397                                }, 200);
2398                            });
2399                        }
2400                    });
2401                });
2402            },
2403            hideMarkerButtons: function () {
2404                $('*[data-marker-id]').each(function () {
2405                    $(this).hide();
2406                });
2407            }
2408        },
2409        mmrRoutePlanner: {
2410            directionsDisplay: null,
2411            directionsService: null,
2412            map: null,
2413            routes: null,
2414            init: function () {
2415                var t = this,
2416                    map = $('.route-map');
2417
2418                if (map.length !== 0) {
2419                    t.initMap();
2420                }
2421            },
2422            initMap: function () {
2423                var t = this,
2424                    inputs = $('.route-inputs'),
2425                    btn = inputs.find('.button-set-route');
2426                mapConfig = {
2427                    zoom: 7,
2428                    center: {
2429                        lat: 52.5318175,
2430                        lng: 18.4950782
2431                    }
2432                };
2433
2434                t.map = new google.maps.Map(document.getElementById('route-map'), mapConfig);
2435                btn.off().on('click', function () {
2436                    t.calcRoute();
2437                });
2438            },
2439            calcRoute: function () {
2440                var t = this,
2441                    _inputs = $('.route-inputs'),
2442                    _origin = _inputs.find('input[name="origin"]').val(),
2443                    _destination = _inputs.find('input[name="destination"]').val(),
2444                    _request = {
2445                        origin: _origin,
2446                        destination: _destination,
2447                        travelMode: 'DRIVING',
2448                        provideRouteAlternatives: true
2449                    };
2450
2451                if (_origin.trim() !== '' && _destination.trim() !== '') {
2452                    if (t.directionsService === null) {
2453                        t.directionsService = new google.maps.DirectionsService();
2454                    }
2455                    t.directionsService.route(_request, function (r, s) {
2456                        t.routes = new Array();
2457                        if (s === google.maps.DirectionsStatus.OK) {
2458                            new google.maps.DirectionsRenderer({
2459                                map: t.map,
2460                                directions: r,
2461                                panel: document.getElementById('route-panel')
2462                            });
2463                        }
2464                    });
2465                }
2466            }
2467        },
2468        mmrCitiesListing: {
2469            init: function () {
2470                var t = this,
2471                    _listing = $('.mmr-cities-listing');
2472
2473                if (_listing.length !== 0) {
2474                    _listing.each(function () {
2475                        var listing = $(this);
2476
2477                        t.initFilter(listing);
2478                        t.initItems(listing);
2479                        t.initMoreBtn(listing);
2480                    });
2481                }
2482            },
2483            initFilter: function (listing) {
2484                var t = this,
2485                    page = listing.find('input[name="page"]')
2486                filter = listing.find('.listing-filter'),
2487                    items = filter.find('.item');
2488
2489                items.each(function () {
2490                    var item = $(this);
2491
2492                    item.off().on('click', function () {
2493                        if (!listing.hasClass('loading')) {
2494                            filter.find('.active').removeClass('active');
2495                            item.addClass('active');
2496                            page.val(1);
2497                            t.load(listing);
2498                            return false;
2499                        }
2500                    });
2501                });
2502            },
2503            initItems: function (listing) {
2504                var _items = listing.find('.items > .item');
2505
2506                _items.each(function () {
2507                    var item = $(this),
2508                        itemDetails = item.find('.item-details'),
2509                        ecBtn = item.find('.ec-btn');
2510
2511                    if (itemDetails.html().trim() !== '') {
2512                        item.addClass('with-details');
2513                    }
2514
2515                    ecBtn.off().on('click', function () {
2516                        if (item.hasClass('expanded')) {
2517                            itemDetails.slideUp(500, function () {
2518                                item.removeClass('expanded');
2519                            });
2520                        } else {
2521                            itemDetails.slideDown(500, function () {
2522                                item.addClass('expanded');
2523                            });
2524                        }
2525                    });
2526                });
2527                rk.modules.mmrMap.initMarkerButtons();
2528            },
2529            initMoreBtn: function (listing) {
2530                var t = this,
2531                    moreBtn = listing.find('.button-more');
2532
2533                moreBtn.each(function () {
2534                    var page = listing.find('input[name="page"]');
2535
2536                    $(this).off().on('click', function () {
2537                        if (!listing.hasClass('loading')) {
2538                            page.val(parseInt(page.val()) + 1);
2539                            t.load(listing);
2540                            return false;
2541                        }
2542                    });
2543                });
2544            },
2545            load: function (listing) {
2546                var t = this,
2547                    moreBtn = listing.find('.button-more'),
2548                    _parentId = listing.attr('data-parent-id'),
2549                    _type = listing.attr('data-type'),
2550                    _copy = listing.attr('data-copy'),
2551                    _direct = listing.attr('data-direct'),
2552                    _order = listing.attr('data-order'),
2553                    _count = parseInt(listing.attr('data-count')),
2554                    _categories = listing.attr('data-categories'),
2555                    _filter = JSON.parse(listing.attr('data-filter') !== '' ? decodeURIComponent(listing.attr('data-filter')) : '{}'),
2556                    _template = listing.attr('data-template'),
2557                    _page = parseInt(listing.find('input[name="page"]').val()),
2558                    _letter = listing.find('.listing-filter .active').data('letter'),
2559                    beforeCnt = parseInt(listing.find('.items .item').length);
2560
2561                if (!listing.hasClass('loading')) {
2562                    if (_letter !== '') {
2563                        _filter.title = {"$regex": "^" + _letter, "$options": "i"};
2564                    }
2565                    $.ajax({
2566                        url: '/shared/listing.php',
2567                        data: {
2568                            parent_id: _parentId,
2569                            type: _type,
2570                            copy: _copy === true ? 'true' : 'false',
2571                            direct: _direct === true ? 'true' : 'false',
2572                            order: _order,
2573                            count: _count * _page,
2574                            categories: _categories,
2575                            filter: JSON.stringify(_filter),
2576                            template: _template
2577                        },
2578                        dataType: 'html',
2579                        beforeSend: function () {
2580                            listing.addClass('loading');
2581                            moreBtn.hide();
2582                        },
2583                        success: function (r) {
2584                            listing.find('.categories .active').removeClass('active');
2585                            listing.find('.categories .category[data-parent-id="' + _parentId + '"]').addClass('active');
2586                            listing.find('.items .item').each(function () {
2587                                $(this).remove();
2588                            });
2589
2590                            if (r.trim() !== '') {
2591                                listing.find('.items').html(r);
2592                                t.initItems(listing);
2593                                parseInt(listing.find('.items .item').length) === beforeCnt && _page !== 1 ? moreBtn.hide() : moreBtn.show();
2594                            }
2595                            listing.removeClass('loading');
2596                        },
2597                        error: function () {
2598                            listing.removeClass('loading');
2599                        }
2600                    });
2601                }
2602            }
2603        },
2604        mmrPlacesListing: {
2605            init: function () {
2606                var t = this,
2607                    _listing = $('.mmr-places-listing');
2608
2609                if (_listing.length !== 0) {
2610                    _listing.each(function () {
2611                        var listing = $(this);
2612
2613                        t.initFilter(listing);
2614                        t.initItems(listing);
2615                        t.initMoreBtn(listing);
2616                    });
2617                }
2618            },
2619            initFilter: function (listing) {
2620                var t = this,
2621                    _fParent = listing.find('.filter-parent'),
2622                    _page = listing.find('input[name="page"]');
2623
2624                if (_fParent.length !== 0) {
2625                    _fParent.off().on('mouseenter', function () {
2626                        _fParent.addClass('hovered');
2627                    }).on('mouseleave', function () {
2628                        _fParent.removeClass('hovered');
2629                    });
2630                    _fParent.find('.current').off().on('click', function () {
2631                        _fParent.toggleClass('expanded');
2632                    });
2633                    _fParent.find('li').off().on('click', function () {
2634                        _fParent.find('li.selected').removeClass('selected');
2635                        _fParent.removeClass('expanded');
2636                        _fParent.find('.current span').html($(this).html());
2637                        listing.attr('data-parent-id', $(this).data('parent-id'));
2638                        $(this).addClass('selected');
2639                        _page.val(1);
2640                        t.load(listing);
2641                    });
2642                }
2643            },
2644            initItems: function (listing) {
2645                rk.modules.mmrMap.initMarkerButtons();
2646            },
2647            initMoreBtn: function (listing) {
2648                var t = this,
2649                    moreBtn = listing.find('.button-more');
2650
2651                moreBtn.each(function () {
2652                    var page = listing.find('input[name="page"]');
2653
2654                    $(this).off().on('click', function () {
2655                        if (!listing.hasClass('loading')) {
2656                            page.val(parseInt(page.val()) + 1);
2657                            t.load(listing);
2658                            return false;
2659                        }
2660                    });
2661                });
2662            },
2663            load: function (listing) {
2664                var t = this,
2665                    moreBtn = listing.find('.button-more'),
2666                    _parentId = listing.attr('data-parent-id'),
2667                    _type = listing.attr('data-type'),
2668                    _copy = listing.attr('data-copy'),
2669                    _direct = listing.attr('data-direct'),
2670                    _order = listing.attr('data-order'),
2671                    _count = parseInt(listing.attr('data-count')),
2672                    _categories = listing.attr('data-categories'),
2673                    _filter = JSON.parse(listing.attr('data-filter') !== '' ? decodeURIComponent(listing.attr('data-filter')) : '{}'),
2674                    _template = listing.attr('data-template'),
2675                    _page = parseInt(listing.find('input[name="page"]').val()),
2676                    beforeCnt = parseInt(listing.find('.items .item').length);
2677
2678                if (!listing.hasClass('loading')) {
2679                    $.ajax({
2680                        url: '/shared/listing.php',
2681                        data: {
2682                            parent_id: _parentId,
2683                            type: _type,
2684                            copy: _copy === true ? 'true' : 'false',
2685                            direct: _direct === true ? 'true' : 'false',
2686                            order: _order,
2687                            count: _count * _page,
2688                            categories: _categories,
2689                            filter: JSON.stringify(_filter),
2690                            template: _template
2691                        },
2692                        dataType: 'html',
2693                        beforeSend: function () {
2694                            listing.addClass('loading');
2695                            moreBtn.hide();
2696                        },
2697                        success: function (r) {
2698                            listing.find('.categories .active').removeClass('active');
2699                            listing.find('.categories .category[data-parent-id="' + _parentId + '"]').addClass('active');
2700                            listing.find('.items .item').each(function () {
2701                                $(this).remove();
2702                            });
2703
2704                            if (r.trim() !== '') {
2705                                listing.find('.items').html(r);
2706                                t.initItems(listing);
2707                                parseInt(listing.find('.items .item').length) === beforeCnt && _page !== 1 ? moreBtn.hide() : moreBtn.show();
2708                            }
2709                            listing.removeClass('loading');
2710                        },
2711                        error: function () {
2712                            listing.removeClass('loading');
2713                        }
2714                    });
2715                }
2716            }
2717        },
2718        mmrGalleriesListing: {
2719            init: function () {
2720                var t = this,
2721                    _listing = $('.mmr-galleries-listing');
2722
2723                if (_listing.length !== 0) {
2724                    _listing.each(function () {
2725                        var listing = $(this);
2726
2727                        t.initFilter(listing);
2728                        t.initMoreBtn(listing);
2729                    });
2730                }
2731            },
2732            initFilter: function (listing) {
2733                var t = this,
2734                    _fParent = listing.find('.filter-parent'),
2735                    _page = listing.find('input[name="page"]');
2736
2737                if (_fParent.length !== 0) {
2738                    _fParent.off().on('mouseenter', function () {
2739                        _fParent.addClass('hovered');
2740                    }).on('mouseleave', function () {
2741                        _fParent.removeClass('hovered');
2742                    });
2743                    _fParent.find('.current').off().on('click', function () {
2744                        _fParent.toggleClass('expanded');
2745                    });
2746                    _fParent.find('li').off().on('click', function () {
2747                        _fParent.find('li.selected').removeClass('selected');
2748                        _fParent.removeClass('expanded');
2749                        _fParent.find('.current span').html($(this).html());
2750                        listing.attr('data-parent-id', $(this).data('parent-id'));
2751                        $(this).addClass('selected');
2752                        _page.val(1);
2753                        t.load(listing);
2754                    });
2755                }
2756            },
2757            initMoreBtn: function (listing) {
2758                var t = this,
2759                    moreBtn = listing.find('.button-more');
2760
2761                moreBtn.each(function () {
2762                    var page = listing.find('input[name="page"]');
2763
2764                    $(this).off().on('click', function () {
2765                        if (!listing.hasClass('loading')) {
2766                            page.val(parseInt(page.val()) + 1);
2767                            t.load(listing);
2768                            return false;
2769                        }
2770                    });
2771                });
2772            },
2773            load: function (listing) {
2774                var t = this,
2775                    moreBtn = listing.find('.button-more'),
2776                    _parentId = listing.attr('data-parent-id'),
2777                    _type = listing.attr('data-type'),
2778                    _copy = listing.attr('data-copy'),
2779                    _direct = listing.attr('data-direct'),
2780                    _order = listing.attr('data-order'),
2781                    _count = parseInt(listing.attr('data-count')),
2782                    _categories = listing.attr('data-categories'),
2783                    _filter = JSON.parse(listing.attr('data-filter') !== '' ? decodeURIComponent(listing.attr('data-filter')) : '{}'),
2784                    _template = listing.attr('data-template'),
2785                    _page = parseInt(listing.find('input[name="page"]').val()),
2786                    beforeCnt = parseInt(listing.find('.items .item').length);
2787
2788                if (!listing.hasClass('loading')) {
2789                    $.ajax({
2790                        url: '/shared/listing.php',
2791                        data: {
2792                            parent_id: _parentId,
2793                            type: _type,
2794                            copy: _copy === true ? 'true' : 'false',
2795                            direct: _direct === true ? 'true' : 'false',
2796                            order: _order,
2797                            count: _count * _page,
2798                            categories: _categories,
2799                            filter: JSON.stringify(_filter),
2800                            template: _template
2801                        },
2802                        dataType: 'html',
2803                        beforeSend: function () {
2804                            listing.addClass('loading');
2805                            moreBtn.hide();
2806                        },
2807                        success: function (r) {
2808                            listing.find('.categories .active').removeClass('active');
2809                            listing.find('.categories .category[data-parent-id="' + _parentId + '"]').addClass('active');
2810                            listing.find('.items .item').each(function () {
2811                                $(this).remove();
2812                            });
2813
2814                            if (r.trim() !== '') {
2815                                listing.find('.items').html(r);
2816                                parseInt(listing.find('.items .item').length) === beforeCnt && _page !== 1 ? moreBtn.hide() : moreBtn.show();
2817                            }
2818                            listing.removeClass('loading');
2819                        },
2820                        error: function () {
2821                            listing.removeClass('loading');
2822                        }
2823                    });
2824                }
2825            }
2826        },
2827        mmrEventsListing: {
2828            init: function () {
2829                var t = this,
2830                    _listing = $('.mmr-events-listing');
2831
2832                if (_listing.length !== 0) {
2833                    _listing.each(function () {
2834                        var listing = $(this);
2835
2836                        t.initFilter(listing);
2837                        t.initMoreBtn(listing);
2838                    });
2839                }
2840            },
2841            initFilter: function (listing) {
2842                var t = this,
2843                    _fParent = listing.find('.filter-parent'),
2844                    _page = listing.find('input[name="page"]');
2845
2846                if (_fParent.length !== 0) {
2847                    _fParent.off().on('mouseenter', function () {
2848                        _fParent.addClass('hovered');
2849                    }).on('mouseleave', function () {
2850                        _fParent.removeClass('hovered');
2851                    });
2852                    _fParent.find('.current').off().on('click', function () {
2853                        _fParent.toggleClass('expanded');
2854                    });
2855                    _fParent.find('li').off().on('click', function () {
2856                        _fParent.find('li.selected').removeClass('selected');
2857                        _fParent.removeClass('expanded');
2858                        _fParent.find('.current span').html($(this).html());
2859                        listing.attr('data-parent-id', $(this).data('parent-id'));
2860                        $(this).addClass('selected');
2861                        _page.val(1);
2862                        t.load(listing);
2863                    });
2864                }
2865            },
2866            initMoreBtn: function (listing) {
2867                var t = this,
2868                    moreBtn = listing.find('.button-more');
2869
2870                moreBtn.each(function () {
2871                    var page = listing.find('input[name="page"]');
2872
2873                    $(this).off().on('click', function () {
2874                        if (!listing.hasClass('loading')) {
2875                            page.val(parseInt(page.val()) + 1);
2876                            t.load(listing);
2877                            return false;
2878                        }
2879                    });
2880                });
2881            },
2882            load: function (listing) {
2883                var t = this,
2884                    moreBtn = listing.find('.button-more'),
2885                    _parentId = listing.attr('data-parent-id'),
2886                    _type = listing.attr('data-type'),
2887                    _copy = listing.attr('data-copy'),
2888                    _direct = listing.attr('data-direct'),
2889                    _order = listing.attr('data-order'),
2890                    _count = parseInt(listing.attr('data-count')),
2891                    _categories = listing.attr('data-categories'),
2892                    _filter = JSON.parse(listing.attr('data-filter') !== '' ? decodeURIComponent(listing.attr('data-filter')) : '{}'),
2893                    _template = listing.attr('data-template'),
2894                    _page = parseInt(listing.find('input[name="page"]').val()),
2895                    beforeCnt = parseInt(listing.find('.items .item').length);
2896
2897                if (!listing.hasClass('loading')) {
2898                    $.ajax({
2899                        url: '/shared/listing.php',
2900                        data: {
2901                            parent_id: _parentId,
2902                            type: _type,
2903                            copy: _copy === true ? 'true' : 'false',
2904                            direct: _direct === true ? 'true' : 'false',
2905                            order: _order,
2906                            count: _count * _page,
2907                            categories: _categories,
2908                            filter: JSON.stringify(_filter),
2909                            template: _template
2910                        },
2911                        dataType: 'html',
2912                        beforeSend: function () {
2913                            listing.addClass('loading');
2914                            moreBtn.hide();
2915                        },
2916                        success: function (r) {
2917                            listing.find('.categories .active').removeClass('active');
2918                            listing.find('.categories .category[data-parent-id="' + _parentId + '"]').addClass('active');
2919                            listing.find('.items .item').each(function () {
2920                                $(this).remove();
2921                            });
2922
2923                            if (r.trim() !== '') {
2924                                listing.find('.items').html(r);
2925                                parseInt(listing.find('.items .item').length) === beforeCnt && _page !== 1 ? moreBtn.hide() : moreBtn.show();
2926                            }
2927                            listing.removeClass('loading');
2928                        },
2929                        error: function () {
2930                            listing.removeClass('loading');
2931                        }
2932                    });
2933                }
2934            }
2935        },
2936        audioPlayer: {
2937            init: function () {
2938                var t = this,
2939                    itemsSimple = $('*[data-audio-player="simple"][data-audio-id]'),
2940                    itemsFull = $('*[data-audio-player="full"][data-audio-id]');
2941
2942                itemsSimple.each(function () {
2943                    var item = $(this);
2944                    _id = item.data('audio-id');
2945
2946                    if ($('#ap-' + _id).length === 0) {
2947                        $('<div class="apc"><div id="ap-' + _id + '" class="audio-player"></div></div>').appendTo(item);
2948                    }
2949
2950                    item.off().on('click', function (e) {
2951                        var item = $(this),
2952                            itemAudioId = item.data('audio-id'),
2953                            itemAudioSrc = item.data('audio-src'),
2954                            itemTime = item.find('.audio-time'),
2955                            itemPlayer = null,
2956                            playingItem = $('*[data-audio-player="simple"][data-audio-id].playing'),
2957                            playingPlayer = playingItem.length !== 0 ? projekktor('#ap-' + playingItem.data('audio-id')) : null;
2958
2959                        e.preventDefault();
2960                        e.stopPropagation();
2961                        e.stopImmediatePropagation();
2962
2963                        if (!item.hasClass('loaded')) {
2964                            item.addClass('loading');
2965
2966                            itemPlayer = projekktor('#ap-' + itemAudioId, {
2967                                title: 'Audio Config',
2968                                poster: 'https://static.prsa.pl/images/a6f944fc-fdc9-47b9-8afe-fc505b16a14c.jpg', // obrazek, który będzie wyświetlany na wstępie, przed rozpoczęciem odtwarzania
2969                                autoplay: true,
2970                                debug: false,
2971                                iframe: false,
2972                                fullscreen: ['full'],
2973                                platforms: ['browser', 'android', 'ios', 'mse', 'native', 'videojs'],
2974                                platformsConfig: {
2975                                    mse: {
2976                                        hlsjs: {
2977                                            src: 'https://s.prk24.pl/p/js/player2/platforms/mse/hlsjs/hls.min.js',
2978                                            initVars: {
2979                                                debug: false,
2980                                                capLevelToPlayerSize: true,
2981                                                startFragPrefech: true
2982                                            }
2983                                        },
2984                                        dashjs: {
2985                                            src: 'https://s.prk24.pl/p/js/player2/platforms/mse/dashjs/dash.all.min.js',
2986                                            initVars: {
2987                                                debug: false,
2988                                                fastSwitchEnabled: true,
2989                                                limitBitrateByPortal: true,
2990                                                usePixelRatioInLimitBitrateByPortal: true,
2991                                                enableBufferOccupancyABR: true
2992                                            }
2993                                        }
2994                                    },
2995                                    videojs: {
2996                                        src: 'https://s.prk24.pl/p/js/player2/platforms/videojs/videojs.vpaid.min.js',
2997                                        css: 'https://s.prk24.pl/p/js/player2/platforms/videojs/videojs.vpaid.min.css',
2998                                        initVars: {}
2999                                    },
3000                                    flash: {
3001                                        src: 'https://s.prk24.pl/p/js/player2/platforms/flash/release/flash.swf',
3002                                        minPlatformVersion: '11.4',
3003                                        initVars: {
3004                                            plugin_hls: 'https://s.prk24.pl/p/js/player2/platforms/flash/release/
3004hls.swf',
3005                                            hls_info: false,
3006                                            hls_warn: false,
3007                                            hls_error: false,
3008                                            hls_debug: false,
3009                                            hls_debug2: false,
3010                                            hls_minbufferlength: -1,
3011                                            hls_lowbufferlength: 2,
3012                                            hls_maxbufferlength: 60,
3013                                            hls_startfromlevel: -1,
3014                                            hls_seekfromlevel: -1,
3015                                            hls_live_flushurlcache: false,
3016                                            hls_seekmode: 'ACCURATE',
3017                                            hls_manifestloadmaxretry: 3,
3018                                            hls_keyloadmaxretry: 3,
3019                                            hls_fragmentloadmaxretry: 3,
3020                                            hls_capleveltostage: true,
3021                                            hls_maxlevelcappingmode: 'downscale'
3022                                        }
3023                                    }
3024                                },
3025                                plugins: ['display', 'controlbar'],
3026                                plugin_controlbar: {
3027                                    showCuePoints: false,
3028                                    showCuePointsImmediately: false,
3029                                    showCuePointGroups: ['midroll'],
3030                                    showOnIdle: false,
3031                                    showOnStart: false,
3032                                    controlsTemplate: '<ul class="left"><li><div %{play}></div><div %{pause}></div></li></ul><ul class="right"><li><div %{vmax}></div></li><li><div %{vslider}><div %{vmarker}></div><div %{vknob}></div></div></li><li><div %{mute}></div></li><li><div %{timeleft}>%{hr_elp}:%{min_elp}:%{sec_elp} | %{hr_dur}:%{min_dur}:%{sec_dur}</div></li></ul><ul class="bottom"><li><div %{scrubber}><div %{loaded}></div><div %{playhead}></div><div %{scrubberknob}></div><div %{scrubberdrag}></div></div></li></ul><div %{scrubbertip}>%{hr_tip}:%{min_tip}:%{sec_tip}</div>'
3033                                },
3034                                playlist: [{0: {src: itemAudioSrc, type: 'audio/mp3'}}],
3035                            }, function (player) {
3036                                player.addListener('state', function (event) {
3037                                    switch (event) {
3038                                        case 'PLAYING':
3039                                            item.removeClass('loading');
3040                                            item.addClass('loaded');
3041                                            item.addClass('playing');
3042                                            break;
3043                                        case 'PAUSED':
3044                                            item.removeClass('playing');
3045                                            break;
3046                                        case 'STOPPED':
3047                                        case 'COMPLETED':
3048                                            item.removeClass('playing');
3049                                            itemTime.html('');
3050                                            break;
3051                                    }
3052                                });
3053                                player.addListener('time', function (time, obj) {
3054                                    var l = parseInt(obj.getTimeLeft()),
3055                                        leftM = Math.floor(l / 60),
3056                                        leftS = l % 60,
3057                                        leftS = leftS < 10 ? '0' + leftS : leftS;
3058
3059                                    itemTime.html(leftM + ':' + leftS);
3060                                });
3061                            });
3062                        } else {
3063                            itemPlayer = projekktor('#ap-' + itemAudioId);
3064                        }
3065
3066                        if (item.hasClass('playing')) {
3067                            itemPlayer.setPause();
3068                            item.removeClass('playing');
3069                        } else {
3070                            if (playingItem.length !== 0 && playingItem.data('audio-id') !== item.data('audio-id')) {
3071                                playingPlayer.setPause();
3072                                playingPlayer.destroy();
3073                                playingItem.find('.audio-player').removeClass('tvp tvphttp tvpstateplaying').html('');
3074                                playingItem.find('.audio-time').html('');
3075                                playingItem.removeClass('playing loaded');
3076                            }
3077                            itemPlayer.setVolume(100);
3078                            itemPlayer.setPlay();
3079                            if (item.hasClass('loaded')) {
3080                                item.addClass('playing');
3081                            }
3082                        }
3083                    });
3084                });
3085                itemsFull.each(function () {
3086                    var item = $(this),
3087                        itemAudioId = item.data('audio-id'),
3088                        itemAudioSrc = item.data('audio-src'),
3089                        itemTime = item.find('.audio-time'),
3090                        itemPlayer = null;
3091
3092                    if (!item.hasClass('loaded')) {
3093                        item.addClass('loading');
3094
3095                        itemPlayer = projekktor('#ap-' + itemAudioId, {
3096                            title: 'Audio Config',
3097                            poster: 'https://static.prsa.pl/images/a6f944fc-fdc9-47b9-8afe-fc505b16a14c.jpg', // obrazek, który będzie wyświetlany na wstępie, przed rozpoczęciem odtwarzania
3098                            autoplay: false,
3099                            debug: false,
3100                            iframe: false,
3101                            fullscreen: ['full'],
3102                            platforms: ['browser', 'android', 'ios', 'mse', 'native', 'videojs'],
3103                            platformsConfig: {
3104                                mse: {
3105                                    hlsjs: {
3106                                        src: 'https://s.prk24.pl/p/js/player2/platforms/mse/hlsjs/hls.min.js',
3107                                        initVars: {
3108                                            debug: false,
3109                                            capLevelToPlayerSize: true,
3110                                            startFragPrefech: true
3111                                        }
3112                                    },
3113                                    dashjs: {
3114                                        src: 'https://s.prk24.pl/p/js/player2/platforms/mse/dashjs/dash.all.min.js',
3115                                        initVars: {
3116                                            debug: false,
3117                                            fastSwitchEnabled: true,
3118                                            limitBitrateByPortal: true,
3119                                            usePixelRatioInLimitBitrateByPortal: true,
3120                                            enableBufferOccupancyABR: true
3121                                        }
3122                                    }
3123                                },
3124                                videojs: {
3125                                    src: 'https://s.prk24.pl/p/js/player2/platforms/videojs/videojs.vpaid.min.js',
3126                                    css: 'https://s.prk24.pl/p/js/player2/platforms/videojs/videojs.vpaid.min.css',
3127                                    initVars: {}
3128                                },
3129                                flash: {
3130                                    src: 'https://s.prk24.pl/p/js/player2/platforms/flash/release/flash.swf',
3131                                    minPlatformVersion: '11.4',
3132                                    initVars: {
3133                                        plugin_hls: 'https://s.prk24.pl/p/js/player2/platforms/flash/release/
3133hls.swf',
3134                                        hls_info: false,
3135                                        hls_warn: false,
3136                                        hls_error: false,
3137                                        hls_debug: false,
3138                                        hls_debug2: false,
3139                                        hls_minbufferlength: -1,
3140                                        hls_lowbufferlength: 2,
3141                                        hls_maxbufferlength: 60,
3142                                        hls_startfromlevel: -1,
3143                                        hls_seekfromlevel: -1,
3144                                        hls_live_flushurlcache: false,
3145                                        hls_seekmode: 'ACCURATE',
3146                                        hls_manifestloadmaxretry: 3,
3147                                        hls_keyloadmaxretry: 3,
3148                                        hls_fragmentloadmaxretry: 3,
3149                                        hls_capleveltostage: true,
3150                                        hls_maxlevelcappingmode: 'downscale'
3151                                    }
3152                                }
3153                            },
3154                            plugins: ['display', 'controlbar'],
3155                            plugin_controlbar: {
3156                                showCuePoints: false,
3157                                showCuePointsImmediately: false,
3158                                showCuePointGroups: ['midroll'],
3159                                showOnIdle: false,
3160                                showOnStart: false,
3161                                controlsTemplate: '<ul class="left"><li><div %{play}></div><div %{pause}></div></li></ul><ul class="right"><li><div %{vmax}></div></li><li><div %{vslider}><div %{vmarker}></div><div %{vknob}></div></div></li><li><div %{mute}></div></li><li><div %{timeleft}>%{hr_elp}:%{min_elp}:%{sec_elp} | %{hr_dur}:%{min_dur}:%{sec_dur}</div></li></ul><ul class="bottom"><li><div %{scrubber}><div %{loaded}></div><div %{playhead}></div><div %{scrubberknob}></div><div %{scrubberdrag}></div></div></li></ul><div %{scrubbertip}>%{hr_tip}:%{min_tip}:%{sec_tip}</div>'
3162                            },
3163                            playlist: [{0: {src: itemAudioSrc, type: 'audio/mp3'}}],
3164                        }, function (player) {
3165                            player.addListener('state', function (event) {
3166                                switch (event) {
3167                                    case 'PLAYING':
3168                                        var playingItem = $('*[data-audio-player="full"][data-audio-id].playing'),
3169                                            playingPlayer = playingItem.length !== 0 ? projekktor('#ap-' + playingItem.data('audio-id')) : null;
3170
3171                                        if (playingItem.length !== 0 && playingItem.data('audio-id') !== item.data('audio-id')) {
3172                                            playingPlayer.setPause();
3173                                            playingItem.removeClass('playing');
3174                                        }
3175
3176                                        item.removeClass('loading');
3177                                        item.addClass('loaded');
3178                                        item.addClass('playing');
3179                                        break;
3180                                    case 'PAUSED':
3181                                        item.removeClass('playing');
3182                                        break;
3183                                    case 'STOPPED':
3184                                    case 'COMPLETED':
3185                                        item.removeClass('playing');
3186                                        itemTime.html('');
3187                                        break;
3188                                }
3189                            });
3190                        });
3191                    } else {
3192                        itemPlayer = projekktor('#ap-' + itemAudioId);
3193                    }
3194                });
3195            }
3196        },
3197        koncertyListing: {
3198            init: function () {
3199                var t = this,
3200                    _listing = $('.koncerty-listing');
3201
3202                if (_listing.length !== 0) {
3203                    _listing.each(function () {
3204                        var listing = $(this);
3205
3206                        t.initFilter(listing);
3207                        t.initItems(listing);
3208                        t.initMoreBtn(listing);
3209                    });
3210                }
3211            },
3212            initFilter: function (listing) {
3213                var t = this,
3214                    page = listing.find('input[name="page"]')
3215                filter = $('.koncerty-menu'),
3216                    items = filter.find('.item');
3217
3218                items.each(function () {
3219                    var item = $(this);
3220
3221                    item.off().on('click', function () {
3222                        if (!listing.hasClass('loading')) {
3223                            listing.attr('data-parent-id', item.data('parent-id'));
3224                            filter.find('.active').removeClass('active');
3225                            item.addClass('active');
3226                            page.val(1);
3227                            t.load(listing);
3228                            return false;
3229                        }
3230                    });
3231                });
3232            },
3233            initItems: function (listing) {
3234                rk.modules.redir.init();
3235                rk.modules.audioPlayer.init();
3236                rk.modules.gallery.init();
3237            },
3238            initMoreBtn: function (listing) {
3239                var t = this,
3240                    moreBtn = listing.find('.button-more');
3241
3242                moreBtn.each(function () {
3243                    var page = listing.find('input[name="page"]');
3244
3245                    $(this).off().on('click', function () {
3246                        if (!listing.hasClass('loading')) {
3247                            page.val(parseInt(page.val()) + 1);
3248                            t.load(listing);
3249                            return false;
3250                        }
3251                    });
3252                });
3253            },
3254            load: function (listing) {
3255                var t = this,
3256                    moreBtn = listing.find('.button-more'),
3257                    _parentId = listing.attr('data-parent-id'),
3258                    _type = listing.attr('data-type'),
3259                    _copy = listing.attr('data-copy'),
3260                    _direct = listing.attr('data-direct'),
3261                    _order = listing.attr('data-order'),
3262                    _count = parseInt(listing.attr('data-count')),
3263                    _categories = listing.attr('data-categories'),
3264                    _filter = JSON.parse(listing.attr('data-filter') !== '' ? decodeURIComponent(listing.attr('data-filter')) : '{}'),
3265                    _template = listing.attr('data-template'),
3266                    _page = parseInt(listing.find('input[name="page"]').val()),
3267                    beforeCnt = parseInt(listing.find('.items .item').length);
3268
3269                if (!listing.hasClass('loading')) {
3270                    $.ajax({
3271                        url: '/shared/listing.php',
3272                        data: {
3273                            parent_id: _parentId,
3274                            type: _type,
3275                            copy: _copy === true ? 'true' : 'false',
3276                            direct: _direct === true ? 'true' : 'false',
3277                            order: _order,
3278                            count: _count * _page,
3279                            categories: _categories,
3280                            filter: JSON.stringify(_filter),
3281                            template: _template
3282                        },
3283                        dataType: 'html',
3284                        beforeSend: function () {
3285                            listing.addClass('loading');
3286                            moreBtn.hide();
3287                        },
3288                        success: function (r) {
3289                            listing.find('.categories .active').removeClass('active');
3290                            listing.find('.categories .category[data-parent-id="' + _parentId + '"]').addClass('active');
3291                            listing.find('.items .item').each(function () {
3292                                $(this).remove();
3293                            });
3294
3295                            if (r.trim() !== '') {
3296                                listing.find('.items').html(r);
3297                                t.initItems(listing);
3298                                parseInt(listing.find('.items .item').length) === beforeCnt && _page !== 1 ? moreBtn.hide() : moreBtn.show();
3299                            }
3300                            listing.removeClass('loading');
3301                        },
3302                        error: function () {
3303                            listing.removeClass('loading');
3304                        }
3305                    });
3306                }
3307            }
3308        },
3309        plytaTygodniaListing: {
3310            init: function () {
3311                var t = this,
3312                    _listing = $('.plyta-tygodnia-listing');
3313
3314                if (_listing.length !== 0) {
3315                    _listing.each(function () {
3316                        var listing = $(this);
3317
3318                        t.initItems(listing);
3319                        t.initMoreBtn(listing);
3320                    });
3321                }
3322            },
3323            initItems: function (listing) {
3324                rk.modules.redir.init();
3325            },
3326            initMoreBtn: function (listing) {
3327                var t = this,
3328                    moreBtn = listing.find('.button-more');
3329
3330                moreBtn.each(function () {
3331                    var page = listing.find('input[name="page"]');
3332
3333                    $(this).off().on('click', function () {
3334                        if (!listing.hasClass('loading')) {
3335                            page.val(parseInt(page.val()) + 1);
3336                            t.load(listing);
3337                            return false;
3338                        }
3339                    });
3340                });
3341            },
3342            load: function (listing) {
3343                var t = this,
3344                    moreBtn = listing.find('.button-more'),
3345                    _parentId = listing.attr('data-parent-id'),
3346                    _type = listing.attr('data-type'),
3347                    _copy = listing.attr('data-copy'),
3348                    _direct = listing.attr('data-direct'),
3349                    _order = listing.attr('data-order'),
3350                    _count = parseInt(listing.attr('data-count')),
3351                    _categories = listing.attr('data-categories'),
3352                    _filter = JSON.parse(listing.attr('data-filter') !== '' ? decodeURIComponent(listing.attr('data-filter')) : '{}'),
3353                    _template = listing.attr('data-template'),
3354                    _page = parseInt(listing.find('input[name="page"]').val()),
3355                    beforeCnt = parseInt(listing.find('.items .item').length);
3356
3357                if (!listing.hasClass('loading')) {
3358                    $.ajax({
3359                        url: '/shared/listing.php',
3360                        data: {
3361                            parent_id: _parentId,
3362                            type: _type,
3363                            copy: _copy === true ? 'true' : 'false',
3364                            direct: _direct === true ? 'true' : 'false',
3365                            order: _order,
3366                            count: (_count - 1) * _page + 1,
3367                            categories: _categories,
3368                            filter: JSON.stringify(_filter),
3369                            template: _template
3370                        },
3371                        dataType: 'html',
3372                        beforeSend: function () {
3373                            listing.addClass('loading');
3374                            moreBtn.hide();
3375                        },
3376                        success: function (r) {
3377                            listing.find('.categories .active').removeClass('active');
3378                            listing.find('.categories .category[data-parent-id="' + _parentId + '"]').addClass('active');
3379                            listing.find('.items .item').each(function () {
3380                                $(this).remove();
3381                            });
3382
3383                            if (r.trim() !== '') {
3384                                listing.find('.items').html(r);
3385                                t.initItems(listing);
3386                                parseInt(listing.find('.items .item').length) === beforeCnt && _page !== 1 ? moreBtn.hide() : moreBtn.show();
3387                            }
3388                            listing.removeClass('loading');
3389                        },
3390                        error: function () {
3391                            listing.removeClass('loading');
3392                        }
3393                    });
3394                }
3395            }
3396        },
3397        playlist: {
3398            init: function () {
3399                var t = this,
3400                    _playlistNav = $('.playlist-navigation'),
3401                    _playlistItems = $('.playlist-items');
3402
3403                if (_playlistNav.length !== 0 && _playlistItems.length !== 0) {
3404                    t.initSlider(_playlistNav);
3405                    t.initStations(_playlistNav, _playlistItems);
3406                    t.initDays(_playlistNav, _playlistItems);
3407                    t.initItems(_playlistNav, _playlistItems);
3408                }
3409            },
3410            initSlider: function (_playlistNav) {
3411                var t = this,
3412                    container = _playlistNav.find('.container'),
3413                    ul = container.find('ul'),
3414                    li = container.find('li'),
3415                    prevBtn = _playlistNav.find('.prev'),
3416                    nextBtn = _playlistNav.find('.next'),
3417                    contW = container.width(),
3418                    liW = 0,
3419                    ulW = 0,
3420                    liPerCont = 0,
3421                    moveFactor = 0,
3422                    currentPos = 0,
3423                    currentL = 0;
3424
3425                li.each(function () {
3426                    liW = $(this).outerWidth(true);
3427                    ulW += liW;
3428
3429                    if ($(this).hasClass('active')) {
3430                        currentPos = $(this).index() + 1;
3431                    }
3432                });
3433
3434                liW = li.first().outerWidth(true);
3435
3436                liPerCont = Math.ceil(contW / liW);
3437                moveFactor = liPerCont * liW;
3438                if (currentPos > liPerCont / 2) {
3439                    currentL = (currentPos - Math.ceil(liPerCont / 2)) * liW;
3440                }
3441                ul.css('width', ulW);
3442                if (ulW <= contW) {
3443                    ul.css('left', (contW - ulW) / 2);
3444                } else {
3445                    ul.css('left', ulW - currentL >= contW ? -currentL : (contW - ulW > 0 ? 0 : contW - ulW));
3446                }
3447                t.toggleButtons(_playlistNav);
3448
3449                $(window).off('resize.epg').on('resize.epg', function () {
3450                    t.positionUL(_playlistNav);
3451                });
3452                prevBtn.off().on('click', function () {
3453                    var _container = _playlistNav.find('.container'),
3454                        _ul = _container.find('ul'),
3455                        _contW = _container.width(),
3456                        _ulW = _ul.width(),
3457                        _ulLeft = parseInt(_ul.css('left').replace('px', '')),
3458                        _liW = _ul.find('li').first().outerWidth(true),
3459                        _liPerCont = Math.ceil(_contW / _liW),
3460                        _moveFactor = _liPerCont * liW,
3461                        _newLeft = _ulLeft + _moveFactor <= 0 ? _ulLeft + _moveFactor : 0;
3462
3463                    if ($(this).hasClass('active')) {
3464                        ul.animate({'left': _newLeft}, 500, function () {
3465                            t.toggleButtons(_playlistNav);
3466                        });
3467                    }
3468                });
3469                nextBtn.off().on('click', function () {
3470                    var _container = _playlistNav.find('.container'),
3471                        _ul = _container.find('ul'),
3472                        _contW = _container.width(),
3473                        _ulW = _ul.width(),
3474                        _ulLeft = parseInt(_ul.css('left').replace('px', '')),
3475                        _liW = _ul.find('li').first().outerWidth(true),
3476                        _liPerCont = Math.ceil(_contW / _liW),
3477                        _moveFactor = _liPerCont * liW,
3478                        _newLeft = _ulLeft - _moveFactor >= _contW - _ulW ? _ulLeft - _moveFactor : _contW - _ulW;
3479
3480                    if ($(this).hasClass('active')) {
3481                        ul.animate({'left': _newLeft}, 500, function () {
3482                            t.toggleButtons(_playlistNav);
3483                        });
3484                    }
3485                });
3486            },
3487            positionUL: function (_playlistNav) {
3488                var t = this,
3489                    container = _playlistNav.find('.container'),
3490                    ul = container.find('ul'),
3491                    li = container.find('li'),
3492                    contW = container.width(),
3493                    liW = 0,
3494                    ulW = 0,
3495                    liPerCont = 0,
3496                    moveFactor = 0,
3497                    currentPos = 0,
3498                    currentL = 0;
3499
3500                li.each(function () {
3501                    liW = $(this).outerWidth(true);
3502                    ulW += liW;
3503
3504                    if ($(this).hasClass('active')) {
3505                        currentPos = $(this).index() + 1;
3506                    }
3507                });
3508
3509                liW = li.first().outerWidth(true);
3510
3511                liPerCont = Math.ceil(contW / liW);
3512                moveFactor = liPerCont * liW;
3513                if (currentPos > liPerCont / 2) {
3514                    currentL = (currentPos - Math.ceil(liPerCont / 2)) * liW;
3515                }
3516                ul.css('width', ulW);
3517                if (ulW <= contW) {
3518                    ul.css('left', (contW - ulW) / 2);
3519                } else {
3520                    ul.css('left', ulW - currentL >= contW ? -currentL : (contW - ulW > 0 ? 0 : contW - ulW));
3521                }
3522                t.toggleButtons(_playlistNav);
3523            },
3524            toggleButtons: function (_playlistNav) {
3525                var container = _playlistNav.find('.container'),
3526                    ul = container.find('ul'),
3527                    prevBtn = _playlistNav.find('.prev'),
3528                    nextBtn = _playlistNav.find('.next'),
3529                    contW = container.width(),
3530                    ulW = ul.width(),
3531                    ulLeft = ul.length !== 0 ? parseInt(ul.css('left').replace('px', '')) : 0;
3532
3533                if (ulW > contW && ulLeft < 0) {
3534                    prevBtn.addClass('active');
3535                } else {
3536                    prevBtn.removeClass('active');
3537                }
3538                if (ulW > contW && ulLeft > contW - ulW) {
3539                    nextBtn.addClass('active');
3540                } else {
3541                    nextBtn.removeClass('active');
3542                }
3543            },
3544            initStations: function (_playlistNav, _playlistItems) {
3545                var t = this,
3546                    _stations = _playlistNav.find('.playlist-stations li');
3547
3548                _stations.each(function () {
3549                    var _channel = $(this);
3550
3551                    _channel.off().on('click', function () {
3552                        _playlistNav.find('.playlist-stations li.active').removeClass('active');
3553                        _channel.addClass('active');
3554                        t.loadNavigation(_playlistNav, _playlistItems);
3555                    });
3556                });
3557            },
3558            initDays: function (_playlistNav, _playlistItems) {
3559                var t = this,
3560                    _days = _playlistNav.find('.playlist-days li');
3561
3562                _days.each(function () {
3563                    var _day = $(this);
3564
3565                    _day.off().on('click', function () {
3566                        _playlistNav.find('.playlist-days li.active').removeClass('active');
3567                        _day.addClass('active');
3568                        t.loadItems(_playlistNav, _playlistItems);
3569                    });
3570                });
3571            },
3572            initItems: function (_playlistNav, _playlistItems) {
3573                rk.modules.audioPlayer.init();
3574                $('.button-more').off().on('click', function () {
3575                    var i = 0;
3576                    _playlistItems.find('.hidden').each(function () {
3577                        //if (i<30) {
3578                        $(this).removeClass('hidden');
3579                        //	i++;
3580                        //}
3581                    });
3582                    if (_playlistItems.find('.hidden').length === 0) {
3583                        $(this).remove();
3584                    }
3585                });
3586            },
3587            loadNavigation: function (_playlistNav, _playlistItems) {
3588                var t = this,
3589                    _currentDate = _playlistNav.data('cd')
3590                _days = _playlistNav.find('.playlist-days');
3591                _stationId = _playlistNav.find('.playlist-stations li.active').attr('data-station-id');
3592
3593                if (!_playlistNav.hasClass('loading') && !_playlistItems.hasClass('loading')) {
3594                    $.ajax({
3595                        url: '/shared/listing.php',
3596                        data: {
3597                            parent_id: _stationId,
3598                            type: 'directory_standard',
3599                            copy: 'true',
3600                            direct: 'true',
3601                            order: 'title,1',
3602                            count: 1,
3603                            filter: '{"title":"' + _currentDate + '"}',
3604                            mode: 'days',
3605                            template: 'muzyka/playlist/current-day-find.html'
3606                        },
3607                        dataType: 'html',
3608                        beforeSend: function () {
3609                            _playlistItems.addClass('loading');
3610                            _playlistNav.addClass('loading');
3611                        },
3612                        success: function (r) {
3613                            _days.replaceWith(r);
3614                            _playlistItems.removeClass('loading');
3615                            _playlistNav.removeClass('loading');
3616
3617                            t.positionUL(_playlistNav);
3618                            t.initDays(_playlistNav, _playlistItems);
3619                            t.loadItems(_playlistNav, _playlistItems);
3620                        },
3621                        error: function () {
3622                            _playlistItems.removeClass('loading');
3623                            _playlistNav.removeClass('loading');
3624                        }
3625                    });
3626                }
3627            },
3628            loadItems: function (_playlistNav, _playlistItems) {
3629                var t = this,
3630                    _dayId = _playlistNav.find('.playlist-days li.active').attr('data-day-id');
3631
3632                if (!_playlistNav.hasClass('loading') && !_playlistItems.hasClass('loading')) {
3633                    $.ajax({
3634                        url: '/shared/listing.php',
3635                        data: {
3636                            parent_id: _dayId,
3637                            type: 'audio',
3638                            copy: 'true',
3639                            direct: 'true',
3640                            order: 'timeline_date,-1',
3641                            count: -1,
3642                            template: 'muzyka/playlist/items.html'
3643                        },
3644                        dataType: 'html',
3645                        beforeSend: function () {
3646                            _playlistItems.addClass('loading');
3647                            _playlistNav.addClass('loading');
3648                        },
3649                        success: function (r) {
3650                            _playlistItems.find('.items').html(r);
3651                            _playlistItems.removeClass('loading');
3652                            _playlistNav.removeClass('loading');
3653                            t.initItems(_playlistNav, _playlistItems);
3654                        },
3655                        error: function () {
3656                            _playlistItems.removeClass('loading');
3657                            _playlistNav.removeClass('loading');
3658                        }
3659                    });
3660                }
3661            }
3662        },
3663        wydawnictwoListing: {
3664            init: function () {
3665                var t = this,
3666                    _listing = $('.o-nas-wydawnictwo-listing');
3667
3668                if (_listing.length !== 0) {
3669                    _listing.each(function () {
3670                        var listing = $(this);
3671
3672                        t.initItems(listing);
3673                        t.initMoreBtn(listing);
3674                    });
3675                }
3676            },
3677            initItems: function (listing) {
3678                rk.modules.redir.init();
3679            },
3680            initMoreBtn: function (listing) {
3681                var t = this,
3682                    moreBtn = listing.find('.button-more');
3683
3684                moreBtn.each(function () {
3685                    var page = listing.find('input[name="page"]');
3686
3687                    $(this).off().on('click', function () {
3688                        if (!listing.hasClass('loading')) {
3689                            page.val(parseInt(page.val()) + 1);
3690                            t.load(listing);
3691                            return false;
3692                        }
3693                    });
3694                });
3695            },
3696            load: function (listing) {
3697                var t = this,
3698                    moreBtn = listing.find('.button-more'),
3699                    _parentId = listing.attr('data-parent-id'),
3700                    _type = listing.attr('data-type'),
3701                    _copy = listing.attr('data-copy'),
3702                    _direct = listing.attr('data-direct'),
3703                    _order = listing.attr('data-order'),
3704                    _count = parseInt(listing.attr('data-count')),
3705                    _categories = listing.attr('data-categories'),
3706                    _filter = JSON.parse(listing.attr('data-filter') !== '' ? decodeURIComponent(listing.attr('data-filter')) : '{}'),
3707                    _template = listing.attr('data-template'),
3708                    _page = parseInt(listing.find('input[name="page"]').val()),
3709                    beforeCnt = parseInt(listing.find('.items .item').length);
3710
3711                if (!listing.hasClass('loading')) {
3712                    $.ajax({
3713                        url: '/shared/listing.php',
3714                        data: {
3715                            parent_id: _parentId,
3716                            type: _type,
3717                            copy: _copy === true ? 'true' : 'false',
3718                            direct: _direct === true ? 'true' : 'false',
3719                            order: _order,
3720                            count: (_count - 1) * _page + 1,
3721                            categories: _categories,
3722                            filter: JSON.stringify(_filter),
3723                            template: _template
3724                        },
3725                        dataType: 'html',
3726                        beforeSend: function () {
3727                            listing.addClass('loading');
3728                            moreBtn.hide();
3729                        },
3730                        success: function (r) {
3731                            listing.find('.categories .active').removeClass('active');
3732                            listing.find('.categories .category[data-parent-id="' + _parentId + '"]').addClass('active');
3733                            listing.find('.items .item').each(function () {
3734                                $(this).remove();
3735                            });
3736
3737                            if (r.trim() !== '') {
3738                                listing.find('.items').html(r);
3739                                t.initItems(listing);
3740                                parseInt(listing.find('.items .item').length) === beforeCnt && _page !== 1 ? moreBtn.hide() : moreBtn.show();
3741                            }
3742                            listing.removeClass('loading');
3743                        },
3744                        error: function () {
3745                            listing.removeClass('loading');
3746                        }
3747                    });
3748                }
3749            }
3750        },
3751        searchResults: {
3752            init: function () {
3753                var t = this,
3754                    _sr = $('.search-results');
3755
3756                if (_sr.length > 0) {
3757                    t.initFilters(_sr);
3758                    t.initMoreButton(_sr);
3759                }
3760            },
3761            initFilters: function (_sr) {
3762                var t = this,
3763                    _page = _sr.find('input[name="page"]'),
3764                    _filters = _sr.find('.search-filter');
3765
3766                _filters.each(function () {
3767                    var _filter = $(this);
3768
3769                    _filter.off().on('mouseenter', function () {
3770                        _filter.addClass('hovered');
3771                    }).on('mouseleave', function () {
3772                        _filter.removeClass('hovered');
3773                    });
3774                    _filter.find('.current').off().on('click', function () {
3775                        _filter.toggleClass('expanded');
3776                    });
3777                    _filter.find('li').off().on('click', function () {
3778                        var _opt = $(this);
3779
3780                        _filter.find('li.selected').removeClass('selected');
3781                        _filter.removeClass('expanded');
3782                        _filter.find('.current span').html($(this).html());
3783                        _sr.attr('data-' + _filter.data('name'), _opt.data('value'));
3784                        _opt.addClass('selected');
3785                        _page.val(1);
3786                        t.load(_sr);
3787                    });
3788                });
3789                $('body').off('click.sr').on('click.sr', function () {
3790                    _filters.each(function () {
3791                        var _filter = $(this);
3792
3793                        if (!_filter.hasClass('hovered')) {
3794                            _filter.removeClass('expanded');
3795                        }
3796                    });
3797                });
3798            },
3799            initMoreButton: function (_sr) {
3800                var t = this,
3801                    _page = _sr.find('input[name="page"]'),
3802                    _btn = _sr.find('.button-more');
3803
3804                if (_btn.length !== 0) {
3805                    _btn.off().on('click', function () {
3806                        _page.val(parseInt(0 + _page.val()) + 1);
3807                        t.load(_sr);
3808                    });
3809                }
3810            },
3811            load: function (_sr) {
3812                var t = this,
3813                    _items = _sr.find('.items'),
3814                    _btn = _sr.find('.button-more'),
3815                    _page = _sr.find('input[name="page"]').val(),
3816                    _limit = parseInt(_sr.data('limit'));
3817
3818                $.ajax({
3819                    url: _sr.attr('data-url'),
3820                    data: {
3821                        query: _sr.find('input[name="query"]').val(),
3822                        sort_by: _sr.attr('data-sort-by'),
3823                        sort_order: _sr.attr('data-sort-order'),
3824                        offset: (_page - 1) * (_limit - 2) + 2,
3825                        limit: _limit - 2,
3826                        template: _sr.attr('data-template')
3827                    },
3828                    dataType: 'html',
3829                    beforeSend: function () {
3830                        _sr.addClass('loading');
3831                    },
3832                    success: function (r) {
3833                        _items.find('input[name="total_results"]').remove();
3834                        _page === 1 ? _items.html(r) : _items.append(r);
3835                        _sr.removeClass('loading');
3836                        parseInt(_items.find('input[name="total_results"]').val()) > _items.find('.item').length ? _btn.show() : _btn.hide();
3837                        //t.initListingEvents(_sr);
3838                    },
3839                    error: function (e) {
3840                        _sr.removeClass('loading');
3841                    }
3842                });
3843            }
3844        },
3845        listaPrzebojow: {
3846            init: function () {
3847                var t = this;
3848
3849                t.initMenu();
3850                t.initPoll();
3851                t.initArchiveNavigation();
3852            },
3853            initMenu: function () {
3854                var t = this,
3855                    _menu = $('.lista-przebojow-menu'),
3856                    _items = _menu.find('.item');
3857
3858                _items.each(function () {
3859                    var _item = $(this),
3860                        _parentId = _item.data('parent-id');
3861
3862                    _item.off().on('click', function () {
3863                        t.loadPoll(_parentId);
3864                        t.loadArchiveNavigation(_parentId);
3865                    });
3866                });
3867            },
3868            loadPoll: function (_parentId) {
3869                var t = this;
3870                _menu = $('.lista-przebojow-menu'),
3871                    _content = $('.content-container');
3872
3873                $.ajax({
3874                    url: '/shared/details.php',
3875                    data: {
3876                        object_id: _parentId,
3877                        template: 'muzyka/lista-przebojow/poll-info.html'
3878                    },
3879                    dataType: 'html',
3880                    beforeSend: function () {
3881                        _content.addClass('loading');
3882                    },
3883                    success: function (r) {
3884                        _menu.find('.item.active').removeClass('active');
3885                        _menu.find('.item[data-parent-id="' + _parentId + '"]').addClass('active');
3886                        _content.html(r);
3887                        _content.removeClass('loading');
3888
3889                        t.initPoll();
3890                        rk.modules.audioPlayer.init();
3891                    },
3892                    error: function () {
3893                        _content.removeClass('loading');
3894                    }
3895                });
3896            },
3897            loadArchiveNavigation: function (_parentId) {
3898                var t = this;
3899                _nav = $('.lp-archive-navigation');
3900
3901                $.ajax({
3902                    url: '/shared/listing.php',
3903                    data: {
3904                        parent_id: _parentId,
3905                        type: 'directory_standard',
3906                        copy: 'false',
3907                        direct: 'true',
3908                        order: 'position,1',
3909                        count: 1,
3910                        filter: '{"object_title":"Archiwum notowań"}',
3911                        template: 'muzyka/lista-przebojow/find-archive.html'
3912                    },
3913                    dataType: 'html',
3914                    beforeSend: function () {
3915                        _nav.addClass('loading');
3916                    },
3917                    success: function (r) {
3918                        _nav.find('.items').html(r);
3919                        _nav.removeClass('loading');
3920
3921                        t.initArchiveNavigation();
3922                    },
3923                    error: function () {
3924                        _nav.removeClass('loading');
3925                    }
3926                });
3927            },
3928            initPoll: function () {
3929                var t = this;
3930
3931                $('.lp-poll.poll-active').each(function () {
3932                    var _poll = $(this),
3933                        _dir = _poll.parent(),
3934                        _answers = _poll.find('.lp-poll-answer'),
3935                        _startMessage = _dir.find('.start-message'),
3936                        _errMessage = _dir.find('.unknown-error-message'),
3937                        _vclMessage = _dir.find('.voting-closed-message'),
3938                        _vnaMessage = _dir.find('.voting-not-allowed'),
3939                        _tmaMessage = _dir.find('.too-many-answers'),
3940                        _thanksMessage = _dir.find('.thanks-message');
3941
3942                    _startMessage.find('.btn-close-overlay').off().on('click', function () {
3943                        _startMessage.fadeOut(500);
3944                    });
3945                    _errMessage.find('.btn-close-overlay').off().on('click', function () {
3946                        _errMessage.fadeOut(500);
3947                    });
3948                    _vclMessage.find('.btn-close-overlay').off().on('click', function () {
3949                        _vclMessage.fadeOut(500);
3950                    });
3951                    _vnaMessage.find('.btn-close-overlay').off().on('click', function () {
3952                        _vnaMessage.fadeOut(500);
3953                    });
3954                    _tmaMessage.find('.btn-close-overlay').off().on('click', function () {
3955                        _tmaMessage.fadeOut(500);
3956                    });
3957                    _thanksMessage.find('.btn-close-overlay').off().on('click', function () {
3958                        _thanksMessage.fadeOut(500);
3959                    });
3960                    _answers.each(function () {
3961                        var _answer = $(this),
3962                            _voteBtn = _answer.find('.answer-btn i'),
3963                            _voteCB = _answer.find('.answer-cb i');
3964
3965                        _voteBtn.off().on('click', function () {
3966                            t.startPoll(_poll, _answer);
3967                        });
3968                        _voteCB.off().on('click', function () {
3969                            var _cb = $(this);
3970
3971                            _cb.toggleClass('checked');
3972
3973                            if (_poll.find('.answer-cb i.checked').length > parseInt(_poll.data('answer-per-query'))) {
3974                                t.showPollMessage(_poll, 20);
3975                                _cb.toggleClass('checked');
3976                            }
3977                        });
3978                    });
3979                });
3980            },
3981            initArchiveNavigation: function () {
3982                var t = this;
3983                _nav = $('.lp-archive-navigation'),
3984                    _years = _nav.find('.year'),
3985                    _months = _nav.find('.month');
3986
3987                _years.each(function () {
3988                    var _year = $(this),
3989                        _parentId = _year.data('parent-id'),
3990                        _btn = _year.find('.year-name'),
3991                        _monthsC = _year.find('.months');
3992
3993                    _btn.off().on('click', function () {
3994                        var _expanded = _nav.find('.year.expanded');
3995
3996                        if (_year.hasClass('expanded')) {
3997                            _monthsC.slideUp(200, function () {
3998                                _year.removeClass('expanded');
3999                            });
4000                        } else {
4001                            if (_year !== _expanded) {
4002                                _expanded.slideUp(200, function () {
4003                                    _expanded.removeClass('expanded');
4004                                });
4005                            }
4006                            _monthsC.slideDown(200, function () {
4007                                _year.addClass('expanded');
4008                            });
4009                        }
4010                    });
4011                });
4012                _months.each(function () {
4013                    var _month = $(this),
4014                        _parentId = _month.data('parent-id'),
4015                        _direct = _month.data('direct');
4016
4017                    _month.off().on('click', function () {
4018                        t.loadArchiveItems(_parentId, _direct);
4019                    });
4020                });
4021            },
4022            loadArchiveItems: function (_parentId, _direct) {
4023                var t = this;
4024                _nav = $('.lp-archive-navigation'),
4025                    _title = _nav.find('input[name="list-name"]').val(),
4026                    _content = $('.content-container');
4027
4028                $.ajax({
4029                    url: '/shared/listing.php',
4030                    data: {
4031                        parent_id: _parentId,
4032                        type: 'poll',
4033                        copy: 'true',
4034                        direct: _direct,
4035                        order: 'release_date,-1',
4036                        count: 10,
4037                        filter: '{}',
4038                        initial: 'true',
4039                        t: encodeURIComponent(_title),
4040                        template: 'muzyka/lista-przebojow/archive-listing.html'
4041                    },
4042                    dataType: 'html',
4043                    beforeSend: function () {
4044                        _content.addClass('loading');
4045                    },
4046                    success: function (r) {
4047                        _content.html(r);
4048                        _content.removeClass('loading');
4049                        rk.modules.listaPrzebojowArchiveListing.init(
4049);
4050                    },
4051                    error: function () {
4052                        _content.removeClass('loading');
4053                    }
4054                });
4055            },
4056            startPoll: function (_poll, _answer) {
4057                var t = this,
4058                    _voteBtn = $('<div class="button-vote">Głosuj</div>');
4059
4060                $.ajax({
4061                    url: '/sess/hit-list-vote.php',
4062                    data: {
4063                        pId: _poll.data('id'),
4064                        action: 'start',
4065                        dump: 'json'
4066                    },
4067                    dataType: 'json',
4068                    beforeSend: function () {
4069                        _poll.addClass('loading');
4070                    },
4071                    success: function (r) {
4072                        if (r.code === 1) {
4073                            _poll.find('.answer-btn').hide();
4074                            _poll.find('.answer-cb').css('display', 'table-cell');
4075                            _poll.append(_voteBtn);
4076                            _voteBtn.off().on('click', function () {
4077                                t.vote(_poll);
4078                            });
4079                            _answer.find('.answer-cb i').addClass('checked');
4080                        } else if ([10, 11, 12].includes(r.code)) {
4081                            _poll.find('.answer-btn i').hide();
4082                            _poll.find('.answer-cb').remove();
4083                        }
4084                        t.showPollMessage(_poll, r.code);
4085                        _poll.removeClass('loading');
4086                    },
4087                    error: function () {
4088                        _poll.removeClass('loading');
4089                    }
4090                });
4091            },
4092            vote: function (_poll) {
4093                var t = this,
4094                    _checkedAnswers = [];
4095
4096                _poll.find('.lp-poll-answer').each(function () {
4097                    var _answer = $(this),
4098                        _answerId = _answer.data('id'),
4099                        _cb = _answer.find('.answer-cb i');
4100
4101                    if (_cb.hasClass('checked')) {
4102                        _checkedAnswers.push(_answerId);
4103                    }
4104                });
4105
4106                if (_checkedAnswers.length === 0) {
4107                    return;
4108                }
4109
4110                if (_checkedAnswers.length > parseInt(_poll.data('answer-per-query'))) {
4111                    t.showPollMessage(_poll, 20);
4112                } else {
4113                    $.ajax({
4114                        url: '/sess/hit-list-vote.php?pId=' + _poll.data('id') + '&action=save&dump=json',
4115                        data: {
4116                            qId: _poll.find('.lp-poll-query').data('id'),
4117                            answers: JSON.stringify(_checkedAnswers)
4118                        },
4119                        method: 'post',
4120                        dataType: 'json',
4121                        beforeSend: function () {
4122                            _poll.addClass('loading');
4123                        },
4124                        success: function (r) {
4125                            if (r.code === 1) {
4126                                t.finishPoll(_poll);
4127                            } else if ([10, 11, 12].includes(r.code)) {
4128                                t.showPollMessage(_poll, r.code);
4129                                _poll.find('.answer-btn i').hide();
4130                                _poll.find('.answer-cb').remove();
4131                                _poll.removeClass('loading');
4132                            }
4133                        },
4134                        error: function () {
4135                            _poll.removeClass('loading');
4136                        }
4137                    });
4138                }
4139            },
4140            finishPoll: function (_poll) {
4141                var t = this;
4142
4143                $.ajax({
4144                    url: '/sess/hit-list-vote.php?pId=' + _poll.data('id') + '&action=finish&dump=json',
4145                    data: {},
4146                    method: 'post',
4147                    dataType: 'json',
4148                    beforeSend: function () {
4149                        _poll.removeClass('loading');
4150                    },
4151                    success: function (r) {
4152                        t.showPollMessage(_poll, r.code);
4153                        _poll.find('.answer-cb i').remove();
4154                        _poll.find('.button-vote').remove();
4155                        _poll.removeClass('loading');
4156                    },
4157                    error: function () {
4158                        _poll.removeClass('loading');
4159                    }
4160                });
4161            },
4162            showPollMessage: function(_poll, code) {
4163                var _dir = _poll.parent(),
4164                    _startMessage = _dir.find('.start-message'),
4165                    _thanksMessage = _dir.find('.thanks-message'),
4166                    _errMessage = _dir.find('.unknown-error-message'),
4167                    _vclMessage = _dir.find('.voting-closed-message'),
4168                    _vnaMessage = _dir.find('.voting-not-allowed'),
4169                    _tmaMessage = _dir.find('.too-many-answers');
4170
4171                    switch (code) {
4172                        case 1:
4173                            _startMessage.css('display', 'flex').hide().fadeIn(150);
4174                            break;
4175                        case 5:
4176                            _thanksMessage.css('display', 'flex').hide().fadeIn(150);
4177                            break;
4178                        case 10:
4179                            _errMessage.css('display', 'flex').hide().fadeIn(150);
4180                            break;
4181                        case 11:
4182                            _vclMessage.css('display', 'flex').hide().fadeIn(150);
4183                            break;
4184                        case 12:
4185                            _vnaMessage.css('display', 'flex').hide().fadeIn(150);
4186                            break;
4187                        case 20:
4188                            _tmaMessage.css('display', 'flex').hide().fadeIn(150);
4189                            break;
4190                    }
4191
4192                $('html,body').animate({'scrollTop': ($('.poll-dir').offset().top - 75) + 'px'}, 500);
4193
4194            }
4195        },
4196        listaPrzebojowArchiveListing: {
4197            init: function () {
4198                var t = this,
4199                    _listing = $('.listing');
4200
4201                _listing.each(function () {
4202                    var listing = $(this),
4203                        moreBtn = listing.find('.button-more');
4204
4205                    moreBtn.each(function () {
4206                        var page = listing.find('input[name="page"]');
4207
4208                        $(this).off().on('click', function () {
4209                            if (!listing.hasClass('loading')) {
4210                                page.val(parseInt(page.val()) + 1);
4211                                t.load(listing);
4212                                return false;
4213                            }
4214                        });
4215                    });
4216                    t.initListingEvents(listing);
4217                });
4218            },
4219            initListingEvents: function (listing) {
4220                rk.modules.audioPlayer.init();
4221            },
4222            load: function (listing) {
4223                var t = this,
4224                    moreBtn = listing.find('.button-more'),
4225                    _parentId = listing.attr('data-parent-id'),
4226                    _type = listing.attr('data-type'),
4227                    _copy = listing.attr('data-copy'),
4228                    _direct = listing.attr('data-direct'),
4229                    _order = listing.attr('data-order'),
4230                    _count = parseInt(listing.attr('data-count')),
4231                    _filter = JSON.parse(listing.attr('data-filter') !== '' ? decodeURIComponent(listing.attr('data-filter')) : '{}'),
4232                    _template = listing.attr('data-template'),
4233                    _page = parseInt(listing.find('input[name="page"]').val()),
4234                    beforeCnt = parseInt(listing.find('.items .item').length);
4235
4236                if (!listing.hasClass('loading')) {
4237                    $.ajax({
4238                        url: '/shared/listing.php',
4239                        data: {
4240                            parent_id: _parentId,
4241                            type: _type,
4242                            copy: _copy === true ? 'true' : 'false',
4243                            direct: _direct === true ? 'true' : 'false',
4244                            order: _order,
4245                            count: listing.hasClass('listing-2-4') ? (_count + 2) * (_page - 1) + _count : _count * _page,
4246                            filter: JSON.stringify(_filter),
4247                            template: _template
4248                        },
4249                        dataType: 'html',
4250                        beforeSend: function () {
4251                            listing.addClass('loading');
4252                            moreBtn.hide();
4253                        },
4254                        success: function (r) {
4255                            listing.find('.items .item').each(function () {
4256                                $(this).remove();
4257                            });
4258
4259                            if (r.trim() !== '') {
4260                                listing.find('.items').html(r);
4261                                t.initListingEvents(listing);
4262                                parseInt(listing.find('.items .item').length) === beforeCnt && _page !== 1 ? moreBtn.hide() : moreBtn.show();
4263                            }
4264                            listing.removeClass('loading');
4265                        },
4266                        error: function () {
4267                            listing.removeClass('loading');
4268                        }
4269                    });
4270                }
4271            }
4272        },
4273        articlePoll: {
4274            init: function () {
4275                var t = this,
4276                    polls = $('.lp-poll.poll-active');
4277
4278                if (polls.length !== 0) {
4279                    t.initPoll();
4280                }
4281            },
4282            initPoll: function () {
4283                var t = this;
4284
4285                $('.lp-poll.poll-active').each(function () {
4286                    var _poll = $(this),
4287                        _dir = _poll.parent(),
4288                        _answers = _poll.find('.lp-poll-answer'),
4289                        _startMessage = _dir.find('.start-message'),
4290                        _vnaMessage = _dir.find('.voting-not-allowed'),
4291                        _tmaMessage = _dir.find('.too-many-answers'),
4292                        _thanksMessage = _dir.find('.thanks-message');
4293
4294                    _startMessage.find('.btn-close-overlay').off().on('click', function () {
4295                        _startMessage.fadeOut(500, function () {
4296                        });
4297                    });
4298                    _vnaMessage.find('.btn-close-overlay').off().on('click', function () {
4299                        _vnaMessage.fadeOut(500, function () {
4300                        });
4301                    });
4302                    _tmaMessage.find('.btn-close-overlay').off().on('click', function () {
4303                        _tmaMessage.fadeOut(500, function () {
4304                        });
4305                    });
4306                    _thanksMessage.find('.btn-close-overlay').off().on('click', function () {
4307                        _thanksMessage.fadeOut(500, function () {
4308                        });
4309                    });
4310                    _answers.each(function () {
4311                        var _answer = $(this),
4312                            _answerId = _answer.data('id'),
4313                            _voteBtn = _answer.find('.answer-btn i'),
4314                            _voteCB = _answer.find('.answer-cb i');
4315
4316                        _voteBtn.off().on('click', function () {
4317                            t.startPoll(_poll, _answer);
4318                        });
4319                        _voteCB.off().on('click', function () {
4320                            var _cb = $(this);
4321
4322                            _cb.toggleClass('checked');
4323
4324                            if (_poll.find('.answer-cb i.checked').length > parseInt(_poll.data('answer-per-query'))) {
4325                                _tmaMessage.fadeIn(150, function () {
4326                                    _cb.removeClass('checked');
4327                                });
4328                                $('html,body').animate({'scrollTop': ($('.poll-dir').offset().top - 75) + 'px'}, 500, function () {
4329                                });
4330                            }
4331                        });
4332                    });
4333                });
4334            },
4335            startPoll: function (_poll, _answer) {
4336                var t = this,
4337                    _dir = _poll.parent();
4338                _startMessage = _dir.find('.start-message'),
4339                    _vnaMessage = _dir.find('.voting-not-allowed'),
4340                    _voteBtn = $('<div class="button-vote">Głosuj</div>');
4341
4342                $.ajax({
4343                    url: '/sess/quiz/quizOpen.php',
4344                    data: {
4345                        poll_id: _poll.data('id'),
4346                        action: 'start_quiz',
4347                        dump: 'json'
4348                    },
4349                    dataType: 'json',
4350                    beforeSend: function () {
4351                        _poll.addClass('loading');
4352                    },
4353                    success: function (r) {
4354                        var responseCode = r.message.msg;
4355
4356                        if (responseCode === 8) {
4357                            if (parseInt(_poll.data('answer-per-query')) > 1) {
4358                                _startMessage.show();
4359                            }
4360                            $('html,body').animate({'scrollTop': ($('.poll-dir').offset().top - 75) + 'px'}, 500, function () {
4361                            });
4362                            _poll.find('.answer-btn').hide();
4363                            _poll.find('.answer-cb').css('display', 'table-cell');
4364                            _poll.append(_voteBtn);
4365                            _voteBtn.off().on('click', function () {
4366                                t.vote(_poll);
4367                            });
4368                            _answer.find('.answer-cb i').addClass('checked');
4369                        } else if (responseCode === 9) {
4370                            _poll.find('.answer-btn i').hide();
4371                            _poll.find('.answer-cb').remove();
4372                            _vnaMessage.show();
4373                            $('html,body').animate({'scrollTop': ($('.poll-dir').offset().top - 75) + 'px'}, 500, function () {
4374                            });
4375                        }
4376                        _poll.removeClass('loading');
4377                    },
4378                    error: function () {
4379                        _poll.removeClass('loading');
4380                    }
4381                });
4382            },
4383            vote: function (_poll) {
4384                var t = this,
4385                    _dir = _poll.parent(),
4386                    _tmaMessage = _dir.find('.too-many-answers'),
4387                    _checkedAnswers = new Array();
4388
4389                _poll.find('.lp-poll-answer').each(function () {
4390                    var _answer = $(this),
4391                        _answerId = _answer.data('id'),
4392                        _cb = _answer.find('.answer-cb i');
4393
4394                    if (_cb.hasClass('checked')) {
4395                        _checkedAnswers.push(_answerId);
4396                    }
4397                });
4398
4399                if (_poll.find('.answer-cb i.checked').length > parseInt(_poll.data('answer-per-query'))) {
4400                    _tmaMessage.fadeIn(150, function () {
4401                    });
4402                    $('html,body').animate({'scrollTop': ($('.poll-dir').offset().top - 75) + 'px'}, 500, function () {
4403                    });
4404                } else {
4405                    $.ajax({
4406                        url: '/sess/quiz/quizOpen.php?poll_id=' + _poll.data('id') + '&action=save&dump=json',
4407                        data: {
4408                            query_id: _poll.find('.lp-poll-query').data('id'),
4409                            multi_answers: _checkedAnswers
4410                        },
4411                        method: 'post',
4412                        dataType: 'json',
4413                        beforeSend: function () {
4414                            _poll.addClass('loading');
4415                        },
4416                        success: function (r) {
4417                            var responseCode = r.message._id;
4418
4419                            if (responseCode === -1 || responseCode === 6) {
4420                                t.finishPoll(_poll);
4421                            } else {
4422                                _poll.removeClass('loading');
4423                            }
4424                        },
4425                        error: function () {
4426                            _poll.removeClass('loading');
4427                        }
4428                    });
4429                }
4430            },
4431            finishPoll: function (_poll) {
4432                var t = this,
4433                    _dir = _poll.parent(),
4434                    _thanksMessage = _dir.find('.thanks-message');
4435
4436                $.ajax({
4437                    url: '/sess/quiz/quizOpen.php?poll_id=' + _poll.data('id') + '&action=end_quiz&dump=json',
4438                    data: {},
4439                    method: 'post',
4440                    dataType: 'json',
4441                    beforeSend: function () {
4442                        _poll.removeClass('loading');
4443                    },
4444                    success: function (r) {
4445                        _thanksMessage.show();
4446                        $('html,body').animate({'scrollTop': ($('.poll-dir').offset().top - 75) + 'px'}, 500, function () {
4447                        });
4448                        _poll.find('.answer-cb i').remove();
4449                        _poll.find('.button-vote').remove();
4450                        _poll.removeClass('loading');
4451                    },
4452                    error: function () {
4453                        _poll.removeClass('loading');
4454                    }
4455                });
4456            }
4457        },
4458        weather: {
4459            init: function () {
4460                var t = this,
4461                    container = $('.weather');
4462
4463                if (container.length !== 0) {
4464                    t.initDots(container);
4465                    t.initNavigation(container);
4466                }
4467            },
4468            initDots: function (container) {
4469                var t = this;
4470
4471                container.find('.map .icon').each(function () {
4472                    var icon = $(this),
4473                        map = container.find('.map'),
4474                        cityId = icon.data('id');
4475
4476                    icon.find('.inner').off().on('mouseenter click', function (e) {
4477                        var city = container.find('.city[data-id="' + cityId + '"]'),
4478                            tooltip = $('<div class="tooltip"><div class="inner"><div class="row"><div class="temp"></div><div class="icon"></div></div><div class="name"></div><div class="arrow"></div></div></div>');
4479
4480                        if (e.target.className !== 'name above' && e.target.className !== 'name below') {
4481                            container.find('.tooltip').remove();
4482                            tooltip.find('.temp').html(city.find('.today .temp').html());
4483                            tooltip.find('.icon').html(city.find('.today .icon').html().replace('-s', ''));
4484                            tooltip.find('.name').html(city.find('.name').html());
4485                            map.append(tooltip);
4486                            tooltip.css('top', parseInt(icon.css('top').replace('px', '')) + 25);
4487                            tooltip.css('left', parseInt(icon.css('left').replace('px', '')) - tooltip.outerWidth() / 2 + 7);
4488
4489                            tooltip.off().on('mouseenter', function () {
4490                                $(this).addClass('hovered');
4491                            }).on('mouseleave', function () {
4492                                $(this).removeClass('hovered').remove();
4493                            });
4494                        }
4495                    }).on('mouseleave', function (e) {
4496                        if (e.target.className !== 'name above' && e.target.className !== 'name below') {
4497                            container.find('.tooltip').remove();
4498                        }
4499                    });
4500                });
4501            },
4502            initNavigation: function (container) {
4503                var t = this,
4504                    nav = container.find('.weather-navigation li');
4505
4506                nav.each(function () {
4507                    var btn = $(this),
4508                        type = btn.data('type');
4509
4510                    btn.off().on('click', function () {
4511                        container.find('.weather-navigation .active').removeClass('active');
4512                        container.find('.main-cities .today').hide();
4513                        container.find('.main-cities .period-0').hide();
4514                        container.find('.main-cities .period-1').hide();
4515                        container.find('.main-cities .period-2').hide();
4516                        container.find('.main-cities .period-3').hide();
4517                        container.find('.main-cities .period-4').hide();
4518                        container.find('.main-cities .' + type).show();
4519                        container.find('.small-cities .today').hide();
4520                        container.find('.small-cities .period-0').hide();
4521                        container.find('.small-cities .period-1').hide();
4522                        container.find('.small-cities .period-2').hide();
4523                        container.find('.small-cities .period-3').hide();
4524                        container.find('.small-cities .period-4').hide();
4525                        container.find('.small-cities .' + type).css('display', 'table');
4526                        container.find('.regions .today').hide();
4527                        container.find('.regions .period-0').hide();
4528                        container.find('.regions .period-1').hide();
4529                        container.find('.regions .period-2').hide();
4530                        container.find('.regions .period-3').hide();
4531                        container.find('.regions .period-4').hide();
4532                        container.find('.regions .' + type).show();
4533                        container.find('.baltic .today').hide();
4534                        container.find('.baltic .period-0').hide();
4535                        container.find('.baltic .period-1').hide();
4536                        container.find('.baltic .period-2').hide();
4537                        container.find('.baltic .period-3').hide();
4538                        container.find('.baltic .period-4').hide();
4539                        container.find('.baltic .' + type).show();
4540                        btn.addClass('active');
4541                    });
4542                });
4543            }
4544        },
4545        reportNews: {
4546            init: function () {
4547                var contactForms = $('.report-news form'),
4548                    that = this;
4549
4550                contactForms.each(function () {
4551                    var $form = $(this),
4552                        dev = parseInt($form.attr('data-d')) === 1,
4553                        id_object = $form.attr('data-id'),
4554                        $successMessage = $('.success-message'),
4555                        $errorMessage = $('.error-message');
4556
4557                    $errorMessage.find('span').off().on('click', function () {
4558                        $errorMessage.hide();
4559                        $form.show();
4560                    });
4561
4562                    $form.on('submit', function (event) {
4563                        event.preventDefault();
4564
4565                        if (event.currentTarget.checkValidity()) {
4566                            var $form = $(event.currentTarget),
4567                                token = $form.attr('data-token'),
4568                                dataForm = {},
4569                                data_are_prepare = true,
4570                                $messageTextarea = $form.find('textarea.message');
4571                            console.log($messageTextarea)
4572                            if ($messageTextarea.length) {
4573                                if ($messageTextarea.val().length < parseInt($messageTextarea.attr('minlength')) || $messageTextarea.val().length > parseInt($messageTextarea.attr('maxlength'))) {
4574                                    $messageTextarea[0].setCustomValidity($messageTextarea.attr('title'));
4575                                } else {
4576                                    $messageTextarea[0].setCustomValidity('');
4577                                }
4578                            }
4579                            $form.find('input, textarea, select').each(function (index, element) {
4580                                var $element = $(element),
4581                                    path = $element.attr('name'),
4582                                    data_are_prepare = true;
4583
4584                                if ($element.attr('type') === 'checkbox') {
4585                                    try {
4586                                        dataForm = that.assignValueToSubObjectByPath(dataForm, path, $element.is(':checked') ? 1 : 0);
4587                                    } catch (error) {
4588                                        data_are_prepare = false;
4589                                    }
4590                                } else {
4591                                    if ($element.val() !== '') {
4592                                        try {
4593                                            dataForm = that.assignValueToSubObjectByPath(dataForm, path, $element.val());
4594                                        } catch (error) {
4595                                            data_are_prepare = false;
4596                                        }
4597                                    }
4598                                }
4599                            });
4600
4601                            if (data_are_prepare) {
4602                                $.ajax({
4603                                    type: 'POST',
4604                                    url: '/sess/forms/processing' + (dev ? '.dev' : '') + '.php',
4605                                    headers: {
4606                                        Authorization: 'Bearer ' + token
4607                                    },
4608                                    data: {
4609                                        id_object: id_object,
4610                                        dataFormJSON: JSON.stringify(dataForm)
4611                                    },
4612                                    dataType: 'json',
4613                                    beforeSend: function () {
4614                                        $form.addClass('loading');
4615                                    },
4616                                    success: function (response) {
4617                                        $form.removeClass('loading').hide();
4618
4619                                        if ($.isPlainObject(response) && !response.error) {
4620                                            $form[0].reset();
4621                                            $successMessage.show();
4622                                        } else {
4623                                            $form.attr('data-token', response.token_new);
4624                                            $errorMessage.show();
4625                                        }
4626                                    },
4627                                    error: function (error) {
4628                                        $form.attr('data-token', error.token_new);
4629                                        $form.removeClass('loading').hide();
4630                                        $errorMessage.show();
4631                                    }
4632                                });
4633                            } else {
4634                                $errorMessage.show();
4635                            }
4636                        }
4637                    });
4638                });
4639            },
4640            createSubObjectsFromPath: function (dataSource, path) {
4641                if (typeof path === 'string' && path.length > 0) {
4642                    var sub_path = '',
4643                        pathSequences = path.match(/([^\"]+)(?=\"\])|([^\']+)(?=\'\])|(\[\d+\])|[^\[\]\.\'\"]+(?=^|\.|\[)|[^\[\]\'\"\.]+/g);
4644
4645                    if (!$.isPlainObject(dataSource) && !$.isArray(dataSource)) {
4646                        if (pathSequences[0].match(/\d+(?=\])/g) === null) {
4647                            dataSource = {};
4648                        } else {
4649                            dataSource = [];
4650                        }
4651                    }
4652                    $.each(pathSequences, function (index_object, name_object) {
4653                        if (name_object.match(/\d+(?=\])/g) === null) {
4654                            var create_object = true;
4655
4656                            if (name_object.match(/\'/g) === null) {
4657                                sub_path += '[\'' + name_object + '\']';
4658                            } else {
4659                                sub_path += '[\"' + name_object + '\"]';
4660                            }
4661                            if (index_object + 1 !== pathSequences.length && pathSequences[index_object + 1].match(/\d+(?=\])/g) !== null) {
4662                                create_object = false;
4663                            }
4664
4665                            var create_sub_data = true;
4666
4667                            try {
4668                                create_sub_data = new Function('data', 'return data' + sub_path + ';')(dataSource) === undefined;
4669                            } catch (error) {
4670                                throw {
4671                                    'sub_path': sub_path,
4672                                    'body_function': 'return data' + sub_path + ';',
4673                                    'data': dataSource,
4674                                    'error': error,
4675                                    'resone': 'new Function error'
4676                                };
4677                            }
4678                            if (create_sub_data) {
4679                                try {
4680                                    dataSource = new Function('data', 'data' + sub_path + ' = ' + (create_object ? '{}' : '[]') + '; return data;')(dataSource);
4681                                } catch (error) {
4682                                    throw {
4683                                        'sub_path': sub_path,
4684                                        'body_function': 'data' + sub_path + ' = {}; return data;',
4685                                        'data': dataSource,
4686                                        'error': error,
4687                                        'resone': 'new Function error'
4688                                    };
4689                                }
4690                            }
4691                        } else {
4692                            var create_object = true;
4693
4694                            sub_path += '[\'' + name_object.match(/\d+/g)[0] + '\']';
4695                            if (index_object + 1 !== pathSequences.length && pathSequences[index_object + 1].match(/\d+(?=\])/g) !== null) {
4696                                create_object = false;
4697                            }
4698
4699                            var create_sub_data = true;
4700
4701                            try {
4702                                create_sub_data = new Function('data', 'return data' + sub_path + ';')(dataSource) === undefined;
4703                            } catch (error) {
4704                                throw {
4705                                    'sub_path': sub_path,
4706                                    'body_function': 'return data' + sub_path + ';',
4707                                    'data': dataSource,
4708                                    'error': error,
4709                                    'resone': 'new Function error'
4710                                };
4711                            }
4712                            if (create_sub_data) {
4713                                try {
4714                                    dataSource = new Function('data', 'data' + sub_path + ' = ' + (create_object ? '{}' : '[]') + '; return data;')(dataSource)
4715                                } catch (error) {
4716                                    throw {
4717                                        'sub_path': sub_path,
4718                                        'body_function': 'data' + sub_path + ' = []; return data;',
4719                                        'data': dataSource,
4720                                        'error': error,
4721                                        'resone': 'new Function error'
4722                                    }
4723                                }
4724                            }
4725                        }
4726                    });
4727                }
4728
4729                return {
4730                    path: sub_path,
4731                    data: dataSource
4732                }
4733            },
4734            assignValueToSubObjectByPath: function (data, path, value) {
4735                var response;
4736
4737                try {
4738                    response = this.createSubObjectsFromPath(data, path);
4739                } catch (error) {
4740                    console.log(error);
4741
4742                    return false;
4743                }
4744                data = response.data;
4745                path = response.path;
4746                try {
4747                    new Function('data', 'value', 'data' + path + ' = value;')(data, value);
4748
4749                    return data;
4750                } catch (error) {
4751                    throw error;
4752                }
4753            }
4754        },
4755        liveblogTimeline: {
4756            to: [],
4757            init: function () {
4758                var t = this;
4759                $('.liveblog-timeline').each(function () {
4760                    var lb = $(this),
4761                        lbID = lb.data('liveblog-id'),
4762                        lbLoadMoreBtn = lb.find('.liveblog-load-more-button');
4763
4764                    lbLoadMoreBtn.off().on('click', function () {
4765                        if (!lb.hasClass('loading')) {
4766                            t.loadOlderEntries(lb);
4767                        }
4768                    });
4769                    t.setRefreshTimeuot(lb);
4770                });
4771            },
4772            setRefreshTimeuot: function (lb) {
4773                var t = this,
4774                    lbID = lb.data('liveblog-id'),
4775                    lbRefreshInterval = parseInt(lb.data('refresh-interval'));
4776
4777                if (lbRefreshInterval > 0) {
4778                    t.to[lbID] = setTimeout(function () {
4779                        t.loadNewEntries(lb);
4780                    }, lbRefreshInterval * 1000);
4781                }
4782            },
4783            initLiveblogEvents: function () {
4784                rk.modules.gallery.init();
4785                rk.modules.embeddedVideoLink.init();
4786                rk.modules.audioPlayer.init();
4787
4788                // if (FB) {
4789                //     FB.XFBML.parse();
4790                // }
4791            },
4792            loadNewEntries: function (lb) {
4793                var t = this,
4794                    lbID = lb.data('liveblog-id'),
4795                    lbRefreshInterval = parseInt(lb.data('refresh-interval')),
4796                    lbVersionContainer = lb.find('.liveblog-version'),
4797                    lbVersion = parseInt(lb.find('.liveblog-version').html()),
4798                    lbFirstItem = lb.find('.liveblog-item').first();
4799
4800                if (!lb.hasClass('loading')) {
4801                    $.ajax({
4802                        url: '/sess/getversion.php',
4803                        data: {
4804                            id: lbID
4805                        },
4806                        beforeSend: function () {
4807                            lb.addClass('loading');
4808                            clearTimeout(t.to[lbID]);
4809                        },
4810                        success: function (v) {
4811                            if (parseInt(v) !== lbVersion) {
4812                                $.ajax({
4813                                    url: '/shared/listing.php',
4814                                    data: {
4815                                        parent_id: lbID,
4816                                        type: 'news_refresh',
4817                                        direct: 'true',
4818                                        order: 'position,1',
4819                                        filter: '{"object_position":{"$lt":' + lbFirstItem.data('item-ts') + '}}',
4820                                        mode: 'new',
4821                                        nocount: 1,
4822                                        template: 'liveblog/timeline.html'
4823                                    },
4824                                    success: function (r) {
4825                                        lbFirstItem.before(r);
4826                                        lbVersionContainer.html(lb.find('.liveblog-ne
4826w-version').html());
4827                                        lb.find('.liveblog-new-version').remove();
4828                                        t.setRefreshTimeuot(lb);
4829                                        t.initLiveblogEvents();
4830                                        lb.removeClass('loading');
4831                                    },
4832                                    error: function () {
4833                                        t.setRefreshTimeuot(lb);
4834                                        lb.removeClass('loading');
4835                                    }
4836                                });
4837                            } else {
4838                                t.setRefreshTimeuot(lb);
4839                                lb.removeClass('loading');
4840                            }
4841                        },
4842                        error: function () {
4843                            t.setRefreshTimeuot(lb);
4844                            lb.removeClass('loading');
4845                        }
4846                    });
4847                }
4848            },
4849            loadOlderEntries: function (lb) {
4850                var t = this,
4851                    lbID = lb.data('liveblog-id'),
4852                    lbCount = parseInt(lb.data('count')),
4853                    lbRefreshInterval = parseInt(lb.data('refresh-interval')),
4854                    lbLoadMoreBtn = lb.find('.liveblog-load-more-button');
4855                lbLastItem = lb.find('.liveblog-item').last();
4856
4857                if (!lb.hasClass('loading')) {
4858                    $.ajax({
4859                        url: '/shared/listing.php',
4860                        data: {
4861                            parent_id: lbID,
4862                            type: 'news_refresh',
4863                            direct: 'true',
4864                            order: 'position,1',
4865                            filter: '{"object_position":{"$gt":' + lbLastItem.data('item-ts') + '}}',
4866                            count: lbCount,
4867                            nocount: 1,
4868                            template: 'liveblog/timeline.html'
4869                        },
4870                        beforeSend: function () {
4871                            lb.addClass('loading');
4872                        },
4873                        success: function (r) {
4874                            var itemsCount = $('<div></div>').html(r).find('.liveblog-item').length;
4875
4876                            lbLastItem.after(r);
4877                            t.initLiveblogEvents()
4878                            if (itemsCount < lbCount) {
4879                                lbLoadMoreBtn.remove();
4880                            }
4881                            lb.removeClass('loading');
4882                        },
4883                        error: function () {
4884                            lb.removeClass('loading');
4885                        }
4886                    });
4887                }
4888            }
4889        },
4890        streamPlayer: {
4891            init: function () {
4892                var playerContainer = $('.stream-player-container'),
4893                    videoId = playerContainer.data('video-id'),
4894                    player = null;
4895
4896                if (videoId !== '') {
4897                    player = new YT.Player('stream-player', {
4898                        videoId: videoId,
4899                        playerVars: {
4900                            autoplay: 1,
4901                            mute: 1,
4902                            controls: 2,
4903                            showinfo: 0,
4904                            rel: 0
4905                        }
4906                    });
4907                }
4908            }
4909        }
4910    }
4911}
4912
4913$(document).ready(function () {
4914    rk.init();
4915});
4916$(document).off('mobileinit').on('mobileinit', function () {
4917    $.event.special.swipe.scrollSupressionThreshold = 50;
4918    $.event.special.swipe.verticalDistanceThreshold = 100;
4919    $.event.special.swipe.horizontalDistanceThreshold = 30;
4920    $.event.special.swipe.durationThreshold = 2500;
4921});
4922
4923function onYouTubeIframeAPIReady() {
4924    rk.modules.streamPlayer.init();
4925}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.