$(document).ready(function () {

    $(".settings").click(function () {
        $("#settings").toggleClass("active");
    });


    $(".detailbtn").click(function () {
        $(".drillcontainer").show();
        var visualheight = $(".drillcontainer").height();
        var xoffset = $("#titletd").width() + $("#actiontd").width() + 90;
        var drillwidth = $("#monitorwrapper").width() - xoffset + 30;

        console.log(xoffset + ' | Visualheight: ' + visualheight);

        $("#monitorwrapper").stop().animate({
            height: visualheight + 50
        }, 1000, function () {
            $(".closeDetail").fadeIn(500, function () {
            });
        });

        $(".drillcontainer").stop().animate({
            left: xoffset,
            width: drillwidth,

        }, 1000, function () {
            $(this).show();
            $("#monitorwrapper").stop().animate({
            }, 300);
        });
    });

    $(".closeDetail").click(function () {
        $(".drillcontainer").stop().animate({
            left: "100%"
        }, 400, function () {
            $(".drillcontainer").hide();

        });

        $("#tablewrapper").stop().animate({
            width: "100%",
            height: "auto",
        }, 400, function () {

            $("#tablewrapper").css(
                "overflow-y", "hidden"
            );
        });

        $("#monitorwrapper").stop().animate({
            height: "auto",
            overflow: "hidden"
        }, 300);
    });


    function maximize() {
        $(".drillcontainer").stop().animate({
            left: 25,
            width: $("#monitorwrapper").width() + 5
        }, 400, function () {

            var visualheight = $(".drillcontainer").height();

            $("#monitorwrapper").stop().animate({
                height: visualheight + 50
            });
        });
    }

    function minimize() {
        var xoffset = $("#titletd").width() + $("#actiontd").width() + 90;
        var drillwidth = $("#monitorwrapper").width() - xoffset + 30;
        $(".drillcontainer").stop().animate({
            left: xoffset,
            width: drillwidth,
        }, 400, function () {

            var visualheight = $(".drillcontainer").height();

            $("#monitorwrapper").stop().animate({
                height: visualheight + 50
            });
        });
    }

    $(".maximize").click(function () {
        return (this.tog = !this.tog) ? maximize() : minimize();
    });

    $(function () {
        $('#supported').text('Supported/allowed: ' + !!screenfull.enabled);

        if (!screenfull.enabled) {
            return false;
        }

        $('#request').click(function () {
            screenfull.request($('#container')[0]);
        });

        $('#exit').click(function () {
            screenfull.exit();
        });

        function fullscreenchange() {
            var elem = screenfull.element;

            $('#status').text('Is fullscreen: ' + screenfull.isFullscreen);

            if (elem) {
                $('#element').text('Element: ' + elem.localName + (elem.id ? '#' + elem.id : ''));
            }

            if (!screenfull.isFullscreen) {
                $('#external-iframe').remove();
                document.body.style.overflow = 'auto';
            }
        }

        screenfull.on('change', fullscreenchange);

        fullscreenchange();
    });

    $('#themeswitch').click(function () {
        $('body').toggleClass("theme-light theme-dark");
    });

    $('.tree-toggle').click(function () {
        $(this).parent().parent().children('ul.tree').toggle(200);
    });

    $(function () {
        $('.tree-toggle').parent().parent().children('ul.tree').toggle(200);
    })

});




function swapStyleSheet(sheet) {
    document.getElementById('pagestyle').setAttribute('href', sheet);
}