var simpleTabMenu = Class.create(
{
	initialize: function(obj)
	{
		var self = this;
		this.obj = obj;
		this.isVisible = 0;
			
		this.menuLinks = $$(this.obj.menu);
		this.content = $$(this.obj.content);
		this.clearInterval = false;
			
		if(this.obj.autoStartFader){
			this.isFading = true;
			this.newTimer = setInterval(function(){
					
				var i = self.isVisible+1;
					
				if(i > (self.menuLinks.length -1)){
					i = 0;		
				}
					
				self.switchImage(i);	
			},self.obj.speed);
		}

		this.setObservers();
	},
	
	setObservers: function(){
	
		var self = this;
		
		this.menuLinks.each(function(elm,i){
			$(elm).observe('mouseover',function(ev){

				if(!self.clearInterval){
					clearInterval(self.newTimer);
					self.clearInterval = true;
				}
				self.switchImage(i);
				Event.stop(ev);
			});
		});
	},
	
	switchImage: function(i){
		
		var self = this;
	
		if(self.isVisible != i){
				
			self.content[i].appear({ duration: 0.3 , queue: { position: 'end', scope: 'change' }});
			self.content[self.isVisible].fade({ duration: 0.3 , queue: { position: 'end', scope: 'change' }});
			
			self.menuLinks[i].addClassName('active');
			self.menuLinks[self.isVisible].removeClassName('active');
			
			self.isVisible = i;
		}
	}

});

Event.observe(window, 'load', function()
{
	if($('faderContainer')){
		new simpleTabMenu(
		{
			menu: '.link',
			content: '.content',
			autoStartFader: true,
			speed: 7000
		});
	}
});