iii.shareprice.apps.user = new Class( {
	Implements: Events,
	is: false,
	cookie: '_user_logged',
	initialize: function ( superclass ) {
		var self = this;
		this.superclass = superclass;
		this.superclass.addEvent( 'layout-ready', function ( ) {
			self.load();
		} );
		this.superclass.addEvent( 'user-login', function ( ) {
			self.save();
		} );
		this.superclass.addEvent( 'user-logout', function ( ) {
			self.save();
			self.superclass.request.send( {
				url: iii.shareprice.apps.config.get( 'serviceUrl' ) + "service/json/client/user/logout"
			} );
		} );
	},
	set: function ( name, data ) {
		if( name ) {
			this.name = name;
			this.is = true;
			this.data = data;
			this.superclass.fireEvent( 'user-login', [ this.name, this.data ] );
		} else {
			this.name = false;
			this.is = false;
			this.data = {};
			this.superclass.fireEvent( 'user-logout', [ this.name, this.data ] );
		}
	},
	save: function ( ) {
		this.superclass.cookie.enc( this.cookie, {
			n: this.name,
			sP: this.data.streamingPassword,
			sU: this.data.streamingUsername,
			sS: this.data.streamingSessionId
		}, false );
	},
	load: function ( ) {
		var $this = this;
		this.superclass.request.send( {
			url: iii.shareprice.apps.config.get( 'serviceUrl' ) + "service/json/client/user/currentuser",
			success: function ( data ) {
				if ( data && data.success == true ) {
					$this.set( data.username, {
						streamingPassword: data.streamingPassword,
						streamingUsername: data.streamingUsername,
						streamingSessionId: data.streamingSessionId
					} )
				}
			}
		} );
	}
} );