var Switcher = Class.create({
  initialize: function(root){
	this.root = root;
	
    // Observe link tags with switch set:
    this.featureLinks().each(function(li){
	   Event.observe(li, 'click', this.clickSwitch.bindAsEventListener(this));
	   li.addClassName("unselected");	    
    }, this);

	this.unselectAll();
	this.hideAll();
	
    var first = this.featureLinks().first();
    first.addClassName("selected");
    this.features().each(function(feature){
	   if(feature.id == first.readAttribute("switch")) {
	     feature.show();	
	   }
    });    
  },

  clickSwitch: function(event){

	this.unselectAll();
	this.hideAll();
	
    var element = Event.element(event);
    element.up("li").addClassName("selected");

    var target_div_name = element.up("li").readAttribute("switch");
    $(target_div_name).show();
  },
 
  featureLinks: function(){
    return this.root.down("ul.featureLinks").childElements();	 
  },
 
  features: function(){
	return this.root.down("div.feature").childElements();  
  }, 

  unselectAll: function(){
	this.featureLinks().each(function(li){
      li.removeClassName("selected");	 
 	}, this);
  },

  hideAll: function(){
    this.features().each(function(feature){
	  feature.hide();
    },this);    	
  }
});