/**
 * Created by Tejas on 21/08/18.
 */

$(function () {
    // gumshoe.init({
    //     offset:85
    // });
    new WOW().init();
    if(!IE){
      var scroll = new SmoothScroll('a[href*="#"]',{header: 'nav'});
    }
    //mobile = "";
    if (mobile == 0) {
        $('#myshow').cycle({
            swipe: "true",
            slides: "> div.slide",
            easing: "easeOutCubic",
            fx: 'scrollHorz', //'scrollVert',
            timeout: 5000,
            speed: 1600,
            allowWrap: true,
            log: false
        });
        $('.cyc-gallery').cycle({
            swipe: "true",
            slides: "> img",
            easing: "easeOutCubic",
            fx: 'carousel', //'scrollVert',
            //carouselVisible:3,
            loop:3,
            prev:"> .prev",
            next:"> .next",
            timeout: 3000, //set timeout = 0 for manual show
            speed: 1000,
            allowWrap: true,
            log: false
        });
        $('.cyc-testimonials').cycle({
            swipe: "true",
            slides: "> .message",
            easing: "easeOutCubic",
            fx: 'scrollHorz', //'scrollVert',
            loop:1,
            prev:"> .prev",
            next:"> .next",
            timeout: 5000,
            speed: 1000,
            allowWrap: true,
            log: false
        });
        var wh = window.innerHeight;
        var navH = $(".navbar").height();
        wh-=navH;
        //console.log(navH);
        $(".slide").height(wh);
        $(".fullpage").height(wh);
        $(".responsive-video").height(wh*0.75);
        //$(".slide").height(wh*0.85);
    } else {
        $('.cyc-gallery').cycle({
            swipe: "true",
            slides: "> img",
            easing: "easeOutCubic",
            fx: 'carousel', //'scrollVert',
            //carouselVisible:3,
            loop:3,
            prev:"> .prev",
            next:"> .next",
            timeout: 3000, //set timeout = 0 for manual show
            speed: 1000,
            allowWrap: true,
            log: false
        });
        $('.cyc-testimonials').cycle({
            swipe: "true",
            slides: "> .message",
            easing: "easeOutCubic",
            fx: 'scrollHorz', //'scrollVert',
            loop:1,
            prev:"> .prev",
            next:"> .next",
            timeout: 5000,
            speed: 1000,
            allowWrap: true,
            log: false
        });
        var wh = window.innerHeight;
        var navH = $(".navbar").height();
        wh-=navH;
        //console.log(navH);
        $(".slide").height("80vh");
    }

    //$(".slide").height(wh);
    $(".slide, .sct-page-top-image").each(function () {
        var img = $(this).attr("data-slide-image"),
            setPage = $(this).attr("data-page"),
            imgpath = "assets/images/";

        var me = $(this);
        if(setPage && setPage=="home"){
            imgpath = imgpath + "home/"
        }
        if(setPage && setPage=="inner"){
            imgpath = imgpath + "inner/"
        }

        if (mobile) {
            img = imgpath + "mobile/" + img;
        } else {
            img = imgpath + img;
        }
        me.css('background', 'url("' + img + '")');
        me.css('background-repeat', 'no-repeat');
        me.css('background-position', 'center');
        me.css('background-size', 'cover');
    });


    $("#close-nav").on("click", function(){
        $(".nav-link").removeClass("selected");
        close_menu();
    });
    var trig = $("#menu-panel-wrap");
    var outer_bg = "";
    function populate_menu(){
        var el_mc = $(".menu-contents");
        var nav_arr = $(".nav-item");
        nav_arr.each(function(index, value){
            var div = document.createElement("div");
            div.setAttribute("id", value.id);
            div.setAttribute("class", "sub-menu-page")
            var ul = $(value).children("ul").clone().appendTo(div);
            el_mc.append(div);
        });

        $("body").append("<div class='menu_outer_bg'></div>");
    }

    function show_menu(id){
        if(!id){
            console.log("no id");
        }
        $(".menu-contents > div").each(function(index, value){
            if(value.id !== "id"){
                $(this).removeClass("show");
            }
        });
        $(".menu-contents div#"+id).addClass("show");
        trig.removeClass("closed");
        outer_bg.show();
    }
    function close_menu(){
        trig.addClass("closed");
        trig.data("current", "");
        outer_bg.hide();
    }
    function is_menu_open(){
        return trig.hasClass("closed");
    }
    //$(document).click(function(event) {
    //    if(!$(event.target).closest('#menu-panel-wrap').length) {
    //        if($('#menu-panel-wrap').is(":visible")) {
    //            $('#menu-panel-wrap').addClass("closed");
    //        }
    //    }
    //});



    if(mobile==0){
        //console.log("desktop");
        /* TOP NAVIGATION FUNCTION*/

        $(".nav-link").on("click", function(e){
            var mob = $(".navbar-toggler").css("display");
            e.preventDefault();
            d = $(this).parent().attr("id");
            if($(this).parent().hasClass("has-submenu")){
                if(trig.data("current") == d){
                    close_menu();
                }else{
                    trig.data("current", d);
                    $(".nav-link").removeClass("selected");
                    $(this).addClass("selected");
                    show_menu(d);
                }
            }
        });
        populate_menu();
        outer_bg = $(".menu_outer_bg");
        outer_bg.hide();
        outer_bg.on("click",function(){
        close_menu();
    });
    }else{
        $(".nav-link").on("click", function(e){
            $(this).parent().children("ul").toggle();
            e.preventDefault();
        });
    }

    /* NAVIGATION END*/

    // $('.watchvideo').magnificPopup({
    //     items: [
    //         {
    //             src: '#my-popup', // CSS selector of an element on page that should be used as a popup
    //             type: 'inline'
    //         }
    //     ],
    //     gallery: {
    //         enabled: false
    //     },
    //     type: 'image' // this is a default type
    // });

    // $('.popup-youtube, .popup-vimeo, .popup-gmaps').magnificPopup({
    //     disableOn: 700,
    //     type: 'iframe',
    //     mainClass: 'mfp-fade',
    //     removalDelay: 160,
    //     preloader: false,

    //     fixedContentPos: false
    // });

/*    $('.enlarge_link').magnificPopup({
        items: [
            {
                src: '#my-popup', // CSS selector of an element on page that should be used as a popup
                type: 'inline'
            }
        ],
        gallery: {
            enabled: false
        },
        type: 'image' // this is a default type
    });*/

});

