function unableScroll() {
	var top = jQuery(document).scrollTop();
	jQuery(document).on('scroll.unable',function (e) {
		jQuery(document).scrollTop(top);
	})
}
function enableScroll() {
	jQuery(document).unbind("scroll.unable");
}
/**/
var wow = new WOW({
    offset: 50,
    mobile: true,
    live: true,
    animateClass: 'animate__animated', 
});
wow.init();

$(function(){	
	/*search*/	
	var search = $('#search');    
	search.children('span').click(function(){
					$(this).toggleClass("on");
					$(this).siblings('.input').stop().slideToggle();
			
	});
	/*navi*/
	var navi = $('#navi');
	var navli = navi.find('li');
    var navbtn = $('#navbtn');
    
    if(typeof navID !='undefined' && $('#navi'+navID).length > 0){
        $('#navi'+navID).addClass('cur');
    }
	navli.each(function(){
		if($(this).find('.sub a').length > 0){
			$(this).prepend('<em></em>');
		}
	});
	navli.find('em').click(function(){
		$(this).siblings('.sub').stop().slideToggle('fast').parent().toggleClass('on').siblings().removeClass('on').children('.sub').stop().slideUp('fast');
	});
    navbtn.click(function(){
    // search.find('.input').hide();     
		if($(this).hasClass('active')){
			enableScroll();
            $(this).removeClass('active');
			navi.removeClass('active');
			navi.stop().fadeOut('fast');
		}else{
			unableScroll();
            $(this).addClass('active');
			navi.stop().fadeIn('fast');
			navi.addClass('active');
		}
	});
	$(window).resize(function(){
		if($(this).width() > 1024){
			enableScroll();			
			/*navi*/
			navi.removeAttr('style');
			navli.on('mouseenter mouseleave');
			navli.mouseenter(function(){
                // search.find('.input').hide();
				$(this).addClass('on');
				if($(this).find('.sub a').length > 0){
					$(this).children('.sub').stop().slideDown('fast');
				}
			}).mouseleave(function(){
				$(this).removeClass('on');
				if($(this).find('.sub a').length > 0){
					$(this).children('.sub').stop().slideUp('fast');
				}
			});
		}else{			
			/*navi*/
			navli.off('mouseenter mouseleave');
		} 
	}).trigger('resize');
    /*popup*/
    var _popuphtml = '<div class="popup vpopup"><div class="video"></div></div>';
    $('a[data="vplay"]').click(function(e){
        e.preventDefault();
        var _videourl = $(this).attr('href');       
        var _videohtml = '<video src="'+_videourl+'" webkit-playsinline="true" playsinline="true" x5-video-player-type="h5" x5-video-player-fullscreen="true" x-webkit-airplay="allow" x5-video-orientation="portraint" controls autoplay></video>';
        var _vpopup = $('.vpopup');
        if(_vpopup.length == 0){
            $('body').append(_popuphtml);
            var _vpopup = $('.vpopup');
        }
        _vpopup.find('.video').html(_videohtml);
        _vpopup.stop().fadeIn('fast',function(){
            $(this).find('video').trigger('play');
        });
        _vpopup.click(function(e){
            if($(e.target).closest($(this).find('video')).length === 0){
            	$(this).find('video').trigger('pause');
                $(this).stop().fadeOut(50,function(){
                	$(this).remove();
                });
            }
        });
    });
});