$(document).ready(function () {

    /* Alert notifications */
    var hulla = new hullabaloo();
    hulla.send("OneView loaded successfully", "success");
    setTimeout(function () {
        hulla.send("Please update you details", "info");
    }, 4000);

    setTimeout(function () {
        hulla.send("You have 15 new tickets", "warning");
    }, 8000);

    $('li.dropdown.notifications a').on('click', function (event) {
        $('li.dropdown.notifications').removeClass('show');
        $('li.dropdown.notifications .dropdown-menu').removeClass('show');
        $(this).parent().addClass('show');
        $(this).siblings(".dropdown-menu").addClass('show');
    });

    $('body').on('click', function (e) {
        if (!$('li.dropdown.notifications').is(e.target)
            && $('li.dropdown.notifications').has(e.target).length === 0
            && $('.open').has(e.target).length === 0
        ) {
            $('li.dropdown.notifications').removeClass('show');
            $('li.dropdown.notifications .dropdown-menu').removeClass('show');

        }
    });


    /* Expand/compress tags panel */

$('#expandtags').click(function () { 
    $('#tags, #graphwrapper').toggleClass("expanded");  
});

/* change icon in filter input and clear on click*/

    $(".material-input input").focus(function () {
        $(this).siblings("i").addClass("icon-close");
        $(this).siblings("i").removeClass("icon-filter");
        $(this).siblings("i").removeClass("icon-search");
        $(this).siblings("i.icon-close").removeClass("disabled");

        $(this).siblings("i").click(function () {
            $(this).siblings("input").val('');
            $(this).addClass("disabled");
            $(this).addClass("icon-filter");
            $(this).removeClass("icon-close");
        });
    });

    $(".material-input input:not(.unitsearch)").focusout(function () {
        if ($(this).val() == "") {
            $(this).siblings("i.icon-close").addClass("disabled");
            $(this).siblings("i.icon-close").addClass("icon-filter");
            $(this).siblings("i.icon-close").removeClass("icon-close");

        }
    });

    $(".material-input .unitsearch").focusout(function () {
        if ($(this).val() == "") {
            $(this).siblings("i.icon-close").addClass("icon-search");
            $(this).siblings("i.icon-close").removeClass("icon-close");

        }
    });



    $(".createuser .material-input input").focus(function () {
        $(this).siblings(".icon-details").show();
        $(this).addClass("alertborder");
    });

    $(".createuser .material-input input").focusout(function () {
        $(this).siblings(".icon-details").hide();
        $(this).removeClass("alertborder");
    });


   
/* input Error demo */
 /*
$(".material-input input").focus(function () {
    //$(this).siblings("error").slideDown();
    $(this).siblings("error").addClass("shown");
    $(this).closest("th").animate({
        height: 71
    }, 200);

    
});

$(".material-input input").focusout(function () {
    //$(this).siblings("error").slideUp();
    $(this).siblings("error").removeClass("shown");
    $(this).closest("th").animate({
        height: 61
    }, 200);

});*/

$("input").focus(function () {
    $(this).next("inlineerror").addClass("shown");
    /*$(this).closest("th").animate({
        height: 71
    }, 200);*/

    
});




    /* Ticket Modal */
    $(".icon-createticket").click(function () {
        $('#ticketModal').modal({
            show: true
        });
    });

    $('#ticketModal').modal({
        show: true
    });

    /* Reports modal */
    $("#reportPeriodOk").click(function () {
        $('#reportModal').modal({
            show: true
        });
    });

    /* Loader icon */
    $(".loader").delay("1000").fadeOut("500", function () {
        $(".status h1").fadeIn("500", function () {
            $(".status h2").fadeIn("400");
        });
        $(".hiddenwhileloading").fadeIn("800");
    });


    /* show all alarm types and recipients */


    $("#showallalarms").click(function () {
        $("#selectednotificationwrapper").toggleClass("fullheight");
        $("#notificationwrapper").toggleClass("fullheight");

        $("#showallalarms span").text(function(i, text){
            return text === "Show all" ? "Show less" : "Show all";
        })
    });

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


    /* Show drill container */
    $(".detailbtn").click(function () {
        $(".detailbtn").removeClass("active");
        $(".detailbtn").addClass("inactive");
        $(".drill-drop").addClass("inactive");

        $(".datarow").removeClass("active");

        $(this).removeClass("inactive").addClass("active");
        $(this).closest(".datarow").addClass("active");
    });

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

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

        $("#tablewrapper").stop().animate({
        }, 1000, function () {

            $(".closeDetail").fadeIn(500, function () {
            });

            $("#tablewrapper").stop().animate({
                width: 340
            }, 1000);

            //$('#filterbuttons').slideUp("fast");
            $('#tablewrapper').height(visualheight - 30);
            $("#tablewrapper").css(
                "overflow-y", "scroll"
            );
        });

        $(".drillcontainer").stop().animate({
            left: xoffset + 25,
            width: drillwidth
        }, 1000, function () {

            $("#monitorwrapper").stop().animate({
            }, 300);
        });
    });

    /* Hide Drillcontainer */

    $(".closeDetail").click(function () {
        $(".detailbtn").removeClass("active");
        $(".detailbtn").removeClass("inactive");
        $(".datarow").removeClass("active");

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

        });

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


        }, 400, function () {

            $(".closeDetail").fadeOut(500, function () {
            });

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

            $('#filterbuttons').slideDown("slow");
        });

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

    });

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

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

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

    /* Minimize drill container */
    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();
    });


    /* Full screen drill container */
    $(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();
    });

    /* Switch color theme */

    $('#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);
    })

});

/* Tooltip */

$(function () {
    $('[data-toggle="tooltip"]').tooltip()
})