$(function() {
    var $body = $('body');
    var $privacy_message = $('#privacy-message');

    var cookie_name = 'tracking-accepted';

    window.privacy_accepted = getCookie(cookie_name);

    if (window.privacy_accepted === null) {
        $privacy_message.removeAttr('style');

        $body.on('click', '.privacy_action--accept', function(event) {
            event.preventDefault();
            setCookie(cookie_name, 'true', 60);
            $privacy_message.remove();
            $body.trigger('enable_tracking');
        });

        $body.on('click', '.privacy_action--decline', function(event) {
            event.preventDefault();
            setCookie(cookie_name, 'false', 60);
            $privacy_message.remove();
        });

        $body.on('click', '.privacy_action--close', function(event) {
            event.preventDefault();
            $privacy_message.remove();
        });
    } else {
        window.privacy_accepted = window.privacy_accepted === 'true';
        $privacy_message.remove();
    }
});