/**
 * @author juanlopez4691@gmail.com
 */

var subMnuAct = 0;


//Prepara las dos imágenes de un botón - mouseover/mouseout - y las devuelve en un array
function prepButtonImgs(pic) {
	var s = pic.split('images/');
	var imagesPath = s[0] + 'images/';
	var img = imagesPath + s[1];
	
	s = img.split('.');
	var imgR = s[0] + 'R' + '.' + s[1];
	
	return [img, imgR];
}


$(document).ready(function(){
	//Colapsa el menú de secciones
	$('.items-seccion').css('display', 'none');
	$('.seccion').css('cursor', 'pointer');
	
	$('.seccion').mouseover(function() {
		$(this).css('color', '#6980a5')
	});
	
	$('.seccion').mouseout(function() {
		$(this).css('color', '#214279')
	});
	
	$('.seccion').mousedown(function() {
		var items = $(this).children('.items-seccion')
		
		/*if ($(items).css('display') != 'none') {
			//$(items).css('display', 'none');
			$(items).hide('normal');
			subMnuAct = 0;
		} else {
			if (subMnuAct != 0) $(subMnuAct).hide('normal');
			$(items).show('normal');
			subMnuAct = items;
		}*/
		if ($(items).css('display') == 'none') {
			if (subMnuAct != 0) $(subMnuAct).hide('normal');
			$(items).show('normal');
			subMnuAct = items;
		}
	})
	
	//Abre la sección del menú correspondiente a la página donde estamos
	var seccion = $('#maincol').attr('class');

	if (seccion != '#inicio') {
		subMnuAct = $(seccion).children('.items-seccion');
		$(subMnuAct).css('display', 'block');
	}
	
	//Todos los enlaces con el atributo rel="externo" se abren en una nueva ventana, al estilo target="_blank"
	$('a[rel="externo"]').attr('target','_blank')
	
	//Todos los enlaces con el atributo rel="lightbox" hacen uso del plugin Lightbox
	$('a[@rel*=lightbox]').lightBox({
			txtImage: '',
			txtOf: '/'
		});
	
	//Prepara los botones de Guardias Telemáticas para cambiar imagen con el rollover
	var btn = $('#btnGTelem').attr('src');
	if (btn != undefined) {
		var btnGTelem = prepButtonImgs(btn);
		$('#btnGTelem').mouseover(function(){
			$(this).attr('src', btnGTelem[1]);
		})
		$('#btnGTelem').mouseout(function(){
			$(this).attr('src', btnGTelem[0]);
		})
	}
	
	//Prepara los botones de Guardias Hospitalarias para cambiar imagen con el rollover
	btn = $('#btnGHospi').attr('src');
	if (btn != undefined) {
		var btnGHospi = prepButtonImgs(btn);
		$('#btnGHospi').mouseover(function(){
			$(this).attr('src', btnGHospi[1]);
		})
		$('#btnGHospi').mouseout(function(){
			$(this).attr('src', btnGHospi[0]);
		})
	}
});