var AjaxTabs = Class.create();
AjaxTabs.prototype = {
		 
	initialize : function(element) {
		this.element = $(element);
		var options = Object.extend({}, arguments[1] || {});
		this.menu = $A(this.element.getElementsByTagName('a'));
		this.menu.each(this.setupTab.bind(this));
		this.on(this.getInitialTab());
	},
	
    setupTab : function(elm) {
		//$(this.tabID(elm)).hide();
		Event.observe(elm,'click',this.activate.bindAsEventListener(this),false)
	},
	
    activate :  function(ev) {
		var elm = Event.findElement(ev, "a");
		Event.stop(ev);
		this.on(elm);
		this.menu.without(elm).each(this.off.bind(this));
	},
	
    getInitialTab : function() {
        /* checks urls for anchor sign
		if(document.location.href.match(/#(w.+)/)) {
               var loc = RegExp.$1;
                var elm = this.menu.find(function(value) { return value.href.match(/#(w.+)/)[1] == loc; });
                return elm || this.menu.first();
        } else {
            return this.menu.first();
        }
        */
		return this.menu.first();
	},
	
    on : function(elm) {
		$(elm).addClassName('active-tab');
		$(this.tabID(elm)).addClassName('active-body');
		$(this.tabID(elm)).show();
		
	},
	
    off : function(elm) {
		$(elm).removeClassName('active-tab');
        $(this.tabID(elm)).removeClassName('active-tab-body');
        $(this.tabID(elm)).hide();
	},
	
    tabID : function(elm) {
        //alert("elm href: " + elm.href);
		return elm.href.match(/#(\.?\w.+)/)[1];
	}
	
	
}
