var vLinks
var tAnimacao
var vCategorias


var objLista = {
	ListaOpen:null,
	AlturaFinal:0,
	ListaClose:null,
	vTimer:null,
	Run: function () {
		
		if( this.ListaOpen )
		{
			
			vAltura = parseInt( this.ListaOpen.style.height )
			this.ListaOpen.style.height = ( vAltura + 5 ) + "px"
			if( vAltura >= this.AlturaFinal )
				{
					this.ListaOpen.style.height = this.AlturaFinal + "px"
					this.ListaOpen  = null
				}
		}

		if( this.ListaClose )
		{
			vAltura = parseInt( this.ListaClose.style.height )
			if( vAltura <= 5 )
				{
					this.ListaClose.style.height = "0px"
					this.ListaClose.style.display = "none";
					this.ListaClose  = null;
				}
			else
				{this.ListaClose.style.height = ( vAltura - 5 ) + "px";}

		}

		if( this.ListaOpen || this.ListaClose )
			{this.vTimer = setTimeout("objLista.Run()" , 1)}
		else
		{
			clearTimeout( this.vTimer );
			this.vTimer = null;
		}

				
	}
}


document.observe("dom:loaded", configEventos );

function configEventos()
{
	vLinks = $$( "a[periodo]" )
	vLinks.each( function(s) {
		 s.observe( "click", abreEventos.bindAsEventListener( s ) );
		}
	);

	vCategorias = $$( "#lista-periodo > li > span" )
	
	vCategorias.each(
		function(s) {
			s.writeAttribute({ativo:"nao"} )
			vLista = s.next("div");
			vLista.style.display = "none";
			vLista.writeAttribute({altura:vLista.getHeight()} )
			vLista.setStyle( {overflow:"hidden",height:((vLista.getHeight()) + "px")} )
			s.observe( "click", abreLista.bindAsEventListener( s ) );		
		}
	);
}


function abreLista( caller )
{

	vSpan = Event.element(caller);

	if( vSpan.readAttribute("ativo") != "sim" && !objLista.vTimer  )
	{
		vCategorias.each(
			function(s) {
				if( s.readAttribute("ativo") == "sim" )
				{
					s.writeAttribute({ativo:"nao"} )
					vLista = s.next("div");
					objLista.ListaClose = vLista;					
					return true;
				}
			}
		)
		vSpan.writeAttribute({ativo:"sim"} )
		vLista = vSpan.next("div");	
		objLista.ListaOpen = vLista;
		objLista.AlturaFinal = vLista.readAttribute("altura");
		vLista.style.display = "";
		vLista.style.height = "0px";
		objLista.Run();
	}


}


function abreEventos( caller ) {
	vLink = Event.element(caller);

	activeBlock = vLink.readAttribute("periodo") 

	vLinks.each( 
		function(s) {
			if( s.readAttribute("periodo") == activeBlock)
				{s.addClassName("ativo");}
			else
				{s.removeClassName("ativo");}
				
			}		
	);

	vBlocks = $$( ".lista-eventos" )
	vBlocks.each(
		function( s ) {
			if( s.id == activeBlock )
				{s.style.display = "block";}
			else
				{s.style.display = "none";}
		}
	);
}