(function(){

    Portlet_Language_Selector = function( id, classname ){

        this.options = {};

        this.events = ['change'];

        this.listen = [
            [this, 'change', this.changeLanguage],
            ['Admin_Language_Data', 'refresh', this.refresh],
            ['Admin_Language_List', 'remove', this.refresh],
            ['Admin_Language_Data', 'switch', this.switchLanguage]
        ];

        IApp_Portlet.apply(this, arguments);
    };

    Portlet_Language_Selector.prototype = $.extend( new IApp_Portlet, {

        init : function(){
            IApp_Portlet.prototype.init.apply(this, arguments);

            /** Place for on init actions **/
            var self = this;
            this.$div.find('select').unbind().change(function(){ self.dispatchEvent('change', $(this).val()); });
        },

        changeLanguage: function( lang_id ){

            this.callRemoteFunc( 'changeLanguage', {data: [lang_id], timeout:60000 } );
        },

        refresh: function(){
        	var self = this;
            this.callRemoteFunc( 'refresh', {target:self.$div} );
        }

    });

})(jQuery);
