/* javascipt con mootools */
var MenuIdDivElem_array = new Array();
var VerticalSlide_array = new Array();
var hilo = null;

window.addEvent('domready', function() {
	mostrarMenuIdDivElem('menu_izq_arriba');
	recopilarMenuIdDivElem('menu_izq_arriba');
	anadirEventosToMenuIdDivElem();
	mostrarItemMenuSiLocation();
});

function mostrarItemMenuSiLocation( ) {
	MenuIdDivElem_array.each(function(id_div, index){
		id_a=id_div+'_a';
		$(id_div).getElements('a').each(function(item, jindex){
			if ((''+document.location).indexOf(''+item.getProperty('href'))!=-1) {
				desplegarMenuIdDivElem($(id_a), VerticalSlide_array[index] );
			}
		});
	});
	return;
}

function mostrarMenuIdDivElem(_id_menu ) {
	$(_id_menu).getElements('a').each(function(element, index){
		if (element.hasClass('a_desplegar')) {
			element.getNext('div').removeClass('oculto');
		}
	});
}

function anadirEventosToMenuIdDivElem( ) {
	MenuIdDivElem_array.each(function(id_div, index){
		id_a=id_div+'_a'; 
		eventoMenuReplegarDesplegar ( $(id_a), VerticalSlide_array[index] );
	});
	return;
}

function eventoMenuReplegarDesplegar( element_a, verticalSlide ) {
	element_a.addEvent('click', function(e) {
		e.stop();
		hilo = null;
		if (element_a.hasClass('replegado')) {
			element_a.removeClass('replegado');
			element_a.addClass('desplegado');
			verticalSlide.slideIn();
			replegarMenuIdDivElemDesplegados( element_a.getProperty('id') );
		} else {
			element_a.removeClass('desplegado');
			element_a.addClass('replegado');
			verticalSlide.slideOut();
		}
	});
}

function replegarMenuIdDivElemDesplegados( id_a_desplegado ) {
	MenuIdDivElem_array.each(function(id_div, index){
		id_a=id_div+'_a';
		if (id_a!=id_a_desplegado) {
			replegarMenuIdDivElem( $(id_a), VerticalSlide_array[index] );
		}
	});
	return;
}

function replegarMenuIdDivElem( element_a, verticalSlide ) {
	if (element_a.hasClass('desplegado')) {
		element_a.removeClass('desplegado');
		element_a.addClass('replegado');
		verticalSlide.slideOut();
	}
	return;
}

function desplegarMenuIdDivElem( element_a, verticalSlide ) {
	if (element_a.hasClass('replegado')) {
		element_a.removeClass('replegado');
		element_a.addClass('desplegado');
		verticalSlide.slideIn();
	}
	return;
}

function ocultarDivs( ) {
	MenuIdDivElem_array.each(function(id, index){
		var myVerticalSlide = new Fx.Slide(id).hide();
	});
	return;
}

function recopilarMenuIdDivElem(_id_menu ) {
	$(_id_menu).getElements('a').each(function(element, index){
		if (element.hasClass('a_desplegar')) {
			id_div = element.getNext('div').getProperty('id');
			MenuIdDivElem_array.include(id_div);
			var href_hijo = element.getNext('a').getProperty('href');
			if ((''+document.location).indexOf(''+href_hijo)!=-1) {
				VerticalSlide_array.include(new Fx.Slide(id_div).slideIn());
				element.removeClass('replegado');
				element.addClass('desplegado');
			} else {
				VerticalSlide_array.include(new Fx.Slide(id_div).hide());
			}
		}
	});
	return;
}

