var SimpleLayerSwitcher = OpenLayers.Class(OpenLayers.Control, { layerStates: null, layersDiv: null, ascending: true, initialize: function(options) { OpenLayers.Control.prototype.initialize.apply(this, arguments); this.layerStates = []; }, destroy: function() { OpenLayers.Event.stopObservingElement(this.div); //clear out layers info and unregister their events this.map.events.un({ "addlayer": this.redraw, "changelayer": this.redraw, "removelayer": this.redraw, "changebaselayer": this.redraw, scope: this }); OpenLayers.Control.prototype.destroy.apply(this, arguments); }, setMap: function(map) { OpenLayers.Control.prototype.setMap.apply(this, arguments); this.map.events.on({ "addlayer": this.redraw, "changelayer": this.redraw, "removelayer": this.redraw, "changebaselayer": this.redraw, scope: this }); }, draw: function() { OpenLayers.Control.prototype.draw.apply(this); this.loadContents(); this.redraw(); return this.div; }, checkRedraw: function() { var redraw = false; if ( !this.layerStates.length || (this.map.layers.length != this.layerStates.length) ) { redraw = true; } else { for (var i=0, len=this.layerStates.length; i