/**
*javascript class i4_Tab
* used by lib_Tab.php
* requires prototype
* 2009-12-01/ditoy/urs
* i4 lite project
*/
var i4_Tab = Class.create({
	name: '',
	tab_list: [],
	
	initialize: function(name) {
		this.tab_list = new Array(); // bug?
		
		if($(name)){
			this.name = name;
			$(name).descendants().each(function(item) {
				item.remove();
			});
		}
		
		return this;
	},
	
	add_item: function(title, name){
		if(this.name != ''){
			this.tab_list.push(name);
			$(this.name).appendChild(Builder.node('div', {
					className: 'tab_button',
					id: 'button_'+name
				},
				title
			));
						
			$('button_'+name).observe('click', (function(){
				this.show(name);	
			}).bind(this));
		}
		
		return this;
	}, // i4_Tap.add_item()
	
	show: function(which){
		if(this.name != ''){
			if (which == null) {
				which = this.tab_list[0];
			}
//			alert(this.tab_list);
			$A(this.tab_list).each(function(item) {
				$('button_'+item).removeClassName('tab_active');
			});
			$('button_'+which).addClassName('tab_active');
			
			$A(this.tab_list).each(function(item) {
				$(item).hide();
			});
			$(which).show();
		}
		
		return this;
	} // i4_Tap.show()
});
