window.addEvent('domready',function(){
	var transition = {
		buttons:$('home-menu').getElements("a"),
		container:$('banner-main'),
		banners:$('banner-main').getChildren(),
		
		current:0,
		
		autoID:null,
		
		changeTo:function(i){
			if(i==this.current) return;
			this.buttons[this.current].tween('color','#ffffff');
			this.buttons[i].tween('color','#0D5141');
			this.banners[i].fade('hide');
			for(j=0;j<this.banners.length;j++){
				if(this.current == j){
					this.banners[j].setStyle('z-index',1);
				} else if(i==j){
					this.banners[j].setStyle('z-index',2);
				} else {
					this.banners[j].setStyle('z-index',0);
				}
			}
			this.banners[i].fade('in');
			this.current = i;
		},
		setup:function(){
			for(i=0;i<this.buttons.length;i++){
				this.buttons[i].addEvent('mouseenter',this.changeTo.bind(this,i));
				
				this.buttons[i].addEvent('mouseenter',this.disableAuto.bind(this));
				this.buttons[i].addEvent('mouseleave',this.enableAuto.bind(this));
				this.banners[i].addEvent('mouseenter',this.disableAuto.bind(this));
				this.banners[i].addEvent('mouseleave',this.enableAuto.bind(this));
			}
			
			this.buttons[this.current].tween('color','#0D5141');
			this.banners[this.current].setStyle('z-index',2);
			this.enableAuto();
		},
		autoChange:function(){
			this.changeTo((this.current+1)%this.buttons.length);
		},
		enableAuto:function(){
			if(this.autoID==null){
				this.autoID = this.autoChange.periodical(3000,this);
			}
		},
		disableAuto:function(){
			$clear(this.autoID);
			this.autoID = null;
		}
	}
	transition.setup();
});
