// crea una tabla de imagenes basadas en un array ImageList y un nº de columnas
// ImageList = array {"path/img1.jpg","path/img2.jpg"}
// ncol = 3
function galeria(ImageList, ncol, ajustarancho)
{
	var anchotabla;
	var anchocelda;

	// a pienrel. En explorer no acaba de funcionar bien con %, así que toca calcular los píxeles.
	// anchotabla = screen.width - 50 - 200 - 200 -50 - 200;
	anchotabla = 600;
	// o un valor a boleo y que sea lo que Dios quiera
	if (anchotabla<0)
		anchotabla = 200;

	anchocelda = anchotabla / ncol;

	document.write("<table style=\"border-collapse: collapse\" width=\"" + anchotabla + "\"><tr>");

	for (var i = 0; i<ImageList.length; i++)
	{
		if (ajustarancho == true)
			document.write("<td><a href=\"verimagen.html?" + ImageList[i] + "\" target=\"_blank\"><img src=\"" + 
				ImageList[i] + "\" border=\"0\" width=\"" + anchocelda + "px\"/></a></td>");
		else
			document.write("<td><a href=\"verimagen.html?" + ImageList[i] + "\" target=\"_blank\"><img src=\"" + 
				ImageList[i] + "\" border=\"0\"/></a></td>");
			
		// cada ncol columnas hace una nueva fila
		if (!((i+1) % ncol))
			document.write("</tr><tr>");
	}
	
	document.write("</tr>");
	document.write("</table>");
}


// No intenta ajustar los anchos, simplemente coge las fotos que le diga
// Requiere de ajuste manual
function galeriameteo(ImageList, ncol)
{
	
	// document.write("<table style=\"border-collapse: collapse\" width=\"100%\"><tr>");
	document.write("<table width=\"100%\"><tr>");

	for (var i = 0; i<ImageList.length; i++)
	{
		document.write("<td align='center'><img src=\"" + ImageList[i] + "\" border=\"0\"/></td>");
		//document.write("<td>hola</td>");
			
		// cada ncol columnas hace una nueva fila
		if (!((i+1) % ncol))
			document.write("</tr><tr>");
	}
	
	document.write("</tr>");
	document.write("</table>");
}


function ajusteVertical(altoTabla)
{
	var alto;
	
	alto = (devuelveAltoVentana() - altoTabla) / 2;

	// ajustes manuales
	alto = alto - 10;

	if (alto>10)
		creaFilaAlto(alto);
		
	
//	alert(document.body.offsetHeight);
/*
var alto;
	alto = (screen.height - altoTabla - 16)/4;
	document.write("<table border=\"1px\" width=\"100%\"><tr height=\"" + alto + 
				   "px\"><td></td></tr></table>");
*/
}

function creaFilaAlto(alto)
{
	document.write("<tr height=\"" + alto + "px\"><td>&nbsp;</td></tr>");
}

function devuelveAltoVentana()
{
	var y;
	if (self.innerHeight) // all except Explorer
	{
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		y = document.body.clientHeight;
	}	

	return y;
}

function devuelveAnchoVentana()
{
	var x;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
	}	

	return x;
}


/*
// Cómo saber alto y ancho de las ventanas en todos los browsers
// http://www.quirksmode.org/viewport/compatibility.html
function a()
{
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}	
	alert("x: " + x + 
		  "y: " + y);
}
*/

