document.observe('dom:loaded',function(e) {
	Tabber.init('div.grey_area');
	Tabber.init('ul.tabs');
});

var Tabber = {

	init: function(s) {
		els = $$(s+' a');
		y = false;
		els.each(function(el) {
			if(!y) {
				y = true;
				el.up().addClassName('current');
			}
			el.observe('click',function(f) {
				Event.stop(f);
				x = f.element();
				if(x.tagName == 'SPAN') x = x.up();
				x.up(1).childElements().each(function(a) {
					a.removeClassName('current');
				});
				x.up().addClassName('current');
			});
			el = el.next('a');
		});
	},

	select: function(s,i) {
		if(!i) i = 0; // Default, first one...
		$$(s+' li').each(function(el,j) {
			if(i == j) {
				el.addClassName('current');
			} else {
				el.removeClassName('current');
			}
		});
	},
	
	selected: function(s) {
		i = 0;
		li = $(s.replace('#','')).down();
		while(li && !li.hasClassName('current')) {
			li = li.next();
			i++;
		}
		return i;
	}

}