if(typeof(Control) == "undefined")
	var Control = {};

Control.Tabs = Class.create();

Control.Tabs.prototype = {
	
	initialize : function(element) {
		this.element = $(element);
		var options = Object.extend({}, arguments[1] || {});
		this.menu = $A(this.element.getElementsByTagName('a'));
		this.menu.each(this.hide.bind(this));
		this.menu.each(this.setupTab.bind(this));
		this.getInitialTab();
	},
	
	setupTab: function(elm) {
		Event.observe(elm,'click',this.activate.bindAsEventListener(this),false)
	},
	
	activate:  function(ev) {
		var elm = Event.findElement(ev, "a");
		Event.stop(ev);
		this.show(elm);
		this.menu.without(elm).each(this.hide.bind(this));
	},
	
	hide : function(elm) {
		$(elm).removeClassName('active');
		$(this.tabID(elm)).hide();
	},
	
	show : function(elm) {
		$(elm).addClassName('active');
		new Effect.Appear(this.tabID(elm),{duration:1, from:0, to:1.0});
		//$(this.tabID(elm)).show();
	},
	
	tabID : function(elm) {
		return elm.href.match(/#(\w.+)/)[1];
	},
	
	getInitialTab : function() {
		var initialTab = "";
		if(document.location.href.match(/#(\w.+)/)) {
			var loc = RegExp.$1;
			var elm = this.menu.find(function(value) { return value.href.match(/#(\w.+)/)[1] == loc; });
			initialTab = elm || this.menu.first();
		} 
		else {
			initialTab = this.menu.first();
		}
		
		this.show(initialTab);
		
		if($(initialTab).readAttribute('rel'))
			eval($(initialTab).readAttribute('onclick'));
	}
}