
var Tabs = new Class({
	Implements: [Options, Events],
	options: {
		btn_active_class: 'current'		
	},
	initialize: function(buttons, blocks, options) {
	
		this.setOptions(options);	
		
		if ($type(buttons) == 'array')
			this.buttons = container;
		else
			this.buttons = $$(String(buttons));
			
		if ($type(blocks) == 'array')
			this.blocks = blocks;
		else
			this.blocks = $$(String(blocks));
	
		
		if (this.buttons.length < 2) {		
			return false;
		}		
		
		this.initButtons();
		this.initBlocks();
		
		if (location.hash.indexOf('#') == 0) {
			start_hash = location.hash.substr(1);
		} else {
			start_hash = location.hash;
		}	
		
		this.current = 0;
		if (start_hash != '' && $defined(this.hashes[start_hash])) {
			this.open(this.hashes[start_hash]);
		}
		this.open(this.current);		
		
	},	
	
	initButtons: function() {
		this.buttons.each(function(button, index) {			
			button.addEvent('click', function(event) {
				event.preventDefault();				
				if (button.hash) {
					window.location = button.href;					
				}
				this.open(index);
			}.bind(this));
		}, this);
	},
	
	
	initBlocks: function() {		
		this.hashes = new Array();
		this.blocks.each(function(block, index){
			this.hashes[block.id] = index;
			block.setStyle('display', 'none');
		}, this);			
	},
	
	open: function(index) {
		if (this.current != index) {
			this.blocks[this.current].setStyle('display', 'none');
			this.buttons[this.current].removeClass(this.options.btn_active_class);
		}
		this.blocks[index].setStyle('display', 'block');
		this.buttons[index].addClass(this.options.btn_active_class);
		
		this.current = index;
		
	}	
	
});