$(
    function() {
        $(".various").fancybox({
            maxWidth: 960,
            fitToView: false,
            width: '95%',
            height: 'auto',
            autoSize: false,
            closeClick: false,
            openEffect: 'fade',
            closeEffect: 'fade',
            padding: "0",
            closeBtn: false,
            helpers: {
                overlay: {
                    css: {
                        'background': 'rgba(0,0,0,0.5)'
                    }
                }
            }
        });


        if ($("#plandue").length) {
            $("#plandue").load("plandue.html");
        }

        $(".alertBox").fancybox({
            maxWidth: 450,
            fitToView: false,
            width: '95%',
            height: 'auto',
            autoSize: false,
            closeClick: false,
            openEffect: 'fade',
            closeEffect: 'fade',
            tpl: {
                wrap: '<div class="fancybox-wrap" tabIndex="-1"><div class="fancybox-skin theme2"><div class="fancybox-outer"><div class="fancybox-inner"></div></div></div></div>'
            },
            padding: "0",
            closeBtn: false,
            beforeShow: function() {
                $(".fancybox-skin").css("border-radius", "3 px")

            },
            helpers: {
                overlay: {
                    css: {
                        'background': 'rgba(0,0,0,0.5)',
                    }
                }
            }
        });


        if ($(window).width() <= 767) {

            $(".navbar-toggle").click(function() {
                var $this = $('.navbar-toggle .iconBar');
                if ($this.hasClass("cssHide")) {
                    $this.removeClass("cssHide");
                    $('.closeButton').removeClass("cssShow");
                    $('.grey-bg').hide();
                    $('.subMenu').css('visibility', 'visible');

                } else {
                    //$("a").removeClass("active");
                    $this.addClass("cssHide");
                    $('.closeButton').addClass("cssShow");
                    $('.grey-bg').fadeIn(200);
                    $('.subMenu').css('visibility', 'hidden');
                }
            });

        }



        if ($('#back-to-top').length) {
            var scrollTrigger = 100, // px
                backToTop = function() {
                    var scrollTop = $(window).scrollTop();
                    if (scrollTop > scrollTrigger) {
                        $('#back-to-top').addClass('show');
                        $(".subMenu").addClass('fixed');
                    } else {
                        $('#back-to-top').removeClass('show');
                        $(".subMenu").removeClass('fixed');
                    }
                };
            backToTop();
            $(window).on('scroll', function() {
                backToTop();
            });
            $('#back-to-top').on('click', function(e) {
                e.preventDefault();
                $('html,body').animate({
                    scrollTop: 0
                }, 700);
            });
        }


        /*if ($(window).width() > 990) {
                resizeFrame();
         }*/


        $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
            resizeFrame();
        });

        $(window).resize(
            function() {
                resizeFrame();
            }
        );

    }
)

function resizeFrame() {

    var bodyHeight = $(".masterFrame").height();
    var vwptHeight = $(window).height();

    if (vwptHeight > bodyHeight) {
        $("footer").addClass("fixed");
    } else {
        $("footer").removeClass("fixed");
    }

}

jQuery(window).load(function() {
    if ($("#hkbnplan").length) {
        $("#hkbnplan").load("normalplan.html", function() {
            if ($(window).width() > 990) {
                resizeFrame();
            }
        });

    } else {
        resizeFrame();
    }
});
