﻿/// <reference name="MicrosoftAjax.js"/>
Type.registerNamespace("aorta.playmeweb.webcontrols");

aorta.playmeweb.webcontrols.InformacoesMusica = function() {
    aorta.playmeweb.webcontrols.InformacoesMusica.initializeBase(this);

    this._imagemCapa = null;
    this._tamanhoCapa = null;
    this._campoArtista = null;
    this._campoAlbum = null;
    this._campoMusica = null;
    this._campoProximaMusicaNome = null;
    this._campoProximaMusicaArtista = null;
    this._player = null;

    //Cria as delegates
    this._player_onShowMusicInfoDelegate = null;
}

aorta.playmeweb.webcontrols.InformacoesMusica.prototype = {
    initialize: function() {
        aorta.playmeweb.webcontrols.InformacoesMusica.callBaseMethod(this, 'initialize');

        this._player_onShowMusicInfoDelegate = Function.createDelegate(this, this._player_onShowMusicInfoHandler);

        //Cria os handlers para os eventos
        this._player.add_showMusicInfo(this._player_onShowMusicInfoDelegate);
    },

    dispose: function() {
        aorta.playmeweb.webcontrols.InformacoesMusica.callBaseMethod(this, 'dispose');

        //Remove os handlers para os eventos
        this._player.remove_showMusicInfo(this._player_onShowMusicInfoDelegate);
    },

    _player_onShowMusicInfoHandler: function(sender, args) {
        //Atualiza as informações da música
        var musica = this.get_player().get_musica();
        var musicaAtual;
        if (musica) {
            musicaAtual = musica.Nome;

            //Set música anterior
            if (this.get_campoMusicaNomeAnterior()) {
                if (this.get_campoMusica()) {
                    if (this.get_campoMusica().innerHTML != musicaAtual)
                        this.get_campoMusicaNomeAnterior().innerHTML = this.get_campoMusica().innerHTML;
                }
            }

            //Set música atual
            if (this.get_imagemCapa()) {
                //this.get_imagemCapa().src = 'App_Controls/RedimensionarImagem.aspx?caminhoImg=' + musica.UrlCapa + '&tamanhoImg=' + this.get_tamanhoCapa();
                this.get_imagemCapa().src = musica.UrlCapa + '&wimg=' + this.get_tamanhoCapa();
            }
            if (this.get_campoArtista())
                this.get_campoArtista().innerHTML = musica.Artista ? musica.Artista : '';

            if (this.get_campoAlbum())
                this.get_campoAlbum().innerHTML = musica.Album ? musica.Album : '';

            if (this.get_campoMusica())
                this.get_campoMusica().innerHTML = musica.Nome ? musica.Nome : '';

            //Set próxima música
            if (this.get_campoProximaMusicaArtista())
                this.get_campoProximaMusicaArtista().innerHTML = musica.ArtistaProximaMusica ? musica.ArtistaProximaMusica.split('-')[0] : '';

            if (this.get_campoProximaMusicaNome())
                this.get_campoProximaMusicaNome().innerHTML = musica.ArtistaProximaMusica ? musica.ArtistaProximaMusica.split('-')[1] : '';
        }
    },

    get_imagemCapa: function() {
        /// <value type="Object" locid="P:J#aorta.playmeweb.webcontrols.InformacoesMusica.imagemCapa"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._imagemCapa;
    },
    set_imagemCapa: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Object}]);
        if (e) throw e;
        this._imagemCapa = value;
    },

    get_tamanhoCapa: function() {
        /// <value type="Number" locid="P:J#aorta.playmeweb.webcontrols.InformacoesMusica.tamanhoCapa"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._tamanhoCapa;
    },
    set_tamanhoCapa: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Number}]);
        if (e) throw e;
        this._tamanhoCapa = value;
    },

    get_campoArtista: function() {
        /// <value type="Object" locid="P:J#aorta.playmeweb.webcontrols.InformacoesMusica.campoArtista"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._campoArtista;
    },
    set_campoArtista: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Object}]);
        if (e) throw e;
        this._campoArtista = value;
    },

    get_campoAlbum: function() {
        /// <value type="Object" locid="P:J#aorta.playmeweb.webcontrols.InformacoesMusica.campoAlbum"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._campoAlbum;
    },
    set_campoAlbum: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Object}]);
        if (e) throw e;
        this._campoAlbum = value;
    },

    get_campoMusica: function() {
        /// <value type="Object" locid="P:J#aorta.playmeweb.webcontrols.InformacoesMusica.campoMusica"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._campoMusica;
    },
    set_campoMusica: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Object}]);
        if (e) throw e;
        this._campoMusica = value;
    },

    get_campoProximaMusicaNome: function() {
        /// <value type="Object" locid="P:J#aorta.playmeweb.webcontrols.InformacoesMusica.campoProximaMusicaNome"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._campoProximaMusicaNome;
    },
    set_campoProximaMusicaNome: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Object}]);
        if (e) throw e;
        this._campoProximaMusicaNome = value;
    },

    get_campoProximaMusicaArtista: function() {
        /// <value type="Object" locid="P:J#aorta.playmeweb.webcontrols.InformacoesMusica.campoProximaMusicaArtista"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._campoProximaMusicaArtista;
    },
    set_campoProximaMusicaArtista: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Object}]);
        if (e) throw e;
        this._campoProximaMusicaArtista = value;
    },

    get_campoMusicaNomeAnterior: function() {
        /// <value type="Object" locid="P:J#aorta.playmeweb.webcontrols.InformacoesMusica.campoMusicaNomeAnterior"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._campoMusicaNomeAnterior;
    },
    set_campoMusicaNomeAnterior: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Object}]);
        if (e) throw e;
        this._campoMusicaNomeAnterior = value;
    },

    get_campoMusicaArtistaAnterior: function() {
        /// <value type="Object" locid="P:J#aorta.playmeweb.webcontrols.InformacoesMusica.campoMusicaArtistaAnterior"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._campoMusicaArtistaAnterior;
    },
    set_campoMusicaArtistaAnterior: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Object}]);
        if (e) throw e;
        this._campoMusicaArtistaAnterior = value;
    },

    get_player: function() {
        /// <value type="Sys.Component" locid="P:J#aorta.playmeweb.webcontrols.InformacoesMusica.player"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._player;
    },
    set_player: function(value) {
        var e = Function._validateParams(arguments, [{ name: "value", type: Sys.Component}]);
        if (e) throw e;
        this._player = value;
    }
}

aorta.playmeweb.webcontrols.InformacoesMusica.registerClass('aorta.playmeweb.webcontrols.InformacoesMusica', Sys.Component);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();