ATV = {

    "flash_player_fullscreen_enabled": false,
    
    "flash_player_is_playing": false,

    "profile": {
        "is_profile": false
    },

    "getLoggedInUser": function()
    {
        /*
         * Sollte die Userdaten aus dem Cookie holen!
         */
        var user_data = Cookie.read('user_data');

        if (user_data)
        {
            user_data = JSON.decode(user_data);
            user_data.avatarUrl = $('base_href').get('href') + 'community/profil/avatar_' + user_data.userId + '_thumb.jpeg';
            user_data.profileUrl = $('base_href').get('href') + 'community/profil/' + user_data.userId + '/' + user_data.userName;
            user_data.logInStatus = 'true';
            user_data.notifications = user_data.notifications || [];
        }

        return user_data || null;
    },

    "isAuthenticated": function()
    {

        if (null === this.getLoggedInUser())
        {
            return false;
        }
        else
        {
            return true;
        }
    },

    "navigateTo": function(url)
    {
        if ($('wallpaper'))
        {
            try
            {
                $('wallpaper').executeCommand('closeAllConnections', {});
            } catch (e)
            {
                /* hide warnings */
            }
        }

        if (url.substr(0, 4) != 'http')
        {
            url = $('base_href').get('href') + url
        }

        /*
         * the following magic is made especially for our friends over at
         * internet explorer development, since they do not send the REFER in
         * case of document.location is set directly! :(
         */
        var ref_link = document.createElement('a');
        ref_link.href = url;

        /* In case we have a click method, try it with that one */
        if (typeof (ref_link.click) !== "undefined")
        {
            document.body.appendChild(ref_link);
            ref_link.click();
        }
        else
        {
            document.location = url;
        }
    },
    "initProfile": function(id, username, can_edit, is_own)
    {
        ATV.profile.id = id;
        ATV.profile.username = username;
        ATV.profile.is_profile = true;
        ATV.profile.is_own = is_own;
        ATV.profile.can_edit = can_edit;
    },

    "isFlashPlayerFullscreenEnabled": function()
    {
        return ATV.flash_player_fullscreen_enabled;
    },
    
    "isFlashPlayerPlaying": function()
    {
        return ATV.flash_player_is_playing;
    }
};

/*
 * register event, to set a fullscreen mode variable
 */
document.addEvent('flashplayer:onFullscreen', function()
{
    ATV.flash_player_fullscreen_enabled = !ATV.flash_player_fullscreen_enabled;
});

document.addEvent('flashplayer:onPlay', function()
{
    ATV.flash_player_is_playing = true;
});

document.addEvent('flashplayer:onPause', function()
{
    ATV.flash_player_is_playing = false;
});

