Ext.namespace('Ext.ux');

var Layerlist = Ext.extend(Object, {
			names : new Array(),
			opacities : new Array(),
			constructor : function(config) {
				names = this.names;
				opacities = this.opacities;
				Ext.apply(this, config)
			},
			removeLayer : function(layer) {
				var name = this.getName(layer);
				var index = this.isInNames(name);
				if (index != -1) {
					this.names.splice(index, 1);
					this.opacities.splice(index, 1);
				}
			},
			addLayer : function(layer) {
				var name = this.getName(layer);
				if (this.isInNames(name) == -1) {
					this.names.push(name);
					this.opacities.push(layer.opacity ? layer.opacity : 1);
				}
			},
			getName : function(layer) {
				return layer.metadata.name.substring(9);
			},
			getNames : function() {
				return this.names;
			},
			isInNames : function(string) {
				var i;
				for (i = 0; i < this.names.length; i++) {
					if (this.names[i] == string) {
						return i;
					}
				}
				return -1;
			},
			isInLayerlist : function(layer) {
				var name = this.getName(layer);
				if (this.isInNames(name) != -1) {
					return true;
				} else {
					return false;
				}
			},
			getOpacity : function(layer) {
				return this.opacities[this.isInNames(this.getName(layer))];
			},
			setOpacity : function(layer, opacity) {
				var index = this.isInNames(this.getName(layer));
				this.opacities[index] = opacity;
			}
		})
Ext.ux.Layerlist = Layerlist;
