CH.ns(function() {with(CH) {

	Tabs = Class.create({
		initialize: function(options) {
			this.setOptions(options); //initialize the default options

			this.tabs = $(this.options.tabContainer).childElements();

			var selectedTab = this.tabs[0];

			this.tabs.each(function(tab) {
				this.hideContent(tab);
				
				tab.href = 'javascript:void(0);';
				
				if(Element.hasClassName(tab, this.options.selectedClass))
					selectedTab = tab;
					
				Event.observe(tab, "click", this.tabClick.bindAsEventListener(this, tab));
				
			}.bind(this));
			
			this.selectTab(selectedTab);
		},
		
		getName: function(tab) {
			return tab.id.replace(this.options.tabPrefix,'');
		},
		
		tabClick: function(event, tab) {
			$$('#'+this.options.tabContainer+' .'+this.options.selectedClass).invoke('removeClassName', this.options.selectedClass);

			this.tabs.each(function(tab) {
				this.hideContent(tab);
			}.bind(this));
			
			this.selectTab(tab);
		},
		
		selectTab: function(tab) {
			tab.addClassName(this.options.selectedClass);
			this.showContent(tab);
		},
		
		showContent: function(tab) {
			var name = this.getName(tab);
			Element.show(this.options.contentPrefix + name);
		},
		
		hideContent: function(tab) {
			var name = this.getName(tab);
			Element.hide(this.options.contentPrefix + name);
		},
		
		setOptions: function (options) {
			this.options = {
				tabContainer: 'tabContainer',
				tabPrefix: 'tab',
				contentPrefix: 'content',
				selectedClass: 'tab_selected'
			};
			Object.extend(this.options, options || {});
		}
	});
	
}});