

var SMA		=
{
	subItensHeight:			30,
	menu_showDelay:			500,
	menu_hideDelay:			500,
	hideWait:				50,
	
	esmaecerFonte:			true,
	item_colorOut:			"rgb(255,255,255)",
	item_colorOutImediata:	"rgb(100,100,150)",
	item_colorOver:			"rgb(0,0,100)",
	item_animationDelayIn:	550,
	item_animationDelayOut:	800,
	
	moverItem:				true,
	layer_offsetX:			0,
	layer_offsetY:			1,
	item_offsetX:			6,
	item_offsetY:			0
};



SMA.ABA		= function()
{
	//Configurações
	var settings	=
	{
		onOver:			function( aba)
		{
			//acessa some uma vez
			if	( !aba.layer)
			{
				aba.layer	= jsRoger(aba).getLastSibling();
				aba.layer.style.display	= "";
				
				aba.layer.appendTo( document.body);
				
				aba.layer.onmouseover	= function()
				{
					if	( !this.aba.teste)
					{
						SMA.ABA.over( this.aba);
						aba.teste	= true;
					}
					if	( SMA.ABA.out.timeOut)
					{
						window.clearTimeout( SMA.ABA.out.timeOut);
					}
				}
				aba.layer.onmouseout	= function()
				{
					SMA.ABA.out( this.aba);
				}
				
				aba.layer.offsetX	= SMA.layer_offsetX;
				aba.layer.offsetY	= SMA.layer_offsetY;
				aba.layer.aba		= aba;
				
				
				//Assegura que o menu não ficará impune
				if	( !SMA.ABA.initialized)
				{
					SMA.ABA.initialized	= true;
					jsRoger(document.body).addEvent("mousedown", function()
														{
															if	( window.aba)
															{
																SMA.ABA.out( window.aba);
															}
														}
											);
				}
			}
			else
			{
				//o protótipo "Element.scrollFromObjRef" é diferente 
				aba.layer._SFOR_isMoving	= true;
			}

			
			if	( !aba.layer._SFOR_isMoving )
			{
				jsRoger.Element.SMP.object( aba.layer, aba, VERTICAL_ORIENTATION);
			}
			
			
			if	( jsRoger.browser.msie && jsRoger.browser.version<7 )
			{
				aba.layer.style.filter	= "";
			}
			
			aba.layer.parentNode.style.display	= "";
			
			
			if	( !aba.layer._widthSet && jsRoger.browser.msie6AndBellow)
			{
				for ( var i=0; i<aba.layer.childNodes.length; i++)
				{
					aba.layer.childNodes[i].style.float	= "left";
				}
				aba.layer.style.float	= "left";
				
				aba.layer.style.width	= (aba.layer.offsetWidth) + "px";
				
				for ( var i=0; i<aba.layer.childNodes.length; i++)
				{
					aba.layer.childNodes[i].style.float	= "";
					aba.layer.childNodes[i].style.width	= "100%";
				}
				aba.layer.style.float	= "";
				
			}
			aba.layer._widthSet		= aba.layer.offsetWidth;
			aba.layer.scrollFromObjRef( aba, VERTICAL_ORIENTATION, SMA.menu_showDelay, TRANSITION_ACUTE);
			
			aba.layer._moveOut		= false;
			
			// //pausa o bg effects
			// if	( window.marquee )
			// {
			// 	marquee.stop();
			// }
			window.aba	= aba;
		},
		onOut:		function( aba)
		{
			aba.layer.moveTo( null, -aba.layer.offsetHeight, SMA.menu_hideDelay, TRANSITION_CIRCUNFLEX);
			aba.layer._moveOut		= true;
			aba.layer.onMoveEnd		= function( ){ if ( this._moveOut){ this.parentNode.style.display	= "none";	}; this.onMoveEnd	= null;}
			
			aba.teste	= false;
			
			if	( window.item )
			{
				SMA.ITEM.out( window.item);
			}
			
			
		}
	}
	
	
	
	
	//Funções privadas. Seja cauteloso ao modificá-las.
	function over( item)
	{
		//Elimina o cronômetro do out.time, evitando que o método "out" seja chamado
		if	( this.out.timeOut)
		{
			window.clearTimeout( this.out.timeOut);
		}
		this.out.timeOut	= 0;
		
		//se houver algum menu já aberto/ativo, fazemo-lo retornar à posição original
		if	( this.lastItem )
		{
			this.onOut( this.lastItem);
			this.lastItem.isVisible	= false;
		}
		
		
		//se o item não estiver visível, tornemo-la visível
		if	( !item.isVisible)
		{
			this.onOver( item);
			this.lastItem	= item;
			item.isVisible	= true;
		}
	}
	function out( item)
	{
		if	( this.out.timeOut)
		{
			window.clearTimeout( this.out.timeOut);
		}
		this.out.timeOut	= out2.delay( this.hideWait, this, item);
	}
	//Private
	function out2( item)
	{
		this.onOut( item);
		
	}
	
	var r	= 
	({
		hideWait:		500,
		over:			over,
		out:			out
	});
	
	return r.merge( settings);
	
}();

SMA.ITEM	= function()
{
	//Configurações
	var settings	=
	{
		hideWait:		20,
		
		//dois métodos requeridos: onOver e onOut
		onOver:			function( item)
		{
			//se for a primeira vez...
			if ( !item.colorTrans )
			{
				item.colorTrans				= new jsRoger.Transition.SetColor( item);
				item.colorTrans.fps			= 10;
			}
			
			if ( SMA.esmaecerFonte )
			{
				item.style.color	= SMA.item_colorOutImediata;
				item.colorTrans.blend( new jsRoger.Color( SMA.item_colorOver), SMA.item_animationDelayIn);
			}
			else
			{
				item.style.color	= SMA.item_colorOver;
			}
			
			
			if ( SMA.moverItem )
			{
				jsRoger(item.firstChild).moveTo( SMA.item_offsetX, SMA.item_offsetY, TRANSITION_ACUTE, EFFECT_QUADRATIC, SMA.item_animationDelayIn);
				item.firstChild.TransitionMoveTo.fps	= 10;
			}
			
			//pausa o bg effects
			// if	( window.marquee)
			// {
			// 	marquee.stop();
			// }
			item.className			= "menuitens_over";
			window.item	= item
			
		},
		
		onOut:			function( item)
		{
			if ( item.colorTrans)
			{
				if ( SMA.esmaecerFonte )
				{
					item.colorTrans.blend( new jsRoger.Color( SMA.item_colorOut), SMA.item_animationDelayOut);
				}
				else
				{
					item.style.color	= SMA.item_colorOut;
				}
				
				if ( SMA.moverItem )
				{
					item.firstChild.moveTo( 0, 0, TRANSITION_ACUTE, EFFECT_QUADRATIC, SMA.item_animationDelayOut);
				}
			}
			item.className	= "menuitens_out";
		}
	}
	
	
	
	
	
	
	//Funções privadas. Seja cauteloso ao modificá-las.
	function over( item)
	{
		//Elimina o cronômetro do out.time, evitando que o método "out" seja chamado
		if	( this.out.timeOut)
		{
			window.clearTimeout( this.out.timeOut);
		}
		this.out.timeOut	= 0;
				
		//se houver algum menu já aberto/ativo, fazemo-lo retornar à  posição original
		if	( this.lastItem )
		{
			this.onOut( this.lastItem);
			this.lastItem.isVisible	= false;
		}
		
		
		//se o item não estiver visível, tornemo-la visível
		if	( !item.isVisible)
		{
			this.onOver( item);
			this.lastItem	= item;
			item.isVisible	= true;
		}
	}
	function out( item)
	{
		if	( this.out.timeOut)
		{
			window.clearTimeout( this.out.timeOut);
		}
		this.out.timeOut	= out2.delay( this.hideWait, this, item);
	}
	//Private
	function out2( item)
	{
		this.onOut( item);
		
	}
	
	if ( !settings.onOver )
	{
		alert( 'Método "onOver" faltando!');
	}
	if ( !settings.onOut )
	{
		alert( 'Método "onOut" faltando!');
	}
	
	var r	= 
	({
		hideWait:		500,
		over:			over,
		out:			out
	});
	
	return r.merge( settings);
	
}();





SMA.createAbas	= function()
{
	var menu		= jsRoger("menu_dropdown");
	var htmlString	= new String;
	var lastAba		= null;
	var oTR			= menu.rows[0];
	var floatLeft	= (jsRoger.browser.msie6AndBellow?"FLOAT:left; ":"");
	
	
	for ( var i=0, aba=null, label=null; i<SMA.abas.length; i++)
	{
		
		aba		= SMA.abas[i];
		
		
		if	( aba)
		{
			label	= aba[0];
			
			if ( label && label!="" && !oTR[label] )
			{
				var oTD		= document.createElement(TD),
					abaLink	= "SMA.OpenAba(this, '"+ (aba[4]||"") +"')";
				
				oTD.className	= "menuaba";
				
				oTR[label]	= oTD;
				
				oTD.onmouseout	= function(){ SMA.ABA.out(this.firstChild);		}
				oTD.onmouseover	= function(){ SMA.ABA.over(this.firstChild);	}
				
				
				
				oTD.htmlString	= 
					'<div class="menuabaOff" onclick="'+ abaLink +'" >'+ label +'</div>'+
					//'<table class="menuLayer" cellpadding="0" cellspacing="0" border="0" style="DISPLAY:none; " ><tbody><tr><td valign="top" ><div class="menuitensHolder">';
					'<div class="menuitensHolder" style="POSITION:relative; '+ floatLeft +' DISPLAY:none; " >';
				;
				oTD.bgPos		= 0;
				
				menu.rows[0].appendChild( oTD);
			}
			
			
			if	( aba[1] && label)
			{
				var urlIcon		= ( (aba[3] && aba[3].left(4)!="http")?	jsRoger.root+"../admin/site/":	"") + aba[3],
					link		= "SMA.OpenSubItem(this, '"+ (aba[2]||"") +"')";
				
				oTR[label].htmlString	+= 
					'<div onclick="'+ link +'" class="menuitens_out" style="POSITION:relative; WHITE-SPACE:nowrap; '+ (jsRoger.browser.msie6AndBellow?"FLOAT:left; ":"") +'CLEAR:both; BACKGROUND-POSITION:left '+ oTR[label].bgPos +'px; " onmouseover="SMA.ITEM.over(this)" onmouseout="SMA.ITEM.out(this)" >'+
						'<div style="POSITION:relative; WHITE-SPACE:nowrap; " '+ floatLeft +'>'+ aba[1] +'</div>'+
					'</div>';
				
				oTR[label].bgPos		-= SMA.subItensHeight;
				
			}
		}
	}
	
	for ( var i=0, cells=menu.rows[0].cells; i<cells.length; i++)
	{
		cells[i].htmlString	+= '</div>';
		
		cells[i].innerHTML	= cells[i].htmlString;
	}
	
}
SMA.OpenSubItem	= function( item, url)
{
	var label		= jsRoger(item).getFirstChild().innerHTML;
	
	window.location	= (url!=""? jsRoger.root +"../"+ url: "materia.php?subitem="+ escape( label) +"&aba="+ escape( jsRoger(aba).innerHTML));
}
SMA.OpenAba		= function( aba, url)
{
	var label	= jsRoger(aba).innerHTML;
	url			= url +"";
	
	window.location	= (url!=""? jsRoger.root +"../"+ url: jsRoger.root +"../pagina.php?aba="+ escape( label));
	
}


jsRoger.Include("Server.HttpRequest");
function LogOut( )
{
	window.location.href	= jsRoger.root +"../login/logout2.php";
}



jsRoger.Include("Element.addEvent");
jsRoger.Include("Function.delay");
jsRoger.Include("Element.DOM");
jsRoger.Include("Element.SMP.object");
jsRoger.Include("Element.styles");
jsRoger.Include("String.left");
jsRoger.Include("Transition.scrollFromObjRef");
jsRoger.Include("Transition.SetColor");
jsRoger.Include("Transition.moveTo");