//Navegador
Event.observe(window, 'load', function(){
	$$('.navButton').each(function(nb){
		$(nb).navEffects = new Array();
		
		//Menus
		//MouseOver
		Event.observe(nb,'mouseover',function(){
			var effect, n;
			
			while( n = $(nb).navEffects.pop() )
				n.cancel();
			
			effect = new Effect.Morph(this,{
				style: 'background-color:#34BABF;',
				duration: 0.25
			});
			
			$(nb).navEffects.push(effect);
		});
		//MouseOut
		Event.observe(nb,'mouseout',function(){
			var effect, n;
			
			//Cancel Effects
			while( n = $(nb).navEffects.pop() )
				n.cancel();
			
			effect = new Effect.Morph(this,{
				style: 'background-color:#53FFFF;',
				duration: 0.25,
				delay:0.25
			});
			$(nb).navEffects.push(effect);
		});
	});
	
	//submenus
	$$('.navSubmenu').each(function(s){
		//inicializar la altura
		$(s).altura = $(s).style.height;
		
		//efectos
		s.effects = new Array();
		
		Event.observe($(s),'mouseout',function(){
			s.effects.push( new Effect.BlindUp(s, {duration:0.25,delay:0.25}) );
			s.padre.navEffects.push( 
				new Effect.Morph(s.padre,{
					style: 'background-color:#53FFFF;',
					duration: 0.25,
					delay:0.25
				})
			);
		});
		Event.observe($(s),'mouseover',function(){
			var e;
			while( e = s.effects.pop() ){
				e.cancel();
			}
			while( e = $(s).padre.navEffects.pop() ){
				e.cancel();
			}
			s.style.height = s.altura;
		});
	});
});

function desplegar(obj, padre){
	var e;
	
	$(obj).style.left = $(padre).positionedOffset()[0] + 'px';
	
	//Cancel Effects
	$$('.navSubmenu').each(function(s){ //cerrar submenus
		if( $(s).id != $(obj).id ){
			s.effects.each(function(e){
				e.cancel();
			});
			s.effects.push(
				new Effect.BlindUp(s,{duration:0.1})
			);
		}
	});
	
	while( e = $(obj).effects.pop() ){
		e.cancel();
	}
	$(obj).style.height = $(obj).altura;
	if(!$(obj).visible())
		new Effect.BlindDown($(obj), {duration:0.25});
	
	$(obj).padre = padre;
}
function colapsar(obj){
	$(obj).effects.push( new Effect.BlindUp($(obj), {duration:0.25,delay:0.25}) );
}