/*
 * Fabtabulous! Simple tabs using Prototype
 * http://tetlaw.id.au/view/blog/fabtabulous-simple-tabs-using-prototype/
 * Andrew Tetlaw
 * version 2 2008-08-10
 * http://creativecommons.org/licenses/by-sa/2.5/
 */
var Fabtabs = Class.create({
	initialize : function(element) {
		this.element = $(element);
		//var options = Object.extend({}, arguments[1] || {});
		if (this.element) {
			this.menu = $A(this.element.getElementsByTagName('a'));
			this.menu.each(this.setupTab.bind(this));
		}

	},
	setupTab : function(elm) {
		Event.observe(elm,'mouseover',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-tab');
		$(this.tabID(elm)).removeClassName('active-tab-body');
	},
	show : function(elm) {
		$(elm).addClassName('active-tab');
		$(this.tabID(elm)).addClassName('active-tab-body');
	},
	tabID : function(elm) {
		return 'tab' + elm.id.match(/tabNav([0-9]+)/)[1];
	}

});

document.observe("dom:loaded", function(){ new Fabtabs('tabNav'); });