var desplegada=0;
var popup;

var ventana;
var abierto=0;

function siguiente()
{
	if(indice+2>=fotos.length)
		return indice;
	else
		return indice+2;
		
}

function anterior ()
{
	if(indice-2<0)
		return 0;
	else
		return indice-2;
}

function getCSSbyBrowser(css)
{
	var nombre = navigator.appName;
	if (nombre == "Microsoft Internet Explorer")
		document.write("<LINK rel='stylesheet' type='text/css' href='css/"+css+".css'>");
	else
		document.write("<LINK rel='stylesheet' type='text/css' href='css/"+css+"_firefox.css'>");
}

function showGallery(pais)
{
	var html = '';
	var click_text = '';
	var galeria = new getObj('multigallery');
	var galeria_contador = new getObj('gallery_nav');
	var txtcomentario = '';
	switch(pais)
	{
		case 'gz':
		case 'es':
			click_text = "Click para ampliar";
			break;
		case 'uk':
			click_text = "Click to enlarge";
			break;
		case 'de':
			click_text = "Zum Vergrößern klicken";
			break;
	}
	
	if(comentario[indice]!=undefined) 
		txtcomentario = comentario[indice];
	else
		txtcomentario = '';
		
	if(txtcomentario!='') 
		html += '<div class="comentario">'+txtcomentario+'</div>';
	else
		html += '<div class="comentario" style="background:none">&nbsp;</div>';
		
	html += '<img style="margin-left:13px;width:175px" src="galeria/'+fotos[indice]+'"> ';
	html += '<img class="sombra" src="img/solapa.gif"> ';
	if(zoom[indice]==undefined)
		html += '<img class="zoom" alt="'+click_text+'" style="cursor:pointer" onclick="viewPhoto(\'galeria/zoom/'+fotos[indice]+'\',\''+txtcomentario+'\',\''+pais+'\')" src="img/zoom.gif">';
	//html += '<br />';
	if(fotos[indice+1]!=undefined)
	{
		if(comentario[indice+1]!=undefined) 
			txtcomentario = comentario[indice+1];
		else
			txtcomentario = '';
			
		if(txtcomentario!='') 
			html += '<div class="comentario">'+txtcomentario+'</div>';
		else
			html += '<div class="comentario" style="background:none">&nbsp;</div>';
			
		html += '<img style="margin-left:13px;width:175px" src="galeria/'+fotos[indice+1]+'"> ';
		html += '<img class="sombra" src="img/solapa.gif"> ';
		if(zoom[indice+1]==undefined)
			html += '<img class="zoom" alt="'+click_text+'" style="cursor:pointer" onclick="viewPhoto(\'galeria/zoom/'+fotos[indice+1]+'\',\''+txtcomentario+'\',\''+pais+'\')" src="img/zoom.gif">';
	}
	else
		html += '<div style="height:144px"></div>';
	galeria.obj.innerHTML = html;
	galeria_contador.obj.innerHTML = (indice/2)+1;
	 
	 
}

function openPopup(url)
{
	var ancho;
	var alto;
	
	ancho=700;
	alto=600;
	
	if(desplegada==1){popup.close();popup=null;desplegada=0}
	popup=window.open(url,'','width='+ancho+',height='+alto+',resizable=no,scrollbars=yes,toolbars=no');
	desplegada++;
}

function openPopup2(url,ancho,alto)
{
	if(desplegada==1){popup.close();popup=null;desplegada=0}
	popup=window.open(url,'','width='+ancho+',height='+alto+',resizable=no,scrollbars=yes,toolbars=no');
	desplegada++;
}


function viewPhoto(foto,titulo,idioma)
{
	if(titulo=='') 
	{
		switch(idioma)
		{
			case 'es': titulo='Galería'; break;
			case 'gz': titulo='Galería'; break;
			case 'uk': titulo='Gallery'; break;
			case 'de': titulo='Bildergalerie'; break;
		}
	}
	var cerrar=''
	switch(idioma)
	{
		case 'es': cerrar='Cerrar esta ventana'; break;
		case 'gz': cerrar='Pechar esta ventá'; break;
		case 'uk': cerrar='Close this window';break;
		case 'de': cerrar='Schließen Sie dieses Fenster';break;
	}
	if(abierto==1){ventana.close();ventana=null;abierto=0}
	ventana=window.open(foto,'ventana','width=10,height=10,resizable=no,scrollbars=no')
	ventana.document.write('<html><head><title>'+titulo+'</title></head><body style="background:#999900;overflow:hidden" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no" onUnload="opener.abierto=0">');
	ventana.document.write('<img src="' + foto + '" onLoad="opener.redimensionar(this.width, this.height)">');
	ventana.document.write('<div style="height:22px;background:#555500;text-align:right;vertical-align:top"><table style="height:100%" cellpadding="0" cellspacing="0"><tr><td style="vertical-align:top;padding-right:8px;">');
	ventana.document.write('<a style="font-family:verdana,arial;font-size:11px;text-decoration:none;color:#999900" onmouseover="this.style.color=\'#ffcc00\'" onmouseout="this.style.color=\'#999900\'" href="#" onclick="self.close()"><img style="border:none;vertical-align:middle" src="img/close.gif" /> '+cerrar+'</a></td></tr></table></div>');
	ventana.document.close();
	abierto++;
}

function redimensionar(ancho, alto)
{
	ventana.resizeTo(ancho+10,alto+59);
	ventana.moveTo((screen.width-ancho)/2,(screen.height-(alto+59))/2); // Para centrar el popup
}

function ajustar(contenedor,foto)
{
	var maximo = 100;
	var objeto = new getObj(contenedor);
	var producto = new Image();
	producto.src = foto;
	
	while(producto.height==0 || producto.width==0)
		producto.src = foto;
		
	if(producto.height > maximo)
	{
		producto.width = parseInt(producto.width * maximo / producto.height); 
		producto.height = maximo;
	}
	
	if(producto.width > maximo)
	{
		producto.height = parseInt(producto.height * maximo / producto.width); 
		producto.width = maximo;
	}
	
	objeto.obj.src=producto.src;	
	objeto.obj.height=producto.height;
	objeto.obj.width=producto.width;
	
}

function navegadorFichas(actual,total)
{
	var x = 1;
	var navtab;
	var tab;
	
	for(x=1;x<=total;x++)
	{
		navtab = new getObj('tab'+x);
		tab = 'ficha'+x;
		
		if(x==actual)
		{
			
			//navtab.style.color='white';
			navtab.style.background='#f0f0dd';
			//navtab.style.background='#008888'
			show(tab);
		}
		else
		{
			navtab.style.background='#ffffff';
			//navtab.style.background='#55aaaa'
			//navtab.style.color='#aaffff';
			hide(tab);
		}
	}
}

function box(actual,total)
{
	var x = 1;
	var imgbox;
	var box;
	
	for(x=1;x<=total;x++)
	{
		imgbox = new getObj('imgbox'+x);
		box = 'box'+x;
		
		if(x==actual)
		{
			imgbox.obj.src='img/close_box2.gif';
			show(box);
		}
		else
		{
			imgbox.obj.src='img/close_box.gif';
			hide(box);
		}
	}
}

function opcion(actual,total)
{
	var x = 1;
	var th;
	var imgOpcion;
	var tbl;
	
	for(x=1;x<=total;x++)
	{
		th = new getObj('th'+x);
		imgOpcion = new getObj('imgOpcion'+x);
		tbl = 'tbl'+x;
		
		if(x==actual)
		{
			th.style.background='#f0f0dd';
			imgOpcion.obj.src='img/close_box2.gif';
			show(tbl);
		}
		else
		{	
			th.style.background='#ffffff';
			imgOpcion.obj.src='img/square.gif';
			hide(tbl);
		}
	}
}

function opcionaux(actual,total) // Igual que la anterior; se utiliza en caso de ya existir otras fichas en un panel adyacente.
{
	var x = 1;
	var th;
	var imgOpcion;
	var tbl;
	
	for(x=1;x<=total;x++)
	{
		th = new getObj('thaux'+x);
		imgOpcion = new getObj('imgOpcionaux'+x);
		tbl = 'tblaux'+x;
		
		if(x==actual)
		{
			th.style.background='#f0f0dd';
			imgOpcion.obj.src='img/close_box2.gif';
			show(tbl);
		}
		else
		{	
			th.style.background='#ffffff';
			imgOpcion.obj.src='img/square.gif';
			hide(tbl);
		}
	}
}

function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers)
	{
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}


function show(elemento)
{
	var objeto= new getObj(elemento);
	objeto.style.display='block';
}

function hide(elemento)
{
	var objeto= new getObj(elemento);
	objeto.style.display='none';
}

function insertValue(id,texto)
{
	var objeto = new getObj(id);
	objeto.obj.innerText=texto;
}

