var HomeBox = Behavior.create({
  initialize:function() {
    this.lis = $$('#home_box li');
    this.contents = $$('#home_box li div.content');
    this.hideContents();
    this.lis.first().addClassName("first");
    this.lis.last().addClassName("last");
    this.switchTo("spring",true);
  },
  
  hideContents:function() {
    this.contents.each(function(e){ e.hide() });
  },
  
  onclick:function(e) {
    var element = Event.element(e);
    if (element.name != null) {
      Event.stop(e);
      this.switchTo(element.name);
    }
  },
  
  current:function() {
    return $$('#home_box li.current').first();
  },
  
  switchTo:function(name,instant) {
    this.killCurrent();
    var e = $('home_' + name)
    e.addClassName('current');
    if (e == this.lis.first())
      e.addClassName('first_current');
    else if (e == this.lis.last())
      e.addClassName('last_current');
    if (!instant)
      Effect.Appear(e.down('div.content'),{duration:0.5,queue:'end'});
    else
      e.down('div.content').show();
  },
  
  killCurrent:function() {
    var current = this.current();
    if (current) {
      current.removeClassName("current");
      current.removeClassName("first_current");
      current.removeClassName("last_current");
      Effect.Fade(current.down('div.content'),{duration:0.5, queue:'end'});
    }
  }
});

Event.addBehavior({'#home_box':HomeBox});