project.player.Header = new Class({
    Implements: [Options, project.player.Logging],

    log_prefix: 'Header',

    title: null,
    sub_title: null,
    favorites: 0,
    hosts: [],
    icon: '<span>&#10084;<span> ',

    options: {

    },

    initialize: function(options)
    {
        this.setOptions(options);
        this.render();
    },

    render: function()
    {
        var player_header = $('player_header');

        this.title = new Element('h3', {
            'text': this.options.title
        });

        this.sub_title = new Element('p', {
            'class': 'subdesc',
            'text': this.options.sub_title
        });

        this.favorites = new Element('p', {
            'class': 'favorized',
            'html': this.icon + '<span id="header_favorized">' + this.options.favorites + '</span>'
        });

        player_header.adopt([
            this.sub_title,
            this.favorites,
            this.title
        ]);
    },

    setTitle: function(value)
    {
        this.logger(['setTitle', value]);
        this.title.set('text', value);
    },

    setSubTitle: function(value)
    {
        this.logger(['setSubTitle', value]);
        this.sub_title.set('html', '&nbsp;'); // deaktiviert laut mantis: 0076667;
    },

    setFavorites: function(value)
    {
        this.logger(['setFavorites', value]);
        $('header_favorized').set('html', value);
    },

    setHosts: function(value)
    {
        this.logger(['setHosts', value]);
        this.hosts = value;
        this.renderHosts();
    },

    setUsername: function(data)
    {
        if( data.username && data.userlink )
        {
            var link = 'http://' + window.location.hostname + data.userlink;
            this.sub_title.set('html', 'Von: <a href="' + link + '">' + data.username + '</a>');
        }
    },

    renderHosts: function(value)
    {
        var links = [];
        if(this.hosts && this.hosts.length > 0)
        {
            this.hosts.each(function(host){
                links.push('<a href="'+host.url+'">'+host.name+'</a>');
            });

            this.sub_title.set('html', 'Moderation: ' + links.join(', '));
        }
    }
});

