/* update on 17/04/2018 */
function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
$(function () {
    var scrollTop = 0;
    var header = $('.pageheader');
    var pagejump = $('.pagejump');
    var mobilemenu = $('.link_mobilemenu');
    var videoclick = $('#videoclick');
    var homevideoclose = $('.videoclose');
    var headerheight = header.height();
    var readourstory = $('.btn_readourstory');
    var btndinemorelearn = $('.btn_dinemore_learn');
    var windowwidth = $(window).width();   
    var windowheight = $(window).height();
    $.jStorage.set('mobile_card_open',0);
    
    var pageclick = function (e) {
        // new
        var datatarget = $(this).attr('data-target');
       
        // new
        if (datatarget) {
            if($('.dropdown_mobile').hasClass('active')){
                mobilemenu.toggleClass('active');
                $('.dropdown_mobile').toggleClass('active');
            }
            if(App.mobileDevice()){
                $('body').removeClass('modalblackbg a_modal_open');
            }
            $.jStorage.set('mobile_card_open',0);
            if (datatarget && $(window).width() < 992 ) {
                var datatargetupdated = datatarget.replace(/\s+/g, '_');
                var pagepos = $('#' + datatargetupdated).offset().top-55;
                if($(e.currentTarget).hasClass('active')){
                    if($('.dropdown_mobile').hasClass('active')){
                        mobilemenu.toggleClass('active');
                        $('.dropdown_mobile').toggleClass('active');
                    }
                    $('html, body').stop().animate({scrollTop: pagepos}, "slow");
                    if(datatarget === 'home'){
                        $('html, body').stop().animate({scrollTop: 0}, "slow");
                    }
                    return false;
                }
            }
            
            
            var datatargetupdated = datatarget.replace(/\s+/g, '_');
            var pagepos = $('#' + datatargetupdated).offset().top-55;
            //update accordinally 
           // var pagepos = $('#' + datatargetupdated).offset().top;
            
            if(windowwidth < 767){
                pagejump.removeClass("active");
                $('.checkoutDiv').addClass('hide');
                App.menupanel();
                App.renderMap();
                setTimeout(function(){
                   pagepos = $('#' + datatargetupdated).offset().top-55 ;
                   //update accordinally 
                   //pagepos = $('#' + datatargetupdated).offset().top ;
                    if(datatarget === 'home'){
                        $('html, body').stop().animate({scrollTop: 0}, "slow");
                    }else{
                        $('html, body').stop().animate({scrollTop: pagepos}, "slow");
                    }

                },300);
            }else{
                if(datatarget === 'home'){
                    $('html, body').stop().animate({scrollTop: 0}, "slow");
                }else{
                    $('html, body').stop().animate({scrollTop: pagepos}, "slow");
                }
            }            
            if(windowwidth < 991){               
                mobilemenu.removeClass('active');
                $('.dropdown_mobile').removeClass('active');
            }
            var datagtm = $(this).attr('data-gtmd');
            var ev_action = datagtm+" Click" ;
            var ev_leble = "Click_on_"+datagtm+"_in_Top_Menu" ;
            dataLayer.push({
                'event': ev_action,
                'restname': App.currentRestaurant.name,
                'ev_label': ev_leble,
                'RestaurantID':restId
            });
            //ga('send', 'event', 'Top Menu Bar '+ App.currentRestaurant.name, ev_action , ev_leble, 1, true);
           
        }

    };

    var globalscroll = function () {
        scrollTop = $(window).scrollTop();
        // if (headerheight < scrollTop) {
        var txtHeight = $(".txt_homepage").offset().top;
        if (txtHeight < (scrollTop + 165)) {
            header.addClass('smallheight');
        } else {
            header.removeClass('smallheight');
        }
        if($('.dropdown_mobile').hasClass('active')){
            mobilemenu.toggleClass('active');
            $('.dropdown_mobile').toggleClass('active');
        }
        if($(window).width() > 992){
            if($('#menu').hasClass('active')){
                if($('.navbarcontainer').offset().top < $(window).scrollTop() + 90){
                    $('.navbarcontainer').addClass('active');
                }else{
                    $('.navbarcontainer').removeClass('active');
                }
            }else{
                $('.navbarcontainer').removeClass('active');
            }
        }
        pagejump.removeClass("active");
        pagejump.each(function () {            
            var currLink = $(this);
            var pageelement = $('#' + currLink.attr('data-target'));
           
            if (pageelement.length){
                if (pageelement.position().top - 60 <= scrollTop && pageelement.position().top + pageelement.height() - 100 > scrollTop) {
                    if($.jStorage.get('mobile_card_open')){
                        $('.pagejump').removeClass('active');
                        $('.y-go-to-menu').addClass('active');
                    }else{
                        currLink.addClass("active");
                        pageelement.addClass("active");
                        window.location.hash = '#!' + currLink.attr('data-target'); 
                    }
                    
                } else {
                    currLink.removeClass("active");
                    pageelement.removeClass("active");
                }
            }
        });

    };
    var mobilemenuClick = function(){
        mobilemenu.toggleClass('active');
        $('.dropdown_mobile').toggleClass('active');
        $('body').removeClass('a_modal_open');
        if($.jStorage.get('mobile_card_open')){
            $('.pagejump').removeClass('active');
            $('.y-go-to-menu').addClass('active');
        }
        
    };
    var homevideoclick = function(){
        vimeoVideoid = $('#videoclick').attr('video-url');
        var vimeoVideoUrl = '//player.vimeo.com/video/' + vimeoVideoid;
        var match = /vimeo.*\/(\d+)/i.exec(vimeoVideoUrl);
        /*if (match) {
            var vimeoVideoID = match[1];
            $.getJSON('//www.vimeo.com/api/v2/video/' + vimeoVideoID + '.json?callback=?', { format: "json" }, function (data) {
                featuredImg = data[0].thumbnail_large;
                $('.videoiframe').css('background-image', 'url('+featuredImg+')');
            });
        }*/
        $('.videoiframe').attr('src' , vimeoVideoUrl + '?title=0&byline=0&portrait=0&autoplay=1');
        $('.modalwatchvideo').removeClass('hide');
        $('body').addClass('a_modal_open');
        dataLayer.push({
            'event':'Watch Video',
            'restname': App.currentRestaurant.name,
            'ev_label': 'Click_on_Watch_Video_Button',
            'RestaurantID':restId
        });
        //ga('send', 'event', 'Video', "Watch Video" , "Click_on_Watch_Video_Button", 1, true);
         if (/iPad|iPhone|iPod/i.test(navigator.userAgent)) {
            $('body').attr('st' , $(window).scrollTop()).css({'position': 'fixed','width': '100%'});
         };
    };
    var homevideocloseclick = function(){
        $('.videoiframe').attr('src' , '');
        $('.videoiframe').css('background-image', '');
        $('.modalwatchvideo').addClass('hide');
        $('body').removeClass('a_modal_open');

        if (/iPad|iPhone|iPod/i.test(navigator.userAgent)) {
            $('body').removeAttr('style');
            $(window).scrollTop($('body').attr('st'));
            setTimeout(function(){
                $('body').removeAttr('st');       
            }, 100);
        };
    };
    var readstory = function(){
        $(this).toggleClass('active');
        $('.storysection').toggleClass('hide');
        if($(this).hasClass('active')){
            $('html, body').animate({scrollTop:$('.storysection').offset().top - 125}, "slow");
            $(this).hide();
        }
        dataLayer.push({
            'event':'Read our story',
            'restname': App.currentRestaurant.name,
            'ev_label': 'Click_on_Read_our_Story_Button',
            'RestaurantID':restId
        });
        //ga('send', 'event', 'About', "Read our story" , "Click_on_Read_our_Story_Button", 1, true);
    };
    var dinemorelearn = function(){
        dataLayer.push({
            'event':'Learn More',
            'restname': App.currentRestaurant.name,
            'ev_label': 'Click_on_learn_more_Button',
            'RestaurantID': restId
        });
        //ga('send', 'event', 'Dine&More '+App.currentRestaurant.name, "Learn More" , "Click_on_learn_more_Button", 1, true);        
        $(this).toggleClass('active');
        $('.panel_dinein_benefit').toggleClass('hide');
        if($(this).hasClass('active')){
            $('.panel_dinemore_learn').hide();
            $('html, body').animate({scrollTop:$('.panel_dinein_benefit').offset().top-75}, "slow");
        }
    };
    videoclick.click(homevideoclick);
    homevideoclose.click(homevideocloseclick);
    mobilemenu.click(mobilemenuClick);
    pagejump.click(pageclick);
    readourstory.click(readstory);
    btndinemorelearn.click(dinemorelearn);
    
    if(windowwidth < 500){
        $('.homebgblack, .home').css('min-height', windowheight);
    }    
    $(window).scroll(globalscroll);
    $(window).resize(function(){
        /*if($(this).width() != windowwidth){
            if($(window).width() > 1025){
                 $('.item_menupanel').masonry({
                     percentPosition: true,
                     itemSelector: '.item_menu',
                     resize: true
                 });
            }
        };*/
        if(windowwidth < 500){
            $('.homebgblack, .home').css('min-height', windowheight);
        }
        if($(window).width() < 767){
            App.renderMap();
        }
        mobilemenu.removeClass('active');
        if($('body').hasClass('a_scrollactive')){
            //if ($(window).width() != $(window).width()) {
                if($(window).width() < 767){
                    var vh = 100;
                }else{
                    var vh = 150;
                }
                var hh = $(window).height() - $('.a_scroll_head').height() - $('.addonpopup_footer').height()-vh;
                $('.a_area').css('max-height', hh);
            //}
        };
        $('.dropdown_mobile').removeClass('active');
        if($(window).width() > 992){
            if($('.tabs').hasClass('mobiletabactive')){
                $('.tabs.mobiletabactive, .menu_container.mobiletabactive').removeClass('deactive').addClass('active');
            }
        }
    });
});

