/**************************************************************

	Script		: Tabs
	Version		: 1.0
	Authors		: Leonard Martin
	Desc		: Hides/shows content based on tab-style navigation

**************************************************************/

//start menu class
var Tabs = new Class({

//implements
	Implements: [Options],
	
	//options
	options:{
		show:0,
		selected:'selected'
	},

	//initialization
	initialize: function(trigger,content,options)
	{	
		//set options
		this.setOptions(options);
		this.content = content;
		
		try {
			var hash = window.location.href.slice(window.location.href.indexOf('?') + 1).split('tab=');
			this.options.show = hash[0,1].split('#')[0];
		} catch (e) {
			
		}
		
		if (trigger!=null)
		{	
			this.triggers = trigger.getElements('a');
			this.triggers.each(function(a,n){
				a.addEvent(
					'click',
					function(e){
						e.preventDefault();
						e.stop();
						this.select(n);
					}.bind(this)// we want 'this' to be our Tabs object
				);
				if(a.getParent().hasClass(this.options.selected)) {
					this.options.show = n;
				}
			}.bind(this));
			this.select(this.options.show);
		}
	},
	
	select: function(n) {
		this.content.each(function(content,i){
			content.setStyle('display', (i==n)?'block':'none');
		});
		this.triggers.each(function(trigger,i){
			if(i==n) {
				trigger.getParent().addClass(this.options.selected);
			}
			else {
				trigger.getParent().removeClass(this.options.selected);
			}
		}.bind(this));
	}
	
});
