/*
 * Fabtabulous! Simple tabs using Prototype
 * http://tetlaw.id.au/view/blog/fabtabulous-simple-tabs-using-prototype/
 * Andrew Tetlaw
 * version 1.1 2006-05-06
 * http://creativecommons.org/licenses/by-sa/2.5/
 *
 * Edited by Mark Kroon to use specific HTML tags of Biopunt
 */
var Fabtabs = Class.create();

// simpele debug functie om een object te tonen
function alertObject( obj ) {
	var message = "object type:" + typeof(obj) + "\n----------------\n";
	for( var i in obj ) {
		message += i + "=" + obj[i] + "\n";
	}
	alert( message );
}

Fabtabs.prototype = {
	initialize : function(element) {
		this.element = $(element);
		var options = Object.extend({}, arguments[1] || {});
		// get all child tabs using a css selector. for example "ul#tabs a.tabheader".
		// note that all tab sets on a page should have different id's for the ul element!
		this.menu = $A($$( "ul#"+this.element.identify() + ' a.tabheader'));
		this.show(this.getInitialTab());
		this.menu.each(this.setupTab.bind(this));
	},
	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), elm);
	},
	hide : function(elm, clickedElm) {			
		$($(elm).parentNode).removeClassName('active');
		$(elm).parentNode.addClassName('noborder');
		$(this.tabID(elm)).removeClassName('content_tabs_active');		
	},
	show : function(elm) {
		$($(elm).parentNode).removeClassName('noborder');
		$(elm).parentNode.addClassName('active');
		$(this.tabID(elm)).addClassName('content_tabs_active');

	},
	tabID : function(elm) {
		return elm.href.match(/#(\w.+)/)[1];
	},
	getInitialTab : function() {
		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();
		}
	}
}

Event.observe(window,'load',
	function(){ 
		$$('.tabs').each(function(elm){
			new Fabtabs(elm); 
		})
		},false);


