
$(function () {
    if ($("#filter-sticker").length)
        setContextSize();
});


function changeFilter() {

    var newValue = "False";
    if ($('#rightmenucontent').hasClass('hidden')) {
        newValue = "True";
    }

    $.cookie("tb_taskfiltersetting", newValue);
    filterToggle();
}

function filterToggle() {
    clickToggle = true;
    var isFilterShow = $.cookie("tb_taskfiltersetting");
    if (isFilterShow == undefined) {
        isFilterShow = $("#defaultfilterfortasklist").val();
    }
    var tblController = window.tableController();
    var isUpdateSize = tblController.toLowerCase().indexOf("dashboard") < 0 && tblController.toLowerCase().indexOf("service") < 0;
    var isPaginationAnimate = tblController.toLowerCase().indexOf("task") < 0;

    if (isFilterShow != undefined && isFilterShow.toLowerCase().indexOf("true") >= 0) {
        $('#rightmenucontent').css("margin-left", "265px");
        $('#rightmenucontent').removeClass('hidden');
        $('#rightmenucontent').animate({ marginLeft: 0 }, 200, function () {
            $("#rightmenu").removeClass("non-border");
            clickToggle = false;
        });
        
        $('#content').animate({ marginRight: 270 }, 200);
        if (isPaginationAnimate)
            $('#pagination').animate({ right: 300 }, 200);

        $("#filter-sticker").animate({ marginRight: 264 }, 200, function () {
            $("#filter-sticker").addClass('arr-right');
            $("#filter-sticker").removeClass('arrow-left');
            $('#footer').removeClass('hidden');

            if (isUpdateSize) {
                updateTasksSize();
                if ($('#footer').length)
                    setFooterTop();
            }
        });

    } else {
        $('#footer').addClass('hidden');
        $("#rightmenu").addClass("non-border");
        $("#filter-sticker").animate({ marginRight: 0, right: -1 }, 200, function () {
            $("#filter-sticker").addClass('arrow-left');
            $("#filter-sticker").removeClass('arrow-right');
        });

        $('#rightmenucontent').animate({ marginLeft: 260 }, 200, "linear", function () {
            $('#rightmenucontent').addClass('hidden');
            clickToggle = false;
        });

        $('#content').animate({ marginRight: 5 }, 200);
        
        if (isPaginationAnimate)
            $('#pagination').animate({ right: 35 }, 200);
        
        $("#filter-sticker").animate({ marginRight: 0 }, 200, function () {
            $("#filter-sticker").addClass('arrow-left');
            $("#filter-sticker").removeClass('arrow-right');

            if (isUpdateSize)
                window.updateTasksSize();
            
        });
    }
}

function updateTasksSize() {

    if ($.browser.msie && parseInt($.browser.version, 10) <= 7) return;

    var $gridContent = $('.k-grid-content');
    if ($gridContent.length != 0) {
        var url = base + window.tableController() + 'ClearColumnResizeGridState';
        $.ajax({ type: "GET", url: url });
        $gridContent.scrollLeft(0);

        KendoGridToPercentWidth($('table.resizable-grid'));
        KendoGridToPixelWidth($('table.resizable-grid'));
    }

}

function setContextSize() {

    var isFilterShow = $.cookie("tb_taskfiltersetting");
    if (isFilterShow == undefined) {
        isFilterShow = $("#defaultfilterfortasklist").val();
    }

    if (isFilterShow != undefined) {

        if (isFilterShow == "True") {
            $('#content').removeClass('margin5');
        } else {
            $('#content').addClass('margin5');
            var tblController = window.tableController();
            var isTaskPage = tblController.toLowerCase().indexOf("task.ivp") >= 0;

            if (!isTaskPage)
                $('#pagination').css("right", "35px");
        }
    }


}
