function menu_open_close(submenu) {
	if (submenu.nextSibling.style.display=='none') {
		$(submenu.nextSibling).slideToggle(100);
		submenu.className='menu_expand';
	}
	else {
		submenu.className='menu_collapse';
		$(submenu.nextSibling).slideToggle(100);		
	}
}

function show_img(image,url_embed,galeria) {
	// Busca la mytable que contiene a esta galería buscando la cadena "_lt_" en los class de elementos padre a la imagen
	mytable=$(galeria).parents("[class*=_lt_]");

	// Miramos a qué elemento del grupo mytable corresponde la imagen clicada para posicionar el navegador de imágenes a partir de esta
	$(mytable).find('img').each(function(index) {
		if (this==galeria)
			elemento=index;//alert("found!"+index);
	});

	// Crea el DIV contenedor de la imagne ampliada
	var divTag = document.createElement("div");
	divTag.id = "shadow";
	divTag.style.opacity=0;
	divTag.style.zIndex=50;	
	var isIE = /*@cc_on!@*/false;
	
	if (isIE) {
		divTag.style.position ="absolute";
		divTag.style.top=document.body.scrollTop;
	}
	else {
		divTag.style.position ="fixed";
		divTag.style.top="0";
	}
 
	divTag.style.width = "100%";
	divTag.style.height = "100%";
	divTag.style.left = "0";

	divTag.innerHTML="<div class='slideshow_panel'><span class='slideshow_button' id='boton_prev'><</span><span class='image_close' onclick='img_close()'>EXIT</span><span class='slideshow_button' id='boton_next'>></span></div>";
	document.body.appendChild(divTag);

	$("#shadow").fadeTo("fast","0.8");
			
	var divTag = document.createElement("div");
	divTag.id = "imagen_content";
	divTag.style.zIndex=50;
	if (isIE) {
		divTag.style.position = "absolute";
		divTag.style.top=document.body.scrollTop+50;
	}
	else {
		divTag.style.position = "fixed";
	
		if (!url_embed)	 
			divTag.style.top="50%";
		else
			divTag.style.top="25";
						
		divTag.style.display="none";	 
	}

	if (!url_embed)	 
		divTag.style.left="50%";
	 
	if (url_embed) {
		divTag.style.width = "100%";
		divTag.style.left = "0";
	}
	 
	document.body.appendChild(divTag);

	if (!url_embed) {
		divTag.innerHTML = "<img id='img_big' onload='img_center()' class='image_big' onclick='img_close()' src='"+image+"'>";
		divTag.onclick=img_close;
	}
	else {	 
	 	$.ajax({
			url: url_embed,success:
			function(datos) {
				divTag.innerHTML=datos;
				$("#imagen_content").fadeIn("fast");
			}
		});
	}
	init_slideshow_botons(mytable,elemento);
}

function init_slideshow_botons(mytable,puntero) {
	if (!puntero>0)
		var puntero=0;

    $("#boton_next").click(function () {
		if ($(mytable).find('img').eq(puntero+1).length > 0)
			puntero++;
		slideshow_changeimage(mytable,puntero);
    });

    $("#boton_prev").click(function () {
		if (puntero>0)
			puntero--;
		slideshow_changeimage(mytable,puntero);
    });
}

function slideshow_changeimage(mytable,puntero) {
	var title = $(mytable).find('img').eq(puntero).attr("alt");
	var thumb_path = $(mytable).find('img').eq(puntero).attr("src");
	var filename=thumb_path.replace(/\\/g,'/').replace( /.*\//, '' );
	var path=thumb_path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
	$("#img_big").attr("src",path+"/big_"+filename);
}

function img_center() {
	img_width=document.getElementById("img_big").width;
	img_height=document.getElementById("img_big").height;
	document.getElementById("imagen_content").style.marginLeft=img_width/-2+"px";
	var isIE = /*@cc_on!@*/false;
	if (!isIE)
	document.getElementById("imagen_content").style.marginTop=img_height/-2+"px";
	$("#imagen_content").fadeIn("fast");
}

function img_close() {
	document.body.removeChild(document.getElementById("shadow"));
	document.body.removeChild(document.getElementById("imagen_content"));
}
				 
function date_validate(field) {
/*
	fecha=field.value;
	campo=field.name;
	var error_msg='';
	var formato=/^\d{2}\-\d{2}\-\d{4}$/
	if (!formato.test(fecha))
		error_msg="Formato de fecha no válido (dd-mm-yyyy).";
	else {
		var dayfield=fecha.split("-")[0]
		var monthfield=fecha.split("-")[1]
		var yearfield=fecha.split("-")[2]
		var dayobj = new Date(yearfield, monthfield-1, dayfield)
		
		if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
			error_msg="Fecha incorrecta.";
	}

	if (error_msg!='') {
		$("#"+campo+"_info").fadeOut("normal");		
		document.getElementById(campo+"_info").innerHTML=error_msg;
		$("#"+campo+"_info").fadeIn("normal");
	}
	else
		$("#"+campo+"_info").fadeOut("normal");
*/		
}

// jqueryUI
$(function() {
	$(".datepicker").datepicker({
		changeMonth: true,
		changeYear: true,
		dateFormat: 'dd-mm-yy',
		showOn: 'button',
		firstDay:1,		
		buttonImage: 'http://gt.dieyes.com/basic/gt/images/calendar.gif', buttonImageOnly: true
	});
});				 

