TSNSlider = function()
{
	var ths=this;
	ths.cursel=0;
	ths.menu_base="";
	ths.menu_cont="";
	ths.box_base="";
	ths.up_btn="";
	ths.down_btn="";
	ths.miny=0;
	ths.maxy=0;
	ths.max=0;
	ths.autotime=3000;				// Ogni quanto tempo cicla al successivo
	ths.autotimestop=10000;		// Quanto tempo sta fermo dopo un click (10 secondi)
	ths.noauto=false;
	ths.atout=null;
	ths.tint=null;
	ths.speed=700;
	ths.busy=false;
	
	ths.init= function(mbase,bbase,num,mcont,up,dn)
	{
		ths.max=num;
		ths.menu_base="#"+mbase;
		ths.box_base="#"+bbase;
		ths.menu_cont="#"+mcont;
		ths.maxy=$(ths.menu_cont).height()-280;
		ths.up_btn="#"+up;
		ths.down_btn="#"+dn;
		for (var k=0;k<ths.max;k++)
		{
			$(ths.menu_base+k).click(ths.menuclick);
		}
		$(ths.down_btn).click(ths.nxt);
		$(ths.up_btn).click(ths.prev);
		ths.tint=setTimeout(function(){ ths.cicle(); },ths.autotime);
	};
	
	ths.menuclick= function(evt)
	{
		if (!ths.busy)
		{
			clearTimeout(ths.tint);
			ths.noauto=true;
			ths.setsel(parseInt(evt.currentTarget.id.substring(6,7)));
		}
	};
	
	ths.setsel= function(nc)
	{
		if (nc!=ths.cursel)
		{
			clearTimeout(ths.tint);
			for (var k=0;k<ths.max;k++)
			{
				if (k==nc)
				{
					$(ths.menu_base+k).addClass("sel");
				}
				else
				{
					$(ths.menu_base+k).removeClass("sel");
				}
			}
			// Animage!
			tsn_an.goto(nc);
			// /Animage!
			ths.cursel=nc;
			ths.maketop(nc);
			if (!ths.noauto)
			{
				ths.tint=setTimeout(function(){ ths.cicle(); },ths.autotime);
			}
			else
			{
				ths.tint=setTimeout(function(){ ths.noauto=false; ths.cicle(); },ths.autotimestop);
			}
		}
	};
	
	ths.maketop= function(nc)
	{
		var he=0;
		for (var k=0;k<nc;k++)
		{
			he+=$(ths.menu_base+k).outerHeight();
		}
		he-=105;
		if (he<0) { he=0; }
		if (he>ths.maxy) { he=ths.maxy; }
		ths.busy=true;
		$(ths.menu_cont).stop().animate({'top':-he},ths.speed,function() { ths.busy=false; });
	};
	
	ths.nxt= function(evt)
	{
		if (!ths.busy)
		{
			clearTimeout(ths.tint);
			ths.noauto=true;
			var nxt=ths.cursel+1;
			if (nxt>(ths.max-1))
			{
				nxt=0;
			}
			ths.setsel(nxt);
		}
	};
	
	ths.prev= function(evt)
	{
		if (!ths.busy)
		{
			clearTimeout(ths.tint);
			ths.noauto=true;
			var nxt=ths.cursel-1;
			if (nxt<0) 
			{ 
				nxt=ths.max-1; 
			}
			ths.setsel(nxt);        
		}
	};        
	
	ths.cicle= function()
	{
		clearTimeout(ths.tint);
		if (!ths.busy)
		{
			if (!ths.noauto)
			{
				var nxt=ths.cursel+1;
				if (nxt>(ths.max-1))
				{
	  			nxt=0;
	  		}
				ths.setsel(nxt);
			}
		}
		else
		{
			ths.tint=setTimeout(function(){ ths.cicle(); },ths.autotime);
		}
	};
}; 
