var Feature = Class.create({
				
				
	initialize: function(args) {
	
		if (args.tabs == null || args.tabContent == null) return;
		
		this.tabs = args.tabs;
		this.content = args.tabContent;
		this.prev = args.prevButton;
		this.next = args.nextButton;
		this.sContainer = args.selectorContainer;
		this.sclass = args.selectedClass;
		this.play = true;
		this.autoPlaySpeed = args.autoPlaySpeed;
		
		this.current = 0;
		this.total = Math.floor(this.tabs.size(), this.content.size());
		
		for (var i = 0; i < this.total; i++) {
			this.sContainer.insert('<a href="#">' + i + '</a>');	
		}
		
		this.selectors = this.sContainer.select('a');
		
		this.initTabs();

	},
	
	
	initTabs: function() {
	
		this.tabs.each(function(t, i) {
		
			t.id = i;
			t.cl = this;
			
			t.observe('click', function(e) {
				this.cl.getTab(this.id);
				this.cl.play = false;
			});
		
		}.bind(this));

		this.selectors.each(function(s, i) {
			
			s.id = i;
			s.cl = this;
			
			s.observe('click', function(e) {
				this.cl.getTab(this.id);
				this.cl.play = false;
			});
			
		}.bind(this));

		this.prev.observe('click', function(e) {
			this.getDir(-1);
			this.play = false;
		}.bind(this));
		
		this.next.observe('click', function(e) {
			this.getDir(1);
			this.play = false;
		}.bind(this));
		
		this.getTab(this.current);
		
		new PeriodicalExecuter(function(pe) {
			
			if (!this.play) {
				pe.stop();
				return;
			}
			
			this.getDir(1);
			
		}.bind(this), this.autoPlaySpeed);
	
	},
	
	
	getTab: function(id) {
	
		if (id >= this.total) return;
		
		this.content[this.current].removeClassName(this.sclass);
		this.tabs[this.current].removeClassName(this.sclass);
		this.selectors[this.current].removeClassName(this.sclass);
		
		this.content[id].addClassName(this.sclass);
		this.tabs[id].addClassName(this.sclass);
		this.selectors[id].addClassName(this.sclass);
		
		this.current = parseInt(id);
		
	},
	
	
	getDir: function(dir) {
	
		var id = this.current + dir;
		if (id < 0) id = this.total - 1;
		if (id > this.total - 1) id = 0;
		this.getTab(id);
		
	}
		
});