var TabSystem = new Class({
	Implements: [Events,Options],
    options:{
			_parent:'tabSystem'
    },
    
    initialize: function(options){
    	this.setOptions(options);
		this._parent	 = this.options._parent;
		this._buttons	 = this._parent.getFirst().getChildren();
		this._containers = this._parent.getFirst().getNext().getChildren();
    	this.hideAllContentBlocks();
    	this.init();
    },
    
    init: function() {
		this._containers[0].setStyle('display','block');
    	this._buttons.each(this.clickTab.bind(this));
	},
    clickTab : function(el, i){
		if(el.hasClass('active')) {this.showContent(el, i);}
		el.addEvent('click', this.showContent.pass([el, i], this));
    },
    showContent : function(el, i){
    	
    	// just in case, remove any overlays from piece, should be a clear function //
    	if($('ingOverlay')){
	    	closeIngOverlayFromTab($('ingOverlay'));
    	}
    	// end //
    	
    	this.activeTab(el);
		this.onActive(el);
    	this.hideAllContentBlocks();
		this._containers[i].setStyle('display','block');
    },
    activeTab: function (el){
    	this._buttons.each(function(x){
    		x.removeClass('active');
    	});
		el.addClass('active');
    },
    onActive: function(el) {
		if(el.getElement('input')) {el.getElement('input').setProperty('checked', 'checked');}
	},
    hideAllContentBlocks: function (){
    	this._containers.each(function(el){
    		el.setStyle('display','none');
		});
    }
});
// TabSystem.implement(new Events, new Options);