Suagencia.Classes.BaseDisplay = Class.create( {
	initialize: function( myID, vOptions ) {
		this.ID = myID ;
		if( vOptions )
			{this.Options = Suagencia.Displays.defaultOptions.merge( vOptions );}
		else
			{this.Options = Suagencia.Displays.defaultOptions.clone( );}

	
		if( this.Options.get("display") == undefined )
			{this.display = $(myID);}
		else
			{this.display = $(this.Options.get("display"));}


		this.group = this.Options.get("group");

		if( $(this.ID).hasClassName("ativo") ) 
		{
			this.status = "ativado";
			this.display.setStyle({"display":"block"});
		}
		else
		{
			this.status = "desativado";
			this.display.setStyle({"display":"none"});
		}

		if( this.Options.get("trigger") != undefined && this.Options.get("action") != undefined  )
		{
			var Triggers = this.Options.get("trigger")

			$$( Triggers ).each( function(t , index ) {
				var event = this.Options.get("action")[index]
				t.observe( event , this.toogle.bind( this ) )
				if( t.tagName.toUpperCase() == "A" && event == "click" )
					{
						if( t.readAttribute("href").indexOf("#") == 0 )
							{t.writeAttribute({"href":(Suagencia.selfLocation + t.readAttribute("href").slice(1))});}
						else
							{t.writeAttribute({"href":Suagencia.selfLocation});}
					}
			}, this );

		}

		Suagencia.Displays.items.set( this.ID , this );

		this.Options.unset("display")
		this.Options.unset("group")
		this.Options.unset("trigger")
		this.Options.unset("action")		

	},
	show: function() 
	{

		var vElement = null
		var Efeitos = new Array();

		if( this.status != "ativado" )
		{
			this.display.setStyle({"display":"block"});
			if( this.group != undefined )
				{vElement = Suagencia.Displays.hideGroup(this.group)}

			$(this.ID).addClassName("ativo");
			this.status = "ativado"
			if( this.efeito )
				{this.efeito.cancel()}

			if( vElement )
			{
				vElement.efeito = vElement._hideInternal()
				this.efeito = this.aparecer()

				if( this.efeito.options.sync == true || vElement.efeito.options.sync == true )
					{new Effect.Parallel([vElement.efeito,this.efeito]);}
				else
				{//alert(vElement.efeito.options.queue.scope + " / " + this.efeito.options.queue.scope )
				}

			}
			else 
			{ 
				this.efeito = this.aparecer();		
				if( this.efeito.options.sync == true )
					{new Effect.Parallel([this.efeito]);}
			}
			
			
		}
	},
	_hideInternal: function () {
		if( this.status != "desativado" )
		{
			if( this.efeito )
				{this.efeito.cancel()}
			this.status = "desativado"
			$( this.ID ).removeClassName("ativo");
			 return this.sumir();
		}
	},
	hide: function()
	{
		if( this.status != "desativado" )
		{
			if( this.efeito )
				{this.efeito.cancel()}
			this.status = "desativado"
			$( this.ID ).removeClassName("ativo");
			this.efeito = new Effect.Parallel( [this.sumir()] );
		}
	},
	toogle: function()
	{
		if( this.status == "ativado" )
			{this.hide();}
		else
			{this.show();}
	},
	aparecer: function ()
	{
		return new Effect.Opacity( this.display , { sync:true, from: 0, to: 1 , duration: 1 } )
	},
	sumir: function ()
	{
		return new Effect.Opacity( this.display , { sync:true, from: 1, to: 0 , duration: 1 } )
	}

});

Suagencia.Displays = {
	items: new Hash(),
	defaultOptions:$H({group:"default"}),
	hideGroup: function( vGrupo )
	{
		var vElement = null;

		var vArray = Suagencia.Displays.items.values()
		for (i = 0; i<vArray.length ; i++)
		{
			if(vArray[i].group == vGrupo && vArray[i].status == "ativado")
			{
				var vElement = vArray[i];
				break;
			}
		}
		
		return vElement

	},
	show: function( vID )
	{
		vElement = Suagencia.Displays.items.get( vID )
		if( vElement != undefined )
			{vElement.show()}
	}


}
