AUI().use("liferay-session", "cookie", function (A) {
    function updateCookie(expiration) {
        var expires = new Date();
        expires = new Date(expires.getTime() + expiration);

        var cookieOptions = {
            path: '/',
            secure: A.UA.secure,
            expires: expiration < 0 ? -1 : expires,
            raw: true
        };

        if (navigator.cookieEnabled) {
            A.Cookie.set("LIFERAY_SESSION_ACTIVE", expiration < 0 ? -1 : expires.toISOString(), cookieOptions);
        }
    }

    if (themeDisplay.isSignedIn()) {
        AUI().use("liferay-session", "cookie", function (A) {

            updateCookie(-1);

            var _startTimer = Liferay.SessionBase.prototype._startTimer;

            Liferay.SessionBase.prototype._startTimer = function () {
                _startTimer.call(this);
                console.log("Active session cookie updated");
                updateCookie(this.get('sessionExpired') ? 0 : this.get('sessionLength'));
            }
        });
    } else {
        updateCookie(0);
    }
});
