﻿tsClass = null;
ts = new Class ({
	initialize: function () {
		this.togglers = $$( ".tabbed .tabs a" );
		this.togglersSpan = $$( ".tabbed .tabs a span" );
		this.blocks = $$( ".tabbed .page" );
		
		this.togglers.each( function( obj, n ) {
			obj.addEvent( 'click', function( e ) {
				e.preventDefault();
				this.setTab(n);
				this.switchPage(n);
			}.bind(this));
		}.bind(this));
		
		// Any default page?
		this.togglers.each( function(obj,n){
			if(obj.hasClass('default'))
				this.switchPage(n);
			else
				this.switchPage(0);
		}.bind(this));
	},
	
	setTab: function (tab) {
		this.togglers.each( function( obj, n ) {
			if( tab == n )
				obj.addClass( 'active' );
			else
				obj.removeClass( 'active' );
		});
	},
	
	switchPage: function (tab) {
		this.blocks.each( function( obj, n ) {
			obj.setStyle( 'display', 'none' );
		});
		
		if( this.blocks[tab] )
			this.blocks[tab].setStyle( 'display', 'block' );
	}
});

window.addEvent( 'domready', function () { tsClass = new ts() } );
