
$(function(){	
	// anulo los href vacios
	$('#secciones ul li a').click(function(){
		if ($(this).attr('href') == '#')
			return false;
	});

	// muestra el submenu
	$('#secciones ul li').hover(
		// hover
		function(){
			var position = $(this).position();
			var posicionDiv = $('div', this).position();
			
			var altoMenu = $(this).height();
			var altoWindow = $(window).height();
			var altoDiv = $('div', this).height();
			var divTop = $('div', this).offset().top;
			var posicionWindow = divTop - $(window).scrollTop();
			
			if((posicionWindow + altoDiv) > altoWindow)
			{
				// 72 = 22 (mendes_sup + mendes_inf) + 50 (mendes_zon1)
				$('div.mendes_zon1', this).css( { "height":(altoDiv - 72) + "px", "background":"transparent url(/images/capa_dos.png) repeat-y top left" } );
				$('div.mendes_zon2', this).css( { "height":"50px", "background":"transparent url(/images/capa_uno.png) no-repeat 0 -11px" } );
				
				// se sale por debajo, resitua la capa ¿26?
				$('div', this).css( { "left":215 + "px", "top":(posicionDiv.top - (altoDiv - 26 - altoMenu)) + "px" } );		
			} else {
				// 72 = 22 (mendes_sup + mendes_inf) + 50 (mendes_zon1)
				$('div.mendes_zon2', this).css( { "height":(altoDiv - 72) + "px" } );
				
				$('div', this).css( { "left":215 + "px", "top":posicionDiv.top + "px" } );				
			}
			
			if ($(this).hasClass('icolib')) {
				$(this).addClass('icolibacti');
			} else {
				if ($(this).hasClass('icoebo')) {
					$(this).addClass('icoeboacti');
				} else {
					if ($(this).hasClass('icomod')) {
						$(this).addClass('icomodacti');
					} else {
						if ($(this).hasClass('icomat'))
							$(this).addClass('icomatacti');
					} 
				} 
			}
			
		},
		// no hover
		function(){						
			// padding negativo de la capa -12
			$('div', this).css( { "left":-9000 + "px", "top":-12 + "px" } );
			
			// por si se ha resituado
			$('div.mendes_zon1', this).css( { "height":"50px", "background":"transparent url(/images/capa_uno.png) no-repeat 0 -11px" } );
			$('div.mendes_zon2', this).css( { "height":"auto", "background":"transparent url(/images/capa_dos.png) repeat-y top left" } );
			
			$(this).removeClass('icolibacti');
			$(this).removeClass('icoeboacti');
			$(this).removeClass('icomodacti');
			$(this).removeClass('icomatacti');
		}
	);
});

