function tabs(controller,part,base_id,tab_top_count, tab_left_count,tab_bottom_count)
{
	this.base_id=base_id;
	this.sel_top=0;
	this.sel_left=0;
	this.sel_bottom=0;
	this.tab_top_cnt=tab_top_count;
	this.tab_left_cnt=tab_left_count;
	this.tab_bottom_cnt=tab_bottom_count;
	this.part=part;
	this.controller=controller;
	this.cols=5;
	this.rq_data=new Object();
	this.options=new Array();
	this.options_reset_id=-1;
	
	this.AddOption=function(name,type, value)
	{				
		this.options[this.options.length]=[name,type,value];
		if(type=='reset')
			this.options_reset_id=this.options.length-1;
	},
	this.set_option_reset=function(opt_n)
	{
	
		if(this.options[this.options_reset_id][2]==0)
		{
			for(var io=0;io<this.options.length;io++)
			{
				this.options[io][2]=0;
			}
			this.options[this.options_reset_id][2]=1;
		}		
		this.Request();
	},
	this.set_option_share=function(opt_n)
	{			
		this.options[opt_n][2]=1-this.options[opt_n][2];
		var act=0;
		for(var io=0;io<this.options.length;io++)
		{
			act+=this.options[io][2];
		}
		if(act==0)
			this.options[this.options_reset_id][2]=1;
		else
			this.options[this.options_reset_id][2]=0;
		this.Request();
	},	
	this.set_option_share_reset=function(opt_n)
	{
	
		var act=0;
		
		if(this.options[opt_n][2]==0)
		{
			for(var io=0;io<this.options.length;io++)
			{
				this.options[io][2]=0;
			}
			this.options[opt_n][2]=1;
			act=1;
		}
		else
		{
			this.options[opt_n][2]=0;
			for(var io=0;io<this.options.length;io++)
			{
				act+=this.options[io][2];
			}
		}
		if(act==0)
			this.options[this.options_reset_id][2]=1;
		else
			this.options[this.options_reset_id][2]=0;
			
		this.Request();
	},
	
	this.tabs_top_redraw=function()
	{
		for(var i=0;i<this.tab_top_cnt;i++)
		{
			if(i==this.sel_top)
				continue;
			var tab=document.getElementById(this.base_id+'_tt_'+i);
			if(tab)
				tab.className='tab_top';
		}
	
		var tab=document.getElementById(this.base_id+'_tt_'+this.sel_top);
		if(tab)
			tab.className='active_tab_top';
	
	},
	this.tabs_bottom_redraw=function()
	{
		for(var i=0;i<this.tab_bottom_cnt;i++)
		{
			if(i==this.sel_bottom)
				continue;
			var tab=document.getElementById(this.base_id+'_tb_'+i);
			if(tab)
				tab.className='tab_bottom';
		}
	
		var tab=document.getElementById(this.base_id+'_tb_'+this.sel_bottom);
		if(tab)
			tab.className='active_tab_bottom';
	
	},
	
	this.tabs_left_redraw=function()
	{
		for(var i=0;i<this.tab_left_cnt;i++)
		{
			if(i==this.sel_left)
				continue;
			var flt=document.getElementById(this.base_id+'_tl_'+i);
			if(flt)
				flt.className='tab_left';
		}
	
		var flt=document.getElementById(this.base_id+'_tl_'+this.sel_left);
		if(flt)
			flt.className='active_tab_left';
	
	},
	this.options_redraw=function()
	{
		var el=0;
		var re=/_act\b/;
		for(var io=0;io<this.options.length;io++)
		{
			el=document.getElementById(this.base_id+'_opt_'+this.options[io][0]);
			
			if(this.options[io][2])
			{
				if(!el.className.match(re))
					el.className+='_act';
			}
			else
			{
				if(el.className.match(re))
					el.className=el.className.replace(re,'');
			}
			//alert(el.className);
			
		}
	},	
	this.change_tab_top=function(tab_n, sw)
	{
		if(tab_n==this.sel_top)
			return;
						
		this.sel_top=tab_n;				
		this.Request(sw,'top');
	},
	this.change_tab_bottom=function(tab_n,sw)
	{
		if(tab_n==this.sel_bottom)
			return;
			
		this.sel_bottom=tab_n;				
		//this.sel_filter=0;
		this.Request(sw,'bottom');
	},	
	
	this.change_tab_left=function(left_n)
	{
		if(left_n==this.sel_left)
			return;
			
		this.sel_left=left_n;				
		
		this.Request();
	},	

	this.Request=function(sw,sw_parent)
	{
		var tabs_ptr=this;
		var st=document.getElementById(this.base_id+'_status');
		if(st)
		{
			
			st.style.display='inline';
		}
		
		var opt='';
		var hx='';
		for(var io=0;io<this.options.length;io++)
		{
				if(this.options[io][2])
				{
					opt+=this.options[io][0]+'_';
				}
				hx+=this.options[io][2];
		}
		
		var rq_index='rq'+this.part+this.sel_top+this.sel_left+this.sel_bottom+hx;
		//alert('/'+this.controller+'/get_sl_page/'+this.part+'/'+this.sel_top+'/'+this.sel_left+'/'+this.sel_bottom+'/'+opt+'/'+(new Date().getTime()));
		//alert(rq_index);
		if(tabs_ptr.rq_data[rq_index])
		{
			tabs_ptr.build_page(tabs_ptr.rq_data[rq_index]);
			tabs_ptr.tabs_top_redraw();
			tabs_ptr.tabs_left_redraw();
			tabs_ptr.tabs_bottom_redraw();
			tabs_ptr.options_redraw();
			if(sw)
			{
				tabs_ptr.show_group(sw_parent,sw);
			}
				
			if(st)
			{
				st.style.display='none';
			}
		}
		else
		{
			new Ajax.Request
			(
				'/'+this.controller+'/get_sl_page/'+this.part+'/'+this.sel_top+'/'+this.sel_left+'/'+this.sel_bottom+'/'+opt+'/'+(new Date().getTime()),
				{
					method		: 'get',
					asynchronous: true,
					evalScripts	: false,
					onSuccess	: function(request) 
					{
						var data=request.responseText.parseJSON();
						//alert(request.responseText);
						tabs_ptr.rq_data[rq_index]=data;
						tabs_ptr.build_page(data);
						tabs_ptr.tabs_top_redraw();
						tabs_ptr.tabs_left_redraw();
						tabs_ptr.tabs_bottom_redraw();
						tabs_ptr.options_redraw();
						if(sw)
						{
							tabs_ptr.show_group(sw_parent,sw);
						}
							
						if(st)
						{
							st.style.display='none';
						}
						
					}
				}
			)	
		}
	},
	this.build_page=function(data)
	{
		var text="<table class='sl_pp_data' border='0' cellspacing='0' cellpadding='0'>";
		var func="window.open(this.href,'_blank','width=800,resizable=yes,scrollbars=yes');return false;";
		var index=0;
		var sl_rows=Math.ceil(data.length/this.cols);
		for(var r=0;r<sl_rows;r++)
		{
			text+="<tr>";
			for(var c=0;c<this.cols;c++)
			{
				text+="<td>";
				index=r+sl_rows*c;
				if(data[index])
				{
					text+="<a href='"+data[index]['href']+"' target='_blank' onclick=\""+func+"\" >"+data[index]['title']+"<span class='cnt'>("+data[index]['cnt']+")</span></a>";
					
				}
				text+="</td>";
			}
			
			text+="</tr>";
		}
		text+="</table>";
		//alert(text);
		var page=document.getElementById(this.base_id+'_sl_page');
		if(page)
			page.innerHTML=text;
	
	},
	
	this.show_group=function(type,gp)
	{
		if(type=='top')
		{
			var tab=document.getElementById(this.base_id+'_tt');
			if(!tab)			
				return;
				
			var td=tab.getElementsByTagName('td');
			var id_group=this.base_id+'_tt_g'+gp;
			for(var i=0;i<td.length;i++)
			{
				if(td[i].id==id_group)
					td[i].style.display='';
				else if(td[i].id!='')
					td[i].style.display='none';	
			}
		}
		else if(type=='bottom')
		{
			var tab=document.getElementById(this.base_id+'_tb');
			if(!tab)			
				return;
				
			var td=tab.getElementsByTagName('td');
			var id_group=this.base_id+'_tb_g'+gp;
			for(var i=0;i<td.length;i++)
			{
				if(td[i].id==id_group)
					td[i].style.display='';
				else if(td[i].id!='')
					td[i].style.display='none';	
			}
		}
		
	}	
}


function redraw_container(cont_n,cont_cnt,obj_id)
{
	for(var i=0;i<cont_cnt;i++)
	{
		if(i==cont_n)
			continue;
		var cont=document.getElementById(obj_id+'_sl_container_'+i);
		if(cont)
			cont.style.display='none';

		var mgr=document.getElementById(obj_id+'_sl_mgr_'+i);
		if(mgr)
			mgr.className='sl_container';
			
	}
	
	var cont=document.getElementById(obj_id+'_sl_container_'+cont_n);
	cont.style.display='';

	var mgr=document.getElementById(obj_id+'_sl_mgr_'+cont_n);
	if(mgr)
		mgr.className='sl_active_container';
	
}



