var _refreshPage = function(){
    window.location.href = window.location.href;
};

$.topbar = function(args){
    args = $.extend({},
        {
            url: 'https://home.kul.vn',
            readyurl: 'https://id.kul.vn/notification.html',
            globalPopup: {
                used: true
            },
            globalPopup2: {
                used: false
            },
            urlLogoutCallBack:null,
            getNotice: true,
            idFrameGame : 'KULFULLSIZEFRAME',
            classCollapse : null,
            onready: function(){}
        }, 
        args
    );
    
    $.topbar.args = args;

    var g = {
        body: $('body')
    };
    
        
    g.loggedNoticeFn = function(json2){
        if( ! json2.status) {
            return false;
        }

        // friend
        var friendItem = $('#topbar-friend-click'),
            friendItemParent = friendItem.parent(),
            friendItemUL = $('#topbar-friend-target ul.ListNofi');

        if(friendItemParent.children('.ShowNum').length > 0) {
            if(json2.data.friend.total > 0) {
                friendItemParent.children('.ShowNum').html(json2.data.friend.total);
            }
            else {
                friendItemParent.children('.ShowNum').remove();
            }
        }
        else {
            if(json2.data.friend.total > 0) {
                friendItemParent.append('<i class="ShowNum">' + json2.data.friend.total + '</i>');
            }
        }

        g.html_friend = '<li>Không có yêu cầu mới</li>';
        if(json2.data.friend.total > 0){
            g.html_friend = '';
        }

        $.each(json2.data.friend.list.request, function(i, row){
            var tmp = $.topbar.template.notices.friend_request;
                tmp = tmp.replace(/\{index\}/g, i);
                tmp = tmp.replace(/\{url\}/g, row.url);
                tmp = tmp.replace(/\{name\}/g, row.name);
                tmp = tmp.replace(/\{image\}/g, row.image);
                tmp = tmp.replace(/\{mutual_friend\}/g, row.mutual_friend);
                tmp = tmp.replace(/\{mutual_friend_url\}/g, row.mutual_friend_url);
                tmp = tmp.replace(/\{accept_url\}/g, row.accept_url);
                tmp = tmp.replace(/\{deny_url\}/g, row.deny_url);

             g.html_friend += tmp;
        });

        if(json2.data.friend.list.suggest.length > 0) {
             g.html_friend += $.topbar.template.notices.friend_suggest_label;
        }
        $.each(json2.data.friend.list.suggest, function(i, row){
            var tmp = $.topbar.template.notices.friend_suggest;
                tmp = tmp.replace(/\{index\}/g, i);
                tmp = tmp.replace(/\{url\}/g, row.url);
                tmp = tmp.replace(/\{name\}/g, row.name);
                tmp = tmp.replace(/\{image\}/g, row.image);
                tmp = tmp.replace(/\{mutual_friend\}/g, row.mutual_friend);
                tmp = tmp.replace(/\{mutual_friend_url\}/g, row.mutual_friend_url);
                tmp = tmp.replace(/\{send_request_url\}/g, row.send_request_url);

            g.html_friend += tmp;
        });
        friendItemUL.html(g.html_friend);

        // message
        var messageItem = $('#topbar-message-click'),
            messageItemParent = messageItem.parent(),
            messageItemUL = $('#topbar-message-target ul.ListNofi');

        if(messageItemParent.children('.ShowNum').length > 0) {
            if(json2.data.message.total > 0) {
                messageItemParent.children('.ShowNum').html(json2.data.message.total);
            }
            else {
                messageItemParent.children('.ShowNum').remove();
            }
        }
        else {
            if(json2.data.message.total > 0) {
                messageItemParent.append('<i class="ShowNum">' + json2.data.message.total + '</i>');
            }
        }

        g.html_message = '<li class="NoMess">Không có tin nhắn</li>';
        if(json2.data.message.list.length > 0){
            g.html_message = '';
        }
        
        $.each(json2.data.message.list, function(i, row){
            var tmp = $.topbar.template.notices.message;
                tmp = tmp.replace(/\{url\}/g, row.url);
                tmp = tmp.replace(/\{name\}/g, row.name);
                tmp = tmp.replace(/\{image\}/g, row.image);
                tmp = tmp.replace(/\{date\}/g, row.date);
                tmp = tmp.replace(/\{message\}/g, row.message);

            g.html_message += tmp;
        });
        messageItemUL.html(g.html_message);

        // notification
        var notificationItem = $('#topbar-notification-click'),
            notificationItemParent = notificationItem.parent(),
            notificationItemUL = $('#topbar-notification-target ul.ListNofi');

        if(notificationItemParent.children('.ShowNum').length > 0) {
            if(json2.data.notification.total > 0) {
                notificationItemParent.children('.ShowNum').html(json2.data.notification.total);
            }
            else {
                notificationItemParent.children('.ShowNum').remove();
            }
        }
        else {
            if(json2.data.notification.total > 0) {
                notificationItemParent.append('<i class="ShowNum">' + json2.data.notification.total + '</i>');
            }
        }

        g.html_notification = '<li>Không có thông báo mới</li>';
        if(json2.data.notification.list.length > 0){
            g.html_notification = '';
        }

        $.each(json2.data.notification.list, function(i, row){
            var tmp = $.topbar.template.notices.notification;
                tmp = tmp.replace(/\{url\}/g, row.url);
                tmp = tmp.replace(/\{name\}/g, row.name);
                tmp = tmp.replace(/\{image\}/g, row.image);
                tmp = tmp.replace(/\{date\}/g, row.date);
                tmp = tmp.replace(/\{message\}/g, row.message);

            g.html_notification += tmp;
        });
        notificationItemUL.html(g.html_notification);

        // gọi lại để lấy thông báo mới
        if (args.getNotice) {
            setTimeout(function(){
                $.getScript(args.readyurl, function(){ g.loggedNoticeFn(jsonResponse) });
            }, json2.time_refresh * 1000);
        }
    };
    
    g.initFn = function(json) {

        // có vấn đề ?
        if( ! json.status) {
            return;
        }
        
        $('#topbar').remove();
        
        g.html = $.topbar.template.html;
        g.html = g.html.replace(/\{logo_url\}/g, args.url);

        // for more HTML
        g.html_more = '';

                    g.html_more += $.topbar.template.notices.search;

            // html more
            g.html = g.html.replace('{html_more}',  g.html_more);
        
        // thêm html
        g.body.prepend(g.html);
        
		// get ads from cgame.vn
		var _AdsTopBar, 
			asignVariable = function (data){
				_AdsTopBar = data;
			};
		$.getScript('//st1.kul.vn/adver/ads19.js',function(data) {
			var _AdsItems = AdsSlide["ads_slide_banner32"], 
				cache = '';
			$.each(_AdsItems.banner, function (k,v) {
				cache += '<a class="slide-item" href="' + v.link + '" target="_blank">' +
							'<img src="' + v.source + '" alt="" />' +
						'</a>';
			});
			asignVariable(cache);
		});
		var Timer = setInterval(function() {
			if (_AdsTopBar) {
				$(".slide-ads").empty().html(_AdsTopBar);
				clearTimeout(Timer);
				StartSlide();
			}			
		}, 1000);
		
		var StartSlide = function () {
			var TotalSlideItem = $('.slide-ads .slide-item').length,
				_st = 1;

			$('.slide-ads').each(function(){
				var item = $(this),
					data = item.data();

				item.css({ width: data.width, height: data.height })
					.children('.slide-item').css({ width: data.width });

				setInterval(function(){
					item.children('.slide-item').hide();
					if (_st > TotalSlideItem) _st = 1;
					var _s = $('.slide-item:nth-child(' + _st + ')');
					_s.fadeIn('slow');
					_st++;
				}, 7000);
			});
		};
		// end get ads

        /* ads slide */
        if($('.slide-ads .slide-item').length > 1){
            
        }
        
                if( ! /\/\/id.kul.vn\/dang-nhap.html|\/\/id.kul.vn\/dang-ky.html/g.test(document.URL)) {
            if(typeof $KulCore == 'object'){
                $('#topbar-loginlink').click(function(e){
                    /*$KulCore.popupLogin({'callback': '_refreshPage'});*/
                    //return false;
                });
            }
            else{
                var loginlink = $('#topbar-loginlink');
                    loginlink.attr('href', loginlink.attr('href') + '?ref=' + document.URL);
            }
        }
        
        /* START FIX Tào lao */
                $('#topbar-search-target').css({ marginLeft: '410px' });
                /* END FIX Tào lao */

        // click mở dropmenu
        var oldClicked = null, clickHideFn = function(){
            if(oldClicked != null) {
                oldClicked.target.hide();
                oldClicked.parent.removeClass('Active');
            }
            oldClicked = null;
            g.hoverItemActive = null;
            g.clickItemActive = null;
        };
        $('a[rel=clicked]').click(function(e){
            // loại bỏ sự kiện click document khi click menu
            e.stopPropagation();

            // khai báo đối tượng clicked
            var item = {
                    obj: $(this)
                };
                item.data = item.obj.data();
                item.target = $(item.data.target);
                item.parent = item.obj.parent();

            // nếu dropmenu không tồn tại
            if(item.target.length == 0) {
                return false;
            }
            
            if(item.parent.hasClass('Active')) {
                clickHideFn();
                return false;
            }
            
            // nếu đối tượng là profile
            if(item.data.profile == '1') {
                if( ! item.data.used){
                    item.target.find('.SubNav_List a').each(function(i){
                        var item2 = {
                            obj: $(this)
                        };
                        item2.data = item2.obj.data();
                        item2.target = $(item2.data.target);
                        item2.parent = item2.obj.parent();

                        if(i == 0) {
                            $.getScript(item2.data.href, function(){
                                var json = jsonResponse;
                                if( ! json.status) {
                                    return false;
                                }
                                
                                item.data.used = true;

                                item2.target = item.target;
                                g.target_category = 'my-' + item2.data.template;
                                g.appendCategoryFn(json.rows, item2);

                                // nếu có đối tượng cũ, ẩn nó đi
                                if(oldClicked != null) {
                                    oldClicked.target.hide();
                                    oldClicked.parent.removeClass('Active');
                                }
                                oldClicked = item;
                                
                                item.parent.addClass('Active');
                                item.target.show().click(function(e){
                                    e.stopPropagation();
                                });
                                
                                if(json.rows.length > 0) {
                                    item.target.find('#topbar-' + g.target_category + '.Scroll').mCustomScrollbar({
                                        horizontalScroll: true,
                                        scrollButtons: {
                                            enable: true
                                        },
                                        theme: 'dark-thin'
                                    });
                                }
                                
                                item.tooltip = item.target.find('#topbar-tooltip-' + g.target_category);
                                
                                item2.target = $(item2.data.target);
                                g.oldMyClicked = item2; // target active

                                if(item.tooltip.length > 0) {
                                    item.target.find('.SubNav_List2 li').each(function(){
                                        var itemHover = $(this),
                                            itemHoverA = itemHover.children('a'),
                                            itemHoverAData = itemHoverA.data();
                                    
                                            if(itemHoverAData == undefined || itemHoverAData == null) {
                                                return false;
                                            }
                                            
                                            itemHover.hover(function(){
                                                itemHover.timeout = setTimeout(function(){
                                                    item.tooltip.find('.topbar-tooltip-knownas').html(itemHoverAData.knownas);
                                                    item.tooltip.find('.topbar-tooltip-title').html(itemHoverAData.title);
                                                    item.tooltip.find('.topbar-tooltip-year').html(itemHoverAData.year);
                                                    item.tooltip
                                                        .css({ left: itemHover.offset().left - item.target.offset().left + 21 - (itemHover.outerWidth() / 2) })
                                                            .show();
                                                }, 100);
                                            }, function(){
                                                item.tooltip.hide();
                                                clearTimeout(itemHover.timeout);
                                            }).mousewheel(function(){
                                                item.tooltip.hide();
                                                clearTimeout(itemHover.timeout);
                                            });
                                    });
                                }
                            });
                        }
                        
                        // click category
                        item2.obj.click(function(){
                            g.clickItemActive = 'profile';
                            if(item2.target.length > 0) {
                                if(g.oldMyClicked.data.target != item2.data.target){
                                    item2.target.show(); item2.parent.addClass('Active');

                                    g.oldMyClicked.target.hide(); g.oldMyClicked.parent.removeClass('Active');
                                    g.oldMyClicked = item2;
                                }
                            }
                            else {
                                $.getScript(item2.data.href, function(){ 
                                    var json = jsonResponse;
                                    if( ! json.status) {
                                        return false;
                                    }
                                    
                                    g.oldMyClicked.target.hide(); g.oldMyClicked.parent.removeClass('Active');
                                    
                                    item.data.used = true;

                                    item2.target = item.target;
                                    g.target_category = 'my-' + item2.data.template;
                                    g.appendCategoryFn(json.rows, item2);
                                    
                                    // fix cái này để hiển thị scroll horizontal
                                    if(g.clickItemActive != 'profile') {
                                        item.target.css({ visibility: 'hidden', 'display': 'block' });
                                    }
                                    
                                    if(json.rows.length > 0) {
                                        item.target.find('#topbar-' + g.target_category + '.Scroll').mCustomScrollbar({
                                            horizontalScroll: true,
                                            scrollButtons: {
                                                enable: true
                                            },
                                            theme: 'dark-thin'
                                        });
                                    }
                                
                                    item.tooltip = item.target.find('#topbar-tooltip-' + g.target_category);
                                    
                                    if(g.clickItemActive != 'profile') {
                                        item.target.css({ visibility: 'visible', 'display': 'none' });
                                    }
                                    
                                    item2.parent.addClass('Active');
                                    item2.target = $(item2.data.target);
                                    g.oldMyClicked = item2; // target active

                                    if(item.tooltip.length > 0) {
                                        item.target.find('.SubNav_List2 li').each(function(){
                                            var itemHover = $(this),
                                                itemHoverA = itemHover.children('a'),
                                                itemHoverAData = itemHoverA.data();
                                    
                                                if(itemHoverAData == undefined || itemHoverAData == null) {
                                                    return false;
                                                }
                                
                                                itemHover.hover(function(){
                                                    itemHover.timeout = setTimeout(function(){
                                                        item.tooltip.find('.topbar-tooltip-knownas').html(itemHoverAData.knownas);
                                                        item.tooltip.find('.topbar-tooltip-title').html(itemHoverAData.title);
                                                        item.tooltip.find('.topbar-tooltip-year').html(itemHoverAData.year);
                                                        item.tooltip
                                                            .css({ left: itemHover.offset().left - item.target.offset().left + 21 - (itemHover.outerWidth() / 2) })
                                                                .show();
                                                    }, 100);
                                                }, function(){
                                                    item.tooltip.hide();
                                                    clearTimeout(itemHover.timeout);
                                                }).mousewheel(function(){
                                                    item.tooltip.hide();
                                                    clearTimeout(itemHover.timeout);
                                                });
                                        });
                                    }
                                });
                            }
                            
                            return false;
                        });
                    });
                }
                else {
                    // nếu có đối tượng cũ, ẩn nó đi
                    if(oldClicked != null) {
                        oldClicked.target.hide();
                        oldClicked.parent.removeClass('Active');
                    }
                    oldClicked = item;

                    // loại bỏ sự kiện click document khi click vào dropmenu
                    item.parent.addClass('Active');
                    item.target.show().click(function(e){
                        e.stopPropagation();
                    });
                }
            }
            else {
                // nếu đối tượng clicked có yêu cầu gọi ajax
                if(item.data.href && (oldClicked == null || item.data.target != oldClicked.data.target)) {
                    $.getScript(item.data.href, function(){ 
                        var json = jsonResponse;
                        item.parent.find('.ShowNum').remove();
                    });
                }

                // nếu có đối tượng cũ, ẩn nó đi
                if(oldClicked != null) {
                    oldClicked.target.hide();
                    oldClicked.parent.removeClass('Active');
                }
                oldClicked = item;

                // loại bỏ sự kiện click document khi click vào dropmenu
                item.parent.addClass('Active');
                item.target.show().click(function(e){
                    e.stopPropagation();
                });
                
                if(/\-search\-/.test( item.data.target )) {
                    document['form-search'].q.focus();
                }
                else if(/\-friend\-/.test( item.data.target )) {
                    item.target.find('.friend-accept, .friend-deny, .friend-send-request').click(function(){
                        var item2 = {
                                obj: $(this)
                            };
                            item2.data = item2.obj.data();
                            item2.parent = item2.obj.parent();
                            item2.target = $(item2.data.target);
                        
                        if(item2.target.length == 0) {
                            return;
                        }

                        $.getScript(item2.data.href, function(){
                            var json5 = jsonResponse;
                            if(json5.status) {
                                item2.target.remove();
                            }
                        });
                        
                        return false;
                    });
                }
            }

            return false;
        });
        
        // click document for hidden dropmenu's clicked
        $(document).click(clickHideFn);

        // hover mở dropmenu
        var oldHover = null;
        $('a[rel=hover]').each(function(){
            var item = {
                    obj: $(this)
                };
                item.data = item.obj.data();
                item.parent = item.obj.parent();
                item.target = $(item.data.target);
            
            item.parent.hover(function(){
                if(item.data.error || item.data.busy) {
                    return;
                }
                g.hoverItemActive = item.data.template;
                
                if( ! item.data.used){
                    item.data.busy = true;
                    $.getScript(item.data.href, function(){
                        if( ! jsonResponse.status) {
                            item.data.error = true;
                            return false;
                        }
                        item.data.used = true;
                        item.data.busy = false;

                        g.html_category = '';
                        g.target_category = '';
                        if(jsonResponse.rows.length == 0) {
                            g.html_category = $.topbar.template.norow;
                        }
                        else {
                            $.each(jsonResponse.rows, function(i, row){
                                var tmp = $.topbar.template.category;
                                    tmp = tmp.replace(/\{class\}/g, i == 0 ? ' class="Active"' : '');
                                    tmp = tmp.replace(/\{url\}/g, row.link);
                                    tmp = tmp.replace(/\{name\}/g, row.name);
                                    tmp = tmp.replace(/\{target\}/g, item.data.template + '-' + i);
                            
                                g.html_category += tmp;

                                g.target_category = item.data.template + '-' + i;
                            
                                // append list
                                g.appendCategoryFn(row.rows, item, i > 0 ? 'display: none;' : '');
                            
                                if(i == 0){
                                    // fix cái này để hiển thị scroll horizontal
                                    if(g.hoverItemActive != item.data.template) {
                                        item.target.css({ visibility: 'hidden', 'display': 'block' });
                                    }
                                    else {
                                        item.target.show();
                                        item.parent.addClass('Active');
                                    }
                                    
                                    if(row.rows.length > 0) {
                                        item.target.find('#topbar-' + g.target_category + '.Scroll').mCustomScrollbar({
                                            horizontalScroll: true,
                                            scrollButtons: {
                                                enable: true
                                            },
                                            theme: 'dark-thin'
                                        });
                                    }
                                
                                    item.tooltip = item.target.find('#topbar-tooltip-' + g.target_category);

                                    if(g.hoverItemActive != item.data.template) {
                                        item.target.css({ visibility: 'visible', 'display': 'none' });
                                    }
                                }
                            });
                        }
                        
                        item.target.find('.SubNav_List')
                            .html(g.html_category);

                        if(item.tooltip.length > 0) {
                            item.target.find('.SubNav_List2 li').each(function(){
                                var itemHover = $(this),
                                    itemHoverA = itemHover.children('a'),
                                    itemHoverAData = itemHoverA.data();
                                    
                                    if(itemHoverAData == undefined || itemHoverAData == null) {
                                        return false;
                                    }
                                    
                                    itemHover.hover(function(){
                                        itemHover.timeout = setTimeout(function(){
                                            item.tooltip.find('.topbar-tooltip-knownas').html(itemHoverAData.knownas);
                                            item.tooltip.find('.topbar-tooltip-title').html(itemHoverAData.title);
                                            item.tooltip.find('.topbar-tooltip-year').html(itemHoverAData.year);
                                            item.tooltip
                                                .css({ left: itemHover.offset().left - item.target.offset().left + 21 - (itemHover.outerWidth() / 2) })
                                                .show();
                                        }, 100);
                                    }, function(){
                                        item.tooltip.hide();
                                        clearTimeout(itemHover.timeout);
                                    }).mousewheel(function(){
                                        item.tooltip.hide();
                                        clearTimeout(itemHover.timeout);
                                    });
                            });
                        }
                            
                        // click category
                        item.a1 = item.target.find('.SubNav_List a'); // danh sách category
                        item.a2 = null; // target active

                        // lọc tất cả category
                        item.a1.each(function(i){
                            var item2 = {
                                    obj: $(this)
                                };
                                item2.data = item2.obj.data();
                                item2.target = $(item2.data.target);
                                item2.parent = item2.obj.parent();

                            if(i == 0) {
                                item.a2 = item2;
                            }
                            item2.obj.hover(function(){

                                item.a2.target.hide(); item.a2.parent.removeClass('Active'); item.a2 = item2;
                                item2.target.show(); item2.parent.addClass('Active');
                                
                                if( ! item2.target.hasClass('mCustomScrollbar') && item2.target.find('.TextInfomation').length == 0){
                                    
                                    // fix cái này để hiển thị scroll horizontal
                                    if(g.hoverItemActive != item.data.template) {
                                        item.target.css({ visibility: 'hidden', 'display': 'block' });
                                    }
                                    
                                    // tạo ra scroll horizontal
                                    item2.target.mCustomScrollbar({
                                        horizontalScroll: true,
                                        scrollButtons: {
                                            enable: true
                                        },
                                        theme: 'dark-thin'
                                    });
                                    
                                    if(g.hoverItemActive != item.data.template) {
                                        item.target.css({ visibility: 'visible', 'display': 'none' });
                                    }
                                }

                                return false;
                            });
                        });
                    });
                }
                else {
                    item.target.show(); item.parent.addClass('Active');
                }
            }, function(){
                item.target.hide(); item.parent.removeClass('Active');
                g.hoverItemActive = null;
            });
        });
        
        
        //Kietthm Collapse TopBar
        if($( '[name="KULIFRAMPLAY"]' ).contents().length>0){
            $('#topbar-collapse').hide();
            $('#topbar-expand-iframe').show('slow');
        }
        //FullScreen
        $('#topbar-expand-iframe').click(function(){
            var element= document.getElementById("KULFULLSIZEFRAME");
            if (element.requestFullscreen){
                return element.requestFullscreen();
            }else if (element.webkitRequestFullScreen){
                return  element.webkitRequestFullScreen();
            }else if (element.mozRequestFullScreen) { 
                return element.mozRequestFullScreen();
            }else{
                alert('Xin lỗi, trình duyệt không hỗ trợ');
            };
        });
        
        $('#topbar-collapse').click(function(){
            
            $('#topbar').animate({
                top: "-35px"
            });
            
            if(args.classCollapse){
                $('.'+args.classCollapse).animate({
                    marginTop: "-35px"
                });
            }else{
                $(document.body).animate({
                    marginTop: "-35px"
                });
            }
            $('#topbar-collapse').hide();
            $('#topbar-expand').show('slow');
            if(args.idFrameGame){
                $('#'+args.idFrameGame).animate({
                    top: "10px",
                    'height':jQuery(window).height()
                });
                $('#topbar-expand-iframe').show('slow');
                $( '[name="KULIFRAMPLAY"]' ).contents().find( "#PlayFrame" ).animate({
                    'height':jQuery(window).height()-10
                }, 500);  
                
            }
        });
        
        $('#topbar-expand').click(function(){
            $('#topbar').animate({
                top: "0px"
            });
            if(args.classCollapse){
                $('.'+args.classCollapse).animate({
                    marginTop: "0px"
                });
            }else{
                $(document.body).animate({
                    marginTop: "0px"
                });
            }
            $('#topbar-expand').hide();
            $('#topbar-collapse').show();
            if($( '[name="KULIFRAMPLAY"]' ).contents().length==0){
                $('#topbar-expand-iframe').hide();
            }
        });
        //END Kietthm Collapse TopBar
        
        // search
        var scache = [],
            stimer = null,
            otherFn = function(value, data){
                var html = '';
                if(data.status) {
                    $.each(data.rows, function(index, rows){
                        if(rows.length > 0) {
                            var temp = $.topbar.template.search['wrap_' + index],
                                items = '';
                            $.each(rows, function(i, row){
                                var item = $.topbar.template.search.item;
                                $.each(row, function(key, value){
                                    item = item.replace( new RegExp('\{' + key + '\}', 'g'), value );
                                });
                                items += item;
                            });
                            html += temp.replace(/\{rows\}/g, items);
                        }
                    });
            
                    var suggest_text = $.topbar.template.search.suggest.replace(/\{keyword\}/g, value);
                        suggest_text = suggest_text.replace(/\{num\}/g, data.total);
            
                    html += suggest_text;
                }
                suggest.html(html).css({ padding: '' });
            },
            movieFn = function(value, data){
                var html = '';
                if(data.status && data.rows.length > 0) {
                    var temp = $.topbar.template.search.wrap_movie,
                        items = '';
                    $.each(data.rows, function(i, row){
                        var item = $.topbar.template.search.item;
                        $.each(row, function(key, value){
                            item = item.replace( new RegExp('\{' + key + '\}', 'g'), value );
                        });
                        items += item;
                    });
                    html += temp.replace(/\{rows\}/g, items);
                
                    if(suggest.html().length > 0) {
                
                        suggest.prepend(html);
                        var num = suggest.find('span.num'),
                            numtext = num.text();
                    
                        num.text(parseInt(numtext) + data.total);
                    
                    } else {
                        var suggest_text = $.topbar.template.search.suggest.replace(/\{keyword\}/g, value);
                            suggest_text = suggest_text.replace(/\{num\}/g, data.total);
                        
                        html += suggest_text;
                    
                        suggest.html(html).css({ padding: '' });
                    }
                }
            },
            search = $('#form-search').submit(function(e){
                var href = $('li[rel=search-suggest-item].actived a').attr('href');
                if(typeof href === 'string' && href.length > 0) {
                    window.location.href = href;
                    e.preventDefault();
                }
            }),
            indexFn = function(items) {
                var index = 0, hasActive = false;
                items.each(function(){
                    if($(this).hasClass('actived')) {
                        hasActive = true;
                        return false;
                    }
                    index++;
                });
                
                return ! hasActive ? -1 : index;
            },
            suggest = $('#suggest-search').css({ padding: '0' }),
            keyword = $('#q-search').keyup(function(e){
                var q = this,
                    l = $('li[rel=search-suggest-item]'),
                    a = l.filter('.actived'),
                    i = indexFn(l);
                    
                if(e.keyCode == 40) { // down
                    var item = $( l[i + 1] != undefined ? l[i + 1] : l[0] );
                        item.addClass('actived').css('background-color', '#c5c5c5'); a.removeClass('actived').css('background-color', '');
                }
                else if(e.keyCode == 38) { // up
                    var item = $( l[i - 1] != undefined ? l[i - 1] : l[l.length - 1] );
                        item.addClass('actived').css('background-color', '#c5c5c5'); a.removeClass('actived').css('background-color', '');
                }
                else if(e.keyCode == 27) { // esc
                    if(suggest.html() == '')  {
                        if(oldClicked != null) {
                            oldClicked.target.hide();
                            oldClicked.parent.removeClass('Active');
                        }
                        oldClicked = null;
                        g.hoverItemActive = null;
                        g.clickItemActive = null;
                    } else {
                        q.value = '';
                        suggest.html('').css({ padding: '0' });
                    }
                }
                else if(e.keyCode != 13) {
                    if(q.value.length >= 3) {
                        clearTimeout(stimer);
                        stimer = setTimeout(function(){
                            if(q.value.length < 3) {
                                return false;
                            }
                            if( scache[ q.value ] ) {
                                otherFn(q.value, scache[ q.value ].other);
                                movieFn(q.value, scache[ q.value ].movie);
                            }
                            else {
                                scache[ q.value ] = {
                                    other: {},
                                    movie: {}
                                };
                                $.post('https://bar.kul.vn/index/search', { q: q.value }, function(dataResponse){
                                    scache[ q.value ].other = dataResponse;
                                    otherFn(q.value, dataResponse);
                                }, 'json');
                            
                                // search phim
                                                             }
                        }, 500);
                    }
                }
                return false;
            });
    };
    
    g.appendCategoryFn = function(rows, item, style){
        g.html_list = '';
        var index = 1, tmp_html = '';
        $.each(rows, function(i, row){
            var tmp = $.topbar.template[ item.data.template ].item;
            if( ! row.image) {
                tmp = $.topbar.template[ item.data.template ].item2;
            }

            if(row.link) {
                tmp = tmp.replace(/\{link\}/g, row.link);
            }

            if(row.play) {
                tmp = tmp.replace(/\{link_play\}/g, row.play);
            }

            if(row.image) {
                tmp = tmp.replace(/\{image\}/g, row.image);
            }

            if(row.title) {
                tmp = tmp.replace(/\{title\}/g, row.title);
            }

            if(row.year) {
                tmp = tmp.replace(/\{year\}/g, row.year);
            }

            if(row.knownas) {
                tmp = tmp.replace(/\{knownas\}/g, row.knownas);
            }

            if(row.name) {
                tmp = tmp.replace(/\{name\}/g, row.name);
            }

            if(row.description) {
                tmp = tmp.replace(/\{description\}/g, row.description);
            }
            
            if( ! row.image) {
                if(index % 6 == 0) {
                    g.html_list += '<li><ul>' + tmp_html + '</ul></li>';
                    tmp_html = '';
                    index = 0;
                }
                else {
                    tmp_html += tmp;
                }
            }
            else {
                g.html_list += tmp;
            }
            
            
            index++;
        });
        
        style = style == undefined ? '' : style;
        if(rows.length == 0) {
            var listWrap = $.topbar.template.category_norow,
                listObj = null;

            listWrap = listWrap.replace(/\{target\}/g, g.target_category);
            listWrap = listWrap.replace(/\{html\}/g, $.topbar.template.norow);
            listWrap = listWrap.replace(/\{style\}/g, style);

            item.target.find('.SubNav_List2').append(listWrap);
        }
        else {
            var listWrap = $.topbar.template[ item.data.template ].wrap,
                listWidth = 0,
                listObj = null;

            listWrap = listWrap.replace(/\{target\}/g, g.target_category);
            listWrap = listWrap.replace(/\{rows\}/g, g.html_list);
            listWrap = listWrap.replace(/\{style\}/g, style);

            item.target.find('.SubNav_List2').append(listWrap);

            listObj = item.target.find('#topbar-' + g.target_category + ' > ul');
            listObj.children().each(function(){
                listWidth += $(this).outerWidth();
            });
            listObj.width(listWidth);
        }
    };
    
    //
    args.onready.call();
    try {
        g.initFn({ status: true });
    } catch(e) {
        g.initFn({ status: true, error: true });
    }
        
    $.globalPopup(args.globalPopup);
    $.globalPopup2(args.globalPopup2);
    
    };

$.topbar.args = {};

$.topbar.refresh = function(){
    $.topbar($.topbar.args);
};

$.topbar.template = {
    html: 
'<div id="topbar" >' +
    '<div class="SubMenu">' +
        '<div class="Main">' +
            '<a href="{logo_url}" class="Logo" title="Kul kết nối game thủ">Kul kết nối game thủ</a>' +
            '<ul class="MenuBar">' +
			
                '<li>' +
                    '<a href="https://game.kul.vn" rel="hover" data-href="https://game.kul.vn/api/game/topbar" data-target="#topbar-game-target" data-template="game">' +
                        'Game' +
                        '<i class="Icon"></i>' +
                    '</a>' +
                    '<div class="SubNav" id="topbar-game-target" style="display: none; left: -154px">' +
                        '<ul class="SubNav_List"></ul>' +
                        '<div class="SubNav_List2"></div>' +
                    '</div>' +
                '</li>' +
				
								                            '</ul>' +
            
            '{html_more}' +
            
            '<img src="http://bar.kul.vn/images/loading-bar.gif" id="topbar-loading" />' +
            
            /* SEARCH */
            '<div class="BgList_Social Search" id="topbar-search-target" style="display: none">' +
                '<div class="Bot_BgList_Social">' +
                    '<form id="form-search" name="form-search" method="get" action="https://home.kul.vn/tim-kiem.html" autocomplete="off">' +
                        '<fieldset>' +
                            '<label for="q-search"></label>' +
                            '<input type="text" name="q" id="q-search" class="BgTopSearch" placeholder="Nhập từ khóa" />' +
                            '<input type="submit" class="BSearch" />' +
                        '</fieldset>' +
                    '</form>' +
                    '<div id="suggest-search" class="Suggest"></div>' +
                '</div>' +
            '</div>' +
        '</div>' +
    '</div>' +
    '<div id="topbar-collapse" style="display: block;float:right;color:#000;margin-right: 52px;cursor: pointer;margin-top:-32px">' +
        '<img src="//st1.kul.vn/kulst/bar/images/topbar_collapse.png" width="18px"/>' +
    '</div>' +
    '<div id="topbar-expand" style="display: block;float:right;color:#fff;margin-right: 52px;cursor: pointer;display:none;margin-top:3px">' +
        '<img src="//st1.kul.vn/kulst/bar/images/topbar_expand.png" width="18px"/>' +
    '</div>' +
    '<div id="topbar-expand-iframe" style="float:right;color:#000;margin-right: 52px;cursor: pointer;margin-top:-32px;display:none;">' +
        '<img src="//st1.kul.vn/kulst/bar/images/fullscreen.png" width="23px"/>' +
    '</div>' +
'</div>',
    search: {
        suggest: 
'<p class="Result">' +
    'Kết quả gợi ý cho “{keyword}”: <span class="TextRed"><span class="num">{num}</span> từ</span>' +
'</p>',
        item: 
'<li rel="search-suggest-item"><a href="{link}">{name}</a></li>',
        wrap_news: 
'<div id="searchnews">' +
    '<h3 class="TextGreen"><i class="IconNews"></i>News</h3>' +
    '<a href="#" class="TextGreen Search_View">Xem thêm</a>' +
    '<ul class="ListSuggest">{rows}</ul>' +
'</div>',
        wrap_house:
'<div id="searchkul_house">' +
    '<h3 class="TextBlue"><i class="IconKul_House"></i>Kul House</h3>' +
    '<a href="#" class="TextBlue Search_View">Xem thêm</a>' +
    '<ul class="ListSuggest">{rows}</ul>' +
'</div>',
        wrap_movie:
'<div id="searchphim">' +
    '<h3 class="TextPurple"><i class="IconPhim"></i>Phim</h3>' +
    '<a href="#" class="TextPurple Search_View">Xem thêm</a>' +
    '<ul class="ListSuggest">{rows}</ul>' +
'</div>',
        wrap_game:
'<div id="searchgame">' +
    '<h3 class="TextOrange"><i class="IconGame"></i>Game</h3>' +
    '<a href="#" class="TextOrange Search_View">Xem thêm</a>' +
    '<ul class="ListSuggest">{rows}</ul>' +
'</div>'
    },
    category:
'<li{class}>' + 
    '<a title="{name}" data-target="#topbar-{target}" href="{url}">{name}</a>' + 
'</li>',
    category_norow: '<div class="Scroll" id="topbar-{target}" style="{style}">{html}</div>',
    norow: '<p class="TextInfomation"><strong class="Text25">&lsquo;&lsquo;</strong> Chưa có thông tin <strong class="Text25">&rsquo;&rsquo;</strong></p>',
    news: {
        item:
'<li>' +
    '<a href="{link}" title="{title}">' +
        '<img src="{image}" alt="{title}" width="159px" />' +
        '<p><strong>{title}</strong></p>' +
    '</a>' +
'</li>',
        wrap:
'<div class="Scroll" id="topbar-{target}" style="{style}">' +
    '<ul class="ChildList Game News clearfix">{rows}</ul>' +
'</div>'
    },
    game: {
        item:
'<li>' +
    '<a href="{link}" title="{title}">' +
        '<img src="{image}" alt="{title}" />' +
        '<p><strong>{title}</strong></p>' +
    '</a>' +
    '<a href="{link_play}" class="ChoiNgay">Chơi Ngay</a>' +
'</li>',
        wrap:
'<div class="Scroll" id="topbar-{target}" style="{style}">' +
    '<ul class="ChildList Game clearfix">{rows}</ul>' +
'</div>'
    },
    movie: {
        item:
'<li>' +
    '<a href="{link}" title="{title}" data-title="{title}" data-year="{year}" data-knownas="{knownas}">' +
        '<img src="{image}" alt="{title}" width="100px" />' + 
    '</a>' +
'</li>',
        item2:
'<li>' +
    '<a href="{link}" title="{name}">' +
        '{name}' + 
    '</a>' +
'</li>',
        wrap:
'<div class="Scroll" id="topbar-{target}" style="{style}">' +
    '<ul class="ChildList Movie clearfix">{rows}</ul>' +
'</div>' +
'<div class="Tooltip" id="topbar-tooltip-{target}" style="display: none">' +
    '<p class="Purple topbar-tooltip-knownas">{knownas}</p>' +
    '<p><strong class="topbar-tooltip-title">{title}</strong></p>' +
    '<p><strong class="topbar-tooltip-year">{year}</strong></p>' +
'</div>'
    },
    movie2: {
        item:
'<li>' +
    '<a href="{link}" title="{title}" data-title="{title}" data-year="{year}" data-knownas="{knownas}">' +
        '<img src="{image}" alt="{title}" width="100px" />' + 
    '</a>' +
'</li>',
        item2:
'<li>' +
    '<a href="{link}" title="{name}">' +
        '{name}' + 
    '</a>' +
'</li>',
        wrap:
'<div class="Scroll" id="topbar-{target}" style="{style}">' +
    '<ul class="ChildList Movie clearfix">{rows}</ul>' +
'</div>' +
'<div class="Tooltip" id="topbar-tooltip-{target}" style="display: none">' +
    '<p class="Purple topbar-tooltip-knownas">{knownas}</p>' +
    '<p><strong class="topbar-tooltip-title">{title}</strong></p>' +
    '<p><strong class="topbar-tooltip-year">{year}</strong></p>' +
'</div>'
    },
    notices: {
        wrap:
'<div class="Social">' +
    '<ul class="ListSocial">' +
        '<li>' +
            '<a href="#" title="Tìm kiếm" class="Search" rel="clicked" id="topbar-search-click" data-target="#topbar-search-target">Tìm kiếm</a>' +
        '</li>' +
                '<li>' +
            '<a href="#" title="Thông báo" class="Connect" rel="clicked" id="topbar-notification-click" data-target="#topbar-notification-target" data-href="https://id.kul.vn/notification.html">Thông báo</a>' +
            '{total_notification}' +
        '</li>' +
        '<li class="Profile None">' +
            '<a href="#" rel="clicked" id="topbar-profile-click" data-target="#topbar-profile-target" data-profile="1">' +
                '<img src="" alt="" />' +
            '</a>' +
        '</li>' +
    '</ul>' +
'</div>' +

'<div class="Ads_Topbar">' +
    '<div class="Ads slide-ads" id="tb_logined">' + 
    '</div>' +
'</div>' +

/* PROFILE */
'<div class="SubNav profile" id="topbar-profile-target" style="display: none">' +
    '<ul class="SubNav_List">' +
        '<li class="Active">' +
            '<a href="#" data-href="https://game.kul.vn/game/game-da-choi.html" data-target="#topbar-my-game" data-template="game" title="Game đã chơi">Game đã chơi</a>' +
        '</li>' +
                            '</ul>' +
    '<div class="SubNav_List2"></div>' +
    '<div class="User_Profile">' +
        '<a href="https://id.kul.vn/tai-khoan.html" title="Thông tin tài khoản">' +
            '<img src="" alt="" />' +
        '</a>' +
        '<div class="Info">' +
            '<p class="UserName"><a href="https://id.kul.vn/tai-khoan.html" title="Thông tin tài khoản" style="color: #000"></a></p>' +
            '<ul class="List_Info">' +
                '<li>' +
                    '<a href="https://id.kul.vn/tai-khoan.html" title="Thông tin tài khoản">Thông tin tài khoản</a>' +
                '</li>' +
                '<li>' +
                    '<a href="https://id.kul.vn/cap-nhat-thong-tin.html" title="Thông tin tài khoản">Cập nhật thông tin</a>' +
                '</li>' +
                '<li>' +
                    '<a href="https://id.kul.vn/thay-doi-mat-khau.html" title="Thông tin tài khoản">Thay đổi mật khẩu</a>' +
                '</li>' +
                '<li>' +
                    '<a href="https://id.kul.vn/nap-xu.html" title="Thông tin tài khoản">Nạp Kxu </a>' +
                '</li>' +
                '<li>' +
                    '<a href="https://id.kul.vn/lich-su-giao-dich.html" title="Thông tin tài khoản">Lịch sử giao dịch</a>' +
                '</li>' +
            '</ul>' +
            '<a href="{url_logout}" title="Thoát" class="Thoat">Thoát</a>' +
        '</div>' +
    '</div>' +
'</div>' +

/* FRIEND */
'<div class="BgList_Social Nofitication" id="topbar-friend-target" style="display: none">' +
    '<div class="Bot_BgList_Social Nofitication">' +
        '<ul class="ListNofi Confirm"> ' +
            '{html_friend}' +
        '</ul>' +
        '<p class="ViewMore"><strong><a href="{url_viewall_friend}">Xem tất cả yêu cầu kết bạn</a></strong></p>' +
    '</div>' +
'</div>' +

/* NOTIFYCATION */
'<div class="BgList_Social Nofitication" id="topbar-notification-target" style="display: none">' +
    '<div class="Bot_BgList_Social Nofitication">' +
        '<p class="TextDes"><span class="">Thông báo</span></p>' +
        '<ul class="ListNofi">' +
            '{html_notification}' +
        '</ul>' +
    '</div>' +
'</div>' +

/* MESSAGE */
'<div class="BgList_Social Nofitication" id="topbar-message-target" style="display: none">' +
    '<div class="Bot_BgList_Social Nofitication">' +
        '<p class="TextDes"><span class="">Hộp thư</span><!--<span><a href="{url_viewall_message}" class="FloatRight">Gửi tin nhắn mới</a></span>--></p>' +
        '<ul class="ListNofi">' +
            '{html_message}' +
        '</ul>' +
        '<p class="ViewMore"><strong><a href="{url_viewall_message}">Xem tất cả tin nhắn</a></strong></p>' +
    '</div>' +
'</div>',
        search:
'<div class="Social">' +
    '<ul class="ListSocial">' +
        '<li>' +
            '<a href="https://id.kul.vn/dang-nhap.html" title="Đăng nhập Kul" class="Icon_Login" id="topbar-loginlink">Đăng nhập Kul</a>' +
        '</li>' +
        '<li>' +
            '<a href="#" title="Tìm kiếm" class="Search" rel="clicked" data-target="#topbar-search-target">Tìm kiếm</a>' +
        '</li>' +
        '<li id="topbar-busy" style="display: none">' +
            '<a href="javascript:;" title="Đang tải" class="Icon_Busy">Đang tải</a>' +
        '</li>' +
    '</ul>' +
'</div>' + 
'<div class="Ads_Topbar">' +
    '<div class="Ads slide-ads" id="test1">' +

    '</div>' +
'</div>',
        friend_request:
'<li id="topbar-friend-request-{index}">' +
    '<a href="{url}"><img src="{image}" alt="" /></a>' +
    '<div class="Des">' +
        '<div class="FriendName">' +
            '<p class="Blue"><a href="{url}">{name}</a></p>' +
            '<p><a href="{mutual_friend_url}">{mutual_friend} bạn chung</a></p>' +
        '</div>' +
        '<a class="Confirm friend-accept" href="#" data-href="{accept_url}" data-target="#topbar-friend-request-{index}" title="Chịu">Chịu</a>' +
        '<a class="NoConfirm friend-deny" href="#" data-href="{deny_url}" data-target="#topbar-friend-request-{index}" title="Không chịu">Không chịu</a>' +
    '</div>' +
'</li>',
        friend_suggest_label:
'<li class="Line"></li>' +
'<li><strong>Hình như bạn quen nè</strong></li>',
        friend_suggest:
'<li id="topbar-friend-suggest-{index}">' +
    '<a href="{url}"><img src="{image}" alt="" /></a>' +
    '<div class="Des">' +
        '<div class="FriendName">' +
            '<p class="Blue"><a href="{url}">{name}</a></p>' +
            '<p><a href="{mutual_friend_url}">{mutual_friend} bạn chung</a></p>' +
        '</div>' +
        '<a class="NoConfirm friend-send-request" href="#" data-href="{send_request_url}" data-target="#topbar-friend-suggest-{index}" title="Kết bạn nhé">Kết bạn nhé</a>' +
    '</div>' +
'</li>',
        message:
'<li>' +
    '<a href="{url}">' +
        '<img src="{image}" alt="" class="noti_avatar" />' +
        '<div class="Des">' +
            '<p class="Blue">{name}</p>' +
            '<p>{message}</p>' +
            '<p class="Text11 TextGray">{date}</p>' +
        '</div>' +
    '</a>' +
'</li>',
        notification:
'<li>' +
    '<a href="{url}">' +
        '<img src="{image}" alt="" class="noti_avatar" />' +
        '<div class="Des">' +
            '<p><span>{message}</span></p>' +
            '<p class="Text11 TextGray">{date}</p>' +
        '</div>' +
    '</a>' +
'</li>'
    }
};

/* jquery.mousewheel */
(function(factory){if(typeof define==='function'&&define.amd){define(['jquery'],factory)}else if(typeof exports==='object'){module.exports=factory}else{factory(jQuery)}}(function($){var toFix=['wheel','mousewheel','DOMMouseScroll','MozMousePixelScroll'],toBind=('onwheel'in document||document.documentMode>=9)?['wheel']:['mousewheel','DomMouseScroll','MozMousePixelScroll'],slice=Array.prototype.slice,nullLowestDeltaTimeout,lowestDelta;if($.event.fixHooks){for(var i=toFix.length;i;){$.event.fixHooks[toFix[--i]]=$.event.mouseHooks}}$.event.special.mousewheel={version:'3.1.6',setup:function(){if(this.addEventListener){for(var i=toBind.length;i;){this.addEventListener(toBind[--i],handler,false)}}else{this.onmousewheel=handler}},teardown:function(){if(this.removeEventListener){for(var i=toBind.length;i;){this.removeEventListener(toBind[--i],handler,false)}}else{this.onmousewheel=null}}};$.fn.extend({mousewheel:function(fn){return fn?this.bind('mousewheel',fn):this.trigger('mousewheel')},unmousewheel:function(fn){return this.unbind('mousewheel',fn)}});function handler(event){var orgEvent=event||window.event,args=slice.call(arguments,1),delta=0,deltaX=0,deltaY=0,absDelta=0;event=$.event.fix(orgEvent);event.type='mousewheel';if('detail'in orgEvent){deltaY=orgEvent.detail*-1}if('wheelDelta'in orgEvent){deltaY=orgEvent.wheelDelta}if('wheelDeltaY'in orgEvent){deltaY=orgEvent.wheelDeltaY}if('wheelDeltaX'in orgEvent){deltaX=orgEvent.wheelDeltaX*-1}if('axis'in orgEvent&&orgEvent.axis===orgEvent.HORIZONTAL_AXIS){deltaX=deltaY*-1;deltaY=0}delta=deltaY===0?deltaX:deltaY;if('deltaY'in orgEvent){deltaY=orgEvent.deltaY*-1;delta=deltaY}if('deltaX'in orgEvent){deltaX=orgEvent.deltaX;if(deltaY===0){delta=deltaX*-1}}if(deltaY===0&&deltaX===0){return}absDelta=Math.max(Math.abs(deltaY),Math.abs(deltaX));if(!lowestDelta||absDelta<lowestDelta){lowestDelta=absDelta}delta=Math[delta>=1?'floor':'ceil'](delta/lowestDelta);deltaX=Math[deltaX>=1?'floor':'ceil'](deltaX/lowestDelta);deltaY=Math[deltaY>=1?'floor':'ceil'](deltaY/lowestDelta);event.deltaX=deltaX;event.deltaY=deltaY;event.deltaFactor=lowestDelta;args.unshift(event,delta,deltaX,deltaY);if(nullLowestDeltaTimeout){clearTimeout(nullLowestDeltaTimeout)}nullLowestDeltaTimeout=setTimeout(nullLowestDelta,200);return($.event.dispatch||$.event.handle).apply(this,args)}function nullLowestDelta(){lowestDelta=null}}));

/* jquery cookie */
(function(factory){if(typeof define==='function'&&define.amd){define(['jquery'],factory)}else if(typeof exports==='object'){factory(require('jquery'))}else{factory(jQuery)}}(function($){var pluses=/\+/g;function encode(s){return config.raw?s:encodeURIComponent(s)}function decode(s){return config.raw?s:decodeURIComponent(s)}function stringifyCookieValue(value){return encode(config.json?JSON.stringify(value):String(value))}function parseCookieValue(s){if(s.indexOf('"')===0){s=s.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,'\\')}try{s=decodeURIComponent(s.replace(pluses,' '));return config.json?JSON.parse(s):s}catch(e){}}function read(s,converter){var value=config.raw?s:parseCookieValue(s);return $.isFunction(converter)?converter(value):value}var config=$.cookie=function(key,value,options){if(value!==undefined&&!$.isFunction(value)){options=$.extend({},config.defaults,options);if(typeof options.expires==='number'){var days=options.expires,t=options.expires=new Date();t.setTime(+t+days*864e+5)}return(document.cookie=[encode(key),'=',stringifyCookieValue(value),options.expires?'; expires='+options.expires.toUTCString():'',options.path?'; path='+options.path:'',options.domain?'; domain='+options.domain:'',options.secure?'; secure':''].join(''))}var result=key?undefined:{};var cookies=document.cookie?document.cookie.split('; '):[];for(var i=0,l=cookies.length;i<l;i++){var parts=cookies[i].split('=');var name=decode(parts.shift());var cookie=parts.join('=');if(key&&key===name){result=read(cookie,value);break}if(!key&&(cookie=read(cookie))!==undefined){result[name]=cookie}}return result};config.defaults={};$.removeCookie=function(key,options){if($.cookie(key)===undefined){return false}$.cookie(key,'',$.extend({},options,{expires:-1}));return!$.cookie(key)}}));

/* popup */
(function($){$.globalPopup=function(args){args=$.extend({},{used:true},args);if(!args.used){return false}var show=function(){$('body').append('<div id="popup-worldcup" class="global-popup">'+'<a href="http://bangbang.kul.vn/giai-dau/trang-chu.html" target="_blank">'+'<img src="http://st1.kul.vn/ads/BB_700x450.gif" alt="" width="600px"/>'+'</a>'+'<a href="javascript:;" id="global-popup-close">'+'Close'+'</a>'+'</div>'+'<div id="popup-worldcup-overlay" class="global-popup-overlay"></div>');$('#popup-worldcup-overlay, a#global-popup-close').click(function(){$('#popup-worldcup-overlay, #popup-worldcup').remove();$.cookie('global-popup-isclose',1);return false})};if(!$.cookie('global-popup-isclose')){show()}else{var num=$.cookie('global-popup-count');if(!num){num=1}if(!num||num%5==0){show();$.removeCookie('global-popup-isclose');$.removeCookie('global-popup-count')}else{$.cookie('global-popup-count',++num)}}}})(jQuery);
/* popup2 */
(function($){$.globalPopup2=function(args){args=$.extend({},{used:true},args);if(!args.used){return false}var show=function(){$('body').append('<div id="popup-worldcup" class="global-popup2">'+'<a href="http://goo.gl/BN4nqT" target="_blank">'+'<img src="http://st1.kul.vn/ads/fshare_300x100.gif" alt="" width="300px" />'+'</a>'+'<a href="javascript:;" id="global-popup-close2">'+'Close'+'</a>'+'</div>');$('a#global-popup-close2').click(function(){$('#popup-worldcup').remove();$.cookie('global-popup-isclose',1);return false})};if(!$.cookie('global-popup-isclose')){show()}else{var num=$.cookie('global-popup-count');if(!num){num=1}if(!num||num%5==0){show();$.removeCookie('global-popup-isclose');$.removeCookie('global-popup-count')}else{$.cookie('global-popup-count',++num)}}}})(jQuery);

/* jquery.mCustomScrollbar.concat.min */
(function(a){function d(b){var c=b||window.event,d=[].slice.call(arguments,1),e=0,f=!0,g=0,h=0;return b=a.event.fix(c),b.type="mousewheel",c.wheelDelta&&(e=c.wheelDelta/120),c.detail&&(e=-c.detail/3),h=e,c.axis!==undefined&&c.axis===c.HORIZONTAL_AXIS&&(h=0,g=-1*e),c.wheelDeltaY!==undefined&&(h=c.wheelDeltaY/120),c.wheelDeltaX!==undefined&&(g=-1*c.wheelDeltaX/120),d.unshift(b,e,g,h),(a.event.dispatch||a.event.handle).apply(this,d)}var b=["DOMMouseScroll","mousewheel"];if(a.event.fixHooks)for(var c=b.length;c;)a.event.fixHooks[b[--c]]=a.event.mouseHooks;a.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=b.length;a;)this.addEventListener(b[--a],d,!1);else this.onmousewheel=d},teardown:function(){if(this.removeEventListener)for(var a=b.length;a;)this.removeEventListener(b[--a],d,!1);else this.onmousewheel=null}},a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);
(function(c){var b={init:function(e){var f={set_width:false,set_height:false,horizontalScroll:false,scrollInertia:950,mouseWheel:true,mouseWheelPixels:"auto",autoDraggerLength:true,autoHideScrollbar:false,alwaysShowScrollbar:false,snapAmount:null,snapOffset:0,scrollButtons:{enable:false,scrollType:"continuous",scrollSpeed:"auto",scrollAmount:40},advanced:{updateOnBrowserResize:true,updateOnContentResize:false,autoExpandHorizontalScroll:false,autoScrollOnFocus:true,normalizeMouseWheelDelta:false},contentTouchScroll:true,callbacks:{onScrollStart:function(){},onScroll:function(){},onTotalScroll:function(){},onTotalScrollBack:function(){},onTotalScrollOffset:0,onTotalScrollBackOffset:0,whileScrolling:function(){}},theme:"light"},e=c.extend(true,f,e);return this.each(function(){var m=c(this);if(e.set_width){m.css("width",e.set_width)}if(e.set_height){m.css("height",e.set_height)}if(!c(document).data("mCustomScrollbar-index")){c(document).data("mCustomScrollbar-index","1")}else{var t=parseInt(c(document).data("mCustomScrollbar-index"));c(document).data("mCustomScrollbar-index",t+1)}m.wrapInner("<div class='mCustomScrollBox mCS-"+e.theme+"' id='mCSB_"+c(document).data("mCustomScrollbar-index")+"' style='position:relative; height:100%; overflow:hidden; max-width:100%;' />").addClass("mCustomScrollbar _mCS_"+c(document).data("mCustomScrollbar-index"));var g=m.children(".mCustomScrollBox");if(e.horizontalScroll){g.addClass("mCSB_horizontal").wrapInner("<div class='mCSB_h_wrapper' style='position:relative; left:0; width:999999px;' />");var k=g.children(".mCSB_h_wrapper");k.wrapInner("<div class='mCSB_container' style='position:absolute; left:0;' />").children(".mCSB_container").css({width:k.children().outerWidth(),position:"relative"}).unwrap()}else{g.wrapInner("<div class='mCSB_container' style='position:relative; top:0;' />")}var o=g.children(".mCSB_container");if(c.support.touch){o.addClass("mCS_touch")}o.after("<div class='mCSB_scrollTools' style='position:absolute;'><div class='mCSB_draggerContainer'><div class='mCSB_dragger' style='position:absolute;' oncontextmenu='return false;'><div class='mCSB_dragger_bar' style='position:relative;'></div></div><div class='mCSB_draggerRail'></div></div></div>");var l=g.children(".mCSB_scrollTools"),h=l.children(".mCSB_draggerContainer"),q=h.children(".mCSB_dragger");if(e.horizontalScroll){q.data("minDraggerWidth",q.width())}else{q.data("minDraggerHeight",q.height())}if(e.scrollButtons.enable){if(e.horizontalScroll){l.prepend("<a class='mCSB_buttonLeft' oncontextmenu='return false;'></a>").append("<a class='mCSB_buttonRight' oncontextmenu='return false;'></a>")}else{l.prepend("<a class='mCSB_buttonUp' oncontextmenu='return false;'></a>").append("<a class='mCSB_buttonDown' oncontextmenu='return false;'></a>")}}g.bind("scroll",function(){if(!m.is(".mCS_disabled")){g.scrollTop(0).scrollLeft(0)}});m.data({mCS_Init:true,mCustomScrollbarIndex:c(document).data("mCustomScrollbar-index"),horizontalScroll:e.horizontalScroll,scrollInertia:e.scrollInertia,scrollEasing:"mcsEaseOut",mouseWheel:e.mouseWheel,mouseWheelPixels:e.mouseWheelPixels,autoDraggerLength:e.autoDraggerLength,autoHideScrollbar:e.autoHideScrollbar,alwaysShowScrollbar:e.alwaysShowScrollbar,snapAmount:e.snapAmount,snapOffset:e.snapOffset,scrollButtons_enable:e.scrollButtons.enable,scrollButtons_scrollType:e.scrollButtons.scrollType,scrollButtons_scrollSpeed:e.scrollButtons.scrollSpeed,scrollButtons_scrollAmount:e.scrollButtons.scrollAmount,autoExpandHorizontalScroll:e.advanced.autoExpandHorizontalScroll,autoScrollOnFocus:e.advanced.autoScrollOnFocus,normalizeMouseWheelDelta:e.advanced.normalizeMouseWheelDelta,contentTouchScroll:e.contentTouchScroll,onScrollStart_Callback:e.callbacks.onScrollStart,onScroll_Callback:e.callbacks.onScroll,onTotalScroll_Callback:e.callbacks.onTotalScroll,onTotalScrollBack_Callback:e.callbacks.onTotalScrollBack,onTotalScroll_Offset:e.callbacks.onTotalScrollOffset,onTotalScrollBack_Offset:e.callbacks.onTotalScrollBackOffset,whileScrolling_Callback:e.callbacks.whileScrolling,bindEvent_scrollbar_drag:false,bindEvent_content_touch:false,bindEvent_scrollbar_click:false,bindEvent_mousewheel:false,bindEvent_buttonsContinuous_y:false,bindEvent_buttonsContinuous_x:false,bindEvent_buttonsPixels_y:false,bindEvent_buttonsPixels_x:false,bindEvent_focusin:false,bindEvent_autoHideScrollbar:false,mCSB_buttonScrollRight:false,mCSB_buttonScrollLeft:false,mCSB_buttonScrollDown:false,mCSB_buttonScrollUp:false});if(e.horizontalScroll){if(m.css("max-width")!=="none"){if(!e.advanced.updateOnContentResize){e.advanced.updateOnContentResize=true}}}else{if(m.css("max-height")!=="none"){var s=false,r=parseInt(m.css("max-height"));if(m.css("max-height").indexOf("%")>=0){s=r,r=m.parent().height()*s/100}m.css("overflow","hidden");g.css("max-height",r)}}m.mCustomScrollbar("update");if(e.advanced.updateOnBrowserResize){var i,j=c(window).width(),u=c(window).height();c(window).bind("resize."+m.data("mCustomScrollbarIndex"),function(){if(i){clearTimeout(i)}i=setTimeout(function(){if(!m.is(".mCS_disabled")&&!m.is(".mCS_destroyed")){var w=c(window).width(),v=c(window).height();if(j!==w||u!==v){if(m.css("max-height")!=="none"&&s){g.css("max-height",m.parent().height()*s/100)}m.mCustomScrollbar("update");j=w;u=v}}},150)})}if(e.advanced.updateOnContentResize){var p;if(e.horizontalScroll){var n=o.outerWidth()}else{var n=o.outerHeight()}p=setInterval(function(){if(e.horizontalScroll){if(e.advanced.autoExpandHorizontalScroll){o.css({position:"absolute",width:"auto"}).wrap("<div class='mCSB_h_wrapper' style='position:relative; left:0; width:999999px;' />").css({width:o.outerWidth(),position:"relative"}).unwrap()}var v=o.outerWidth()}else{var v=o.outerHeight()}if(v!=n){m.mCustomScrollbar("update");n=v}},300)}})},update:function(){var n=c(this),k=n.children(".mCustomScrollBox"),q=k.children(".mCSB_container");q.removeClass("mCS_no_scrollbar");n.removeClass("mCS_disabled mCS_destroyed");k.scrollTop(0).scrollLeft(0);var y=k.children(".mCSB_scrollTools"),o=y.children(".mCSB_draggerContainer"),m=o.children(".mCSB_dragger");if(n.data("horizontalScroll")){var A=y.children(".mCSB_buttonLeft"),t=y.children(".mCSB_buttonRight"),f=k.width();if(n.data("autoExpandHorizontalScroll")){q.css({position:"absolute",width:"auto"}).wrap("<div class='mCSB_h_wrapper' style='position:relative; left:0; width:999999px;' />").css({width:q.outerWidth(),position:"relative"}).unwrap()}var z=q.outerWidth()}else{var w=y.children(".mCSB_buttonUp"),g=y.children(".mCSB_buttonDown"),r=k.height(),i=q.outerHeight()}if(i>r&&!n.data("horizontalScroll")){y.css("display","block");var s=o.height();if(n.data("autoDraggerLength")){var u=Math.round(r/i*s),l=m.data("minDraggerHeight");if(u<=l){m.css({height:l})}else{if(u>=s-10){var p=s-10;m.css({height:p})}else{m.css({height:u})}}m.children(".mCSB_dragger_bar").css({"line-height":m.height()+"px"})}var B=m.height(),x=(i-r)/(s-B);n.data("scrollAmount",x).mCustomScrollbar("scrolling",k,q,o,m,w,g,A,t);var D=Math.abs(q.position().top);n.mCustomScrollbar("scrollTo",D,{scrollInertia:0,trigger:"internal"})}else{if(z>f&&n.data("horizontalScroll")){y.css("display","block");var h=o.width();if(n.data("autoDraggerLength")){var j=Math.round(f/z*h),C=m.data("minDraggerWidth");if(j<=C){m.css({width:C})}else{if(j>=h-10){var e=h-10;m.css({width:e})}else{m.css({width:j})}}}var v=m.width(),x=(z-f)/(h-v);n.data("scrollAmount",x).mCustomScrollbar("scrolling",k,q,o,m,w,g,A,t);var D=Math.abs(q.position().left);n.mCustomScrollbar("scrollTo",D,{scrollInertia:0,trigger:"internal"})}else{k.unbind("mousewheel focusin");if(n.data("horizontalScroll")){m.add(q).css("left",0)}else{m.add(q).css("top",0)}if(n.data("alwaysShowScrollbar")){if(!n.data("horizontalScroll")){m.css({height:o.height()})}else{if(n.data("horizontalScroll")){m.css({width:o.width()})}}}else{y.css("display","none");q.addClass("mCS_no_scrollbar")}n.data({bindEvent_mousewheel:false,bindEvent_focusin:false})}}},scrolling:function(i,q,n,k,A,f,D,w){var l=c(this);if(!l.data("bindEvent_scrollbar_drag")){var o,p,C,z,e;if(c.support.pointer){C="pointerdown";z="pointermove";e="pointerup"}else{if(c.support.msPointer){C="MSPointerDown";z="MSPointerMove";e="MSPointerUp"}}if(c.support.pointer||c.support.msPointer){k.bind(C,function(K){K.preventDefault();l.data({on_drag:true});k.addClass("mCSB_dragger_onDrag");var J=c(this),M=J.offset(),I=K.originalEvent.pageX-M.left,L=K.originalEvent.pageY-M.top;if(I<J.width()&&I>0&&L<J.height()&&L>0){o=L;p=I}});c(document).bind(z+"."+l.data("mCustomScrollbarIndex"),function(K){K.preventDefault();if(l.data("on_drag")){var J=k,M=J.offset(),I=K.originalEvent.pageX-M.left,L=K.originalEvent.pageY-M.top;G(o,p,L,I)}}).bind(e+"."+l.data("mCustomScrollbarIndex"),function(x){l.data({on_drag:false});k.removeClass("mCSB_dragger_onDrag")})}else{k.bind("mousedown touchstart",function(K){K.preventDefault();K.stopImmediatePropagation();var J=c(this),N=J.offset(),I,M;if(K.type==="touchstart"){var L=K.originalEvent.touches[0]||K.originalEvent.changedTouches[0];I=L.pageX-N.left;M=L.pageY-N.top}else{l.data({on_drag:true});k.addClass("mCSB_dragger_onDrag");I=K.pageX-N.left;M=K.pageY-N.top}if(I<J.width()&&I>0&&M<J.height()&&M>0){o=M;p=I}}).bind("touchmove",function(K){K.preventDefault();K.stopImmediatePropagation();var N=K.originalEvent.touches[0]||K.originalEvent.changedTouches[0],J=c(this),M=J.offset(),I=N.pageX-M.left,L=N.pageY-M.top;G(o,p,L,I)});c(document).bind("mousemove."+l.data("mCustomScrollbarIndex"),function(K){if(l.data("on_drag")){var J=k,M=J.offset(),I=K.pageX-M.left,L=K.pageY-M.top;G(o,p,L,I)}}).bind("mouseup."+l.data("mCustomScrollbarIndex"),function(x){l.data({on_drag:false});k.removeClass("mCSB_dragger_onDrag")})}l.data({bindEvent_scrollbar_drag:true})}function G(J,K,L,I){if(l.data("horizontalScroll")){l.mCustomScrollbar("scrollTo",(k.position().left-(K))+I,{moveDragger:true,trigger:"internal"})}else{l.mCustomScrollbar("scrollTo",(k.position().top-(J))+L,{moveDragger:true,trigger:"internal"})}}if(c.support.touch&&l.data("contentTouchScroll")){if(!l.data("bindEvent_content_touch")){var m,E,s,t,v,F,H;q.bind("touchstart",function(x){x.stopImmediatePropagation();m=x.originalEvent.touches[0]||x.originalEvent.changedTouches[0];E=c(this);s=E.offset();v=m.pageX-s.left;t=m.pageY-s.top;F=t;H=v});q.bind("touchmove",function(x){x.preventDefault();x.stopImmediatePropagation();m=x.originalEvent.touches[0]||x.originalEvent.changedTouches[0];E=c(this).parent();s=E.offset();v=m.pageX-s.left;t=m.pageY-s.top;if(l.data("horizontalScroll")){l.mCustomScrollbar("scrollTo",H-v,{trigger:"internal"})}else{l.mCustomScrollbar("scrollTo",F-t,{trigger:"internal"})}})}}if(!l.data("bindEvent_scrollbar_click")){n.bind("click",function(I){var x=(I.pageY-n.offset().top)*l.data("scrollAmount"),y=c(I.target);if(l.data("horizontalScroll")){x=(I.pageX-n.offset().left)*l.data("scrollAmount")}if(y.hasClass("mCSB_draggerContainer")||y.hasClass("mCSB_draggerRail")){l.mCustomScrollbar("scrollTo",x,{trigger:"internal",scrollEasing:"draggerRailEase"})}});l.data({bindEvent_scrollbar_click:true})}if(l.data("mouseWheel")){if(!l.data("bindEvent_mousewheel")){i.bind("mousewheel",function(K,M){var J,I=l.data("mouseWheelPixels"),x=Math.abs(q.position().top),L=k.position().top,y=n.height()-k.height();if(l.data("normalizeMouseWheelDelta")){if(M<0){M=-1}else{M=1}}if(I==="auto"){I=100+Math.round(l.data("scrollAmount")/2)}if(l.data("horizontalScroll")){L=k.position().left;y=n.width()-k.width();x=Math.abs(q.position().left)}if((M>0&&L!==0)||(M<0&&L!==y)){K.preventDefault();K.stopImmediatePropagation()}J=x-(M*I);l.mCustomScrollbar("scrollTo",J,{trigger:"internal"})});l.data({bindEvent_mousewheel:true})}}if(l.data("scrollButtons_enable")){if(l.data("scrollButtons_scrollType")==="pixels"){if(l.data("horizontalScroll")){w.add(D).unbind("mousedown touchstart MSPointerDown pointerdown mouseup MSPointerUp pointerup mouseout MSPointerOut pointerout touchend",j,h);l.data({bindEvent_buttonsContinuous_x:false});if(!l.data("bindEvent_buttonsPixels_x")){w.bind("click",function(x){x.preventDefault();r(Math.abs(q.position().left)+l.data("scrollButtons_scrollAmount"))});D.bind("click",function(x){x.preventDefault();r(Math.abs(q.position().left)-l.data("scrollButtons_scrollAmount"))});l.data({bindEvent_buttonsPixels_x:true})}}else{f.add(A).unbind("mousedown touchstart MSPointerDown pointerdown mouseup MSPointerUp pointerup mouseout MSPointerOut pointerout touchend",j,h);l.data({bindEvent_buttonsContinuous_y:false});if(!l.data("bindEvent_buttonsPixels_y")){f.bind("click",function(x){x.preventDefault();r(Math.abs(q.position().top)+l.data("scrollButtons_scrollAmount"))});A.bind("click",function(x){x.preventDefault();r(Math.abs(q.position().top)-l.data("scrollButtons_scrollAmount"))});l.data({bindEvent_buttonsPixels_y:true})}}function r(x){if(!k.data("preventAction")){k.data("preventAction",true);l.mCustomScrollbar("scrollTo",x,{trigger:"internal"})}}}else{if(l.data("horizontalScroll")){w.add(D).unbind("click");l.data({bindEvent_buttonsPixels_x:false});if(!l.data("bindEvent_buttonsContinuous_x")){w.bind("mousedown touchstart MSPointerDown pointerdown",function(y){y.preventDefault();var x=B();l.data({mCSB_buttonScrollRight:setInterval(function(){l.mCustomScrollbar("scrollTo",Math.abs(q.position().left)+x,{trigger:"internal",scrollEasing:"easeOutCirc"})},17)})});var j=function(x){x.preventDefault();clearInterval(l.data("mCSB_buttonScrollRight"))};w.bind("mouseup touchend MSPointerUp pointerup mouseout MSPointerOut pointerout",j);D.bind("mousedown touchstart MSPointerDown pointerdown",function(y){y.preventDefault();var x=B();l.data({mCSB_buttonScrollLeft:setInterval(function(){l.mCustomScrollbar("scrollTo",Math.abs(q.position().left)-x,{trigger:"internal",scrollEasing:"easeOutCirc"})},17)})});var h=function(x){x.preventDefault();clearInterval(l.data("mCSB_buttonScrollLeft"))};D.bind("mouseup touchend MSPointerUp pointerup mouseout MSPointerOut pointerout",h);l.data({bindEvent_buttonsContinuous_x:true})}}else{f.add(A).unbind("click");l.data({bindEvent_buttonsPixels_y:false});if(!l.data("bindEvent_buttonsContinuous_y")){f.bind("mousedown touchstart MSPointerDown pointerdown",function(y){y.preventDefault();var x=B();l.data({mCSB_buttonScrollDown:setInterval(function(){l.mCustomScrollbar("scrollTo",Math.abs(q.position().top)+x,{trigger:"internal",scrollEasing:"easeOutCirc"})},17)})});var u=function(x){x.preventDefault();clearInterval(l.data("mCSB_buttonScrollDown"))};f.bind("mouseup touchend MSPointerUp pointerup mouseout MSPointerOut pointerout",u);A.bind("mousedown touchstart MSPointerDown pointerdown",function(y){y.preventDefault();var x=B();l.data({mCSB_buttonScrollUp:setInterval(function(){l.mCustomScrollbar("scrollTo",Math.abs(q.position().top)-x,{trigger:"internal",scrollEasing:"easeOutCirc"})},17)})});var g=function(x){x.preventDefault();clearInterval(l.data("mCSB_buttonScrollUp"))};A.bind("mouseup touchend MSPointerUp pointerup mouseout MSPointerOut pointerout",g);l.data({bindEvent_buttonsContinuous_y:true})}}function B(){var x=l.data("scrollButtons_scrollSpeed");if(l.data("scrollButtons_scrollSpeed")==="auto"){x=Math.round((l.data("scrollInertia")+100)/40)}return x}}}if(l.data("autoScrollOnFocus")){if(!l.data("bindEvent_focusin")){i.bind("focusin",function(){i.scrollTop(0).scrollLeft(0);var x=c(document.activeElement);if(x.is("input,textarea,select,button,a[tabindex],area,object")){var J=q.position().top,y=x.position().top,I=i.height()-x.outerHeight();if(l.data("horizontalScroll")){J=q.position().left;y=x.position().left;I=i.width()-x.outerWidth()}if(J+y<0||J+y>I){l.mCustomScrollbar("scrollTo",y,{trigger:"internal"})}}});l.data({bindEvent_focusin:true})}}if(l.data("autoHideScrollbar")&&!l.data("alwaysShowScrollbar")){if(!l.data("bindEvent_autoHideScrollbar")){i.bind("mouseenter",function(x){i.addClass("mCS-mouse-over");d.showScrollbar.call(i.children(".mCSB_scrollTools"))}).bind("mouseleave touchend",function(x){i.removeClass("mCS-mouse-over");if(x.type==="mouseleave"){d.hideScrollbar.call(i.children(".mCSB_scrollTools"))}});l.data({bindEvent_autoHideScrollbar:true})}}},scrollTo:function(e,f){var i=c(this),o={moveDragger:false,trigger:"external",callbacks:true,scrollInertia:i.data("scrollInertia"),scrollEasing:i.data("scrollEasing")},f=c.extend(o,f),p,g=i.children(".mCustomScrollBox"),k=g.children(".mCSB_container"),r=g.children(".mCSB_scrollTools"),j=r.children(".mCSB_draggerContainer"),h=j.children(".mCSB_dragger"),t=draggerSpeed=f.scrollInertia,q,s,m,l;if(!k.hasClass("mCS_no_scrollbar")){i.data({mCS_trigger:f.trigger});if(i.data("mCS_Init")){f.callbacks=false}if(e||e===0){if(typeof(e)==="number"){if(f.moveDragger){p=e;if(i.data("horizontalScroll")){e=h.position().left*i.data("scrollAmount")}else{e=h.position().top*i.data("scrollAmount")}draggerSpeed=0}else{p=e/i.data("scrollAmount")}}else{if(typeof(e)==="string"){var v;if(e==="top"){v=0}else{if(e==="bottom"&&!i.data("horizontalScroll")){v=k.outerHeight()-g.height()}else{if(e==="left"){v=0}else{if(e==="right"&&i.data("horizontalScroll")){v=k.outerWidth()-g.width()}else{if(e==="first"){v=i.find(".mCSB_container").find(":first")}else{if(e==="last"){v=i.find(".mCSB_container").find(":last")}else{v=i.find(e)}}}}}}if(v.length===1){if(i.data("horizontalScroll")){e=v.position().left}else{e=v.position().top}p=e/i.data("scrollAmount")}else{p=e=v}}}if(i.data("horizontalScroll")){if(i.data("onTotalScrollBack_Offset")){s=-i.data("onTotalScrollBack_Offset")}if(i.data("onTotalScroll_Offset")){l=g.width()-k.outerWidth()+i.data("onTotalScroll_Offset")}if(p<0){p=e=0;clearInterval(i.data("mCSB_buttonScrollLeft"));if(!s){q=true}}else{if(p>=j.width()-h.width()){p=j.width()-h.width();e=g.width()-k.outerWidth();clearInterval(i.data("mCSB_buttonScrollRight"));if(!l){m=true}}else{e=-e}}var n=i.data("snapAmount");if(n){e=Math.round(e/n)*n-i.data("snapOffset")}d.mTweenAxis.call(this,h[0],"left",Math.round(p),draggerSpeed,f.scrollEasing);d.mTweenAxis.call(this,k[0],"left",Math.round(e),t,f.scrollEasing,{onStart:function(){if(f.callbacks&&!i.data("mCS_tweenRunning")){u("onScrollStart")}if(i.data("autoHideScrollbar")&&!i.data("alwaysShowScrollbar")){d.showScrollbar.call(r)}},onUpdate:function(){if(f.callbacks){u("whileScrolling")}},onComplete:function(){if(f.callbacks){u("onScroll");if(q||(s&&k.position().left>=s)){u("onTotalScrollBack")}if(m||(l&&k.position().left<=l)){u("onTotalScroll")}}h.data("preventAction",false);i.data("mCS_tweenRunning",false);if(i.data("autoHideScrollbar")&&!i.data("alwaysShowScrollbar")){if(!g.hasClass("mCS-mouse-over")){d.hideScrollbar.call(r)}}}})}else{if(i.data("onTotalScrollBack_Offset")){s=-i.data("onTotalScrollBack_Offset")}if(i.data("onTotalScroll_Offset")){l=g.height()-k.outerHeight()+i.data("onTotalScroll_Offset")}if(p<0){p=e=0;clearInterval(i.data("mCSB_buttonScrollUp"));if(!s){q=true}}else{if(p>=j.height()-h.height()){p=j.height()-h.height();e=g.height()-k.outerHeight();clearInterval(i.data("mCSB_buttonScrollDown"));if(!l){m=true}}else{e=-e}}var n=i.data("snapAmount");if(n){e=Math.round(e/n)*n-i.data("snapOffset")}d.mTweenAxis.call(this,h[0],"top",Math.round(p),draggerSpeed,f.scrollEasing);d.mTweenAxis.call(this,k[0],"top",Math.round(e),t,f.scrollEasing,{onStart:function(){if(f.callbacks&&!i.data("mCS_tweenRunning")){u("onScrollStart")}if(i.data("autoHideScrollbar")&&!i.data("alwaysShowScrollbar")){d.showScrollbar.call(r)}},onUpdate:function(){if(f.callbacks){u("whileScrolling")}},onComplete:function(){if(f.callbacks){u("onScroll");if(q||(s&&k.position().top>=s)){u("onTotalScrollBack")}if(m||(l&&k.position().top<=l)){u("onTotalScroll")}}h.data("preventAction",false);i.data("mCS_tweenRunning",false);if(i.data("autoHideScrollbar")&&!i.data("alwaysShowScrollbar")){if(!g.hasClass("mCS-mouse-over")){d.hideScrollbar.call(r)}}}})}if(i.data("mCS_Init")){i.data({mCS_Init:false})}}}function u(w){if(i.data("mCustomScrollbarIndex")){this.mcs={top:k.position().top,left:k.position().left,draggerTop:h.position().top,draggerLeft:h.position().left,topPct:Math.round((100*Math.abs(k.position().top))/Math.abs(k.outerHeight()-g.height())),leftPct:Math.round((100*Math.abs(k.position().left))/Math.abs(k.outerWidth()-g.width()))};switch(w){case"onScrollStart":i.data("mCS_tweenRunning",true).data("onScrollStart_Callback").call(i,this.mcs);break;case"whileScrolling":i.data("whileScrolling_Callback").call(i,this.mcs);break;case"onScroll":i.data("onScroll_Callback").call(i,this.mcs);break;case"onTotalScrollBack":i.data("onTotalScrollBack_Callback").call(i,this.mcs);break;case"onTotalScroll":i.data("onTotalScroll_Callback").call(i,this.mcs);break}}}},stop:function(){var g=c(this),e=g.children().children(".mCSB_container"),f=g.children().children().children().children(".mCSB_dragger");d.mTweenAxisStop.call(this,e[0]);d.mTweenAxisStop.call(this,f[0])},disable:function(e){var j=c(this),f=j.children(".mCustomScrollBox"),h=f.children(".mCSB_container"),g=f.children(".mCSB_scrollTools"),i=g.children().children(".mCSB_dragger");f.unbind("mousewheel focusin mouseenter mouseleave touchend");h.unbind("touchstart touchmove");if(e){if(j.data("horizontalScroll")){i.add(h).css("left",0)}else{i.add(h).css("top",0)}}g.css("display","none");h.addClass("mCS_no_scrollbar");j.data({bindEvent_mousewheel:false,bindEvent_focusin:false,bindEvent_content_touch:false,bindEvent_autoHideScrollbar:false}).addClass("mCS_disabled")},destroy:function(){var e=c(this);e.removeClass("mCustomScrollbar _mCS_"+e.data("mCustomScrollbarIndex")).addClass("mCS_destroyed").children().children(".mCSB_container").unwrap().children().unwrap().siblings(".mCSB_scrollTools").remove();c(document).unbind("mousemove."+e.data("mCustomScrollbarIndex")+" mouseup."+e.data("mCustomScrollbarIndex")+" MSPointerMove."+e.data("mCustomScrollbarIndex")+" MSPointerUp."+e.data("mCustomScrollbarIndex"));c(window).unbind("resize."+e.data("mCustomScrollbarIndex"))}},d={showScrollbar:function(){this.stop().animate({opacity:1},"fast")},hideScrollbar:function(){this.stop().animate({opacity:0},"fast")},mTweenAxis:function(g,i,h,f,o,y){var y=y||{},v=y.onStart||function(){},p=y.onUpdate||function(){},w=y.onComplete||function(){};var n=t(),l,j=0,r=g.offsetTop,s=g.style;if(i==="left"){r=g.offsetLeft}var m=h-r;q();e();function t(){if(window.performance&&window.performance.now){return window.performance.now()}else{if(window.performance&&window.performance.webkitNow){return window.performance.webkitNow()}else{if(Date.now){return Date.now()}else{return new Date().getTime()}}}}function x(){if(!j){v.call()}j=t()-n;u();if(j>=g._time){g._time=(j>g._time)?j+l-(j-g._time):j+l-1;if(g._time<j+1){g._time=j+1}}if(g._time<f){g._id=_request(x)}else{w.call()}}function u(){if(f>0){g.currVal=k(g._time,r,m,f,o);s[i]=Math.round(g.currVal)+"px"}else{s[i]=h+"px"}p.call()}function e(){l=1000/60;g._time=j+l;_request=(!window.requestAnimationFrame)?function(z){u();return setTimeout(z,0.01)}:window.requestAnimationFrame;g._id=_request(x)}function q(){if(g._id==null){return}if(!window.requestAnimationFrame){clearTimeout(g._id)}else{window.cancelAnimationFrame(g._id)}g._id=null}function k(B,A,F,E,C){switch(C){case"linear":return F*B/E+A;break;case"easeOutQuad":B/=E;return -F*B*(B-2)+A;break;case"easeInOutQuad":B/=E/2;if(B<1){return F/2*B*B+A}B--;return -F/2*(B*(B-2)-1)+A;break;case"easeOutCubic":B/=E;B--;return F*(B*B*B+1)+A;break;case"easeOutQuart":B/=E;B--;return -F*(B*B*B*B-1)+A;break;case"easeOutQuint":B/=E;B--;return F*(B*B*B*B*B+1)+A;break;case"easeOutCirc":B/=E;B--;return F*Math.sqrt(1-B*B)+A;break;case"easeOutSine":return F*Math.sin(B/E*(Math.PI/2))+A;break;case"easeOutExpo":return F*(-Math.pow(2,-10*B/E)+1)+A;break;case"mcsEaseOut":var D=(B/=E)*B,z=D*B;return A+F*(0.499999999999997*z*D+-2.5*D*D+5.5*z+-6.5*D+4*B);break;case"draggerRailEase":B/=E/2;if(B<1){return F/2*B*B*B+A}B-=2;return F/2*(B*B*B+2)+A;break}}},mTweenAxisStop:function(e){if(e._id==null){return}if(!window.requestAnimationFrame){clearTimeout(e._id)}else{window.cancelAnimationFrame(e._id)}e._id=null},rafPolyfill:function(){var f=["ms","moz","webkit","o"],e=f.length;while(--e>-1&&!window.requestAnimationFrame){window.requestAnimationFrame=window[f[e]+"RequestAnimationFrame"];window.cancelAnimationFrame=window[f[e]+"CancelAnimationFrame"]||window[f[e]+"CancelRequestAnimationFrame"]}}};d.rafPolyfill.call();c.support.touch=!!("ontouchstart" in window);c.support.pointer=window.navigator.pointerEnabled;c.support.msPointer=window.navigator.msPointerEnabled;var a=("https:"==document.location.protocol)?"https:":"http:";c.event.special.mousewheel||document.write('<script src="'+a+'//cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.0.6/jquery.mousewheel.min.js"><\/script>');c.fn.mCustomScrollbar=function(e){if(b[e]){return b[e].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof e==="object"||!e){return b.init.apply(this,arguments)}else{c.error("Method "+e+" does not exist")}}}})(jQuery);