$(function () {
    var ids = getCookie('user_read_ids');
    if (ids != null) {
        var temp = ids.split(",");
        $.each(temp, function (k, v) {
            $('#' + v).parents('li:first').find('i:first').removeClass('fa-angle-down');
            $('#' + v).parents('li:first').find('i:first').addClass('fa-angle-right');
            $('#' + v).parents('li:first').find('ul:first').show();
        });
    }

    $('i.fa-angle-down').click(function () {

        setCookie('user_read_ids', $(this).attr('id'), 1);
    });
    $('i.fa-angle-right').click(function () {
        delCookie('user_read_ids', $(this).attr('id'), 1);
    });
});

function setCookie(name, value, min) {
    var val = getCookie(name);
    if (val === null) {
        val = "";
    } else {
        val = val + ",";
    }

    var date, expires;
    if (min) {
        date = new Date();
        date.setTime(date.getTime() + (min * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    } else {
        expires = "";
    }
    document.cookie = name + "=" + val + value + expires + "; path=/";
}

function delCookie(name, value, min) {
    var val = getCookie(name);
    if (val != null) {
        var temp = val.split(",");
        var new_val = null;
        $.each(temp, function (k, v) {
            if (v !== value) {
                new_val = v + ",";
            }
            var date, expires;
            if (min) {
                date = new Date();
                date.setTime(date.getTime() + (min * 60 * 1000));
                expires = "; expires=" + date.toGMTString();
            } else {
                expires = "";
            }
            document.cookie = name + "=" + new_val + expires + "; path=/";
        });
    }
}

function getCookie(name) {
    var cookie = " " + document.cookie;
    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;
    if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = cookie.indexOf(";", offset)
            if (end == -1) {
                end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
    return(setStr);
}