
var posicion;
posicion=10;
var scroll;
scroll=0;

// Mueve la capa del scroll 
function moverA(pos){

	// Explorer
	if (document.all){
		document.all["galeria"].style.left = posicion;
		document.all["galeria"].style.width = (-posicion+300);
		document.all["galeria"].style.clip = "rect( 0 "+(-posicion+300)+" 55 "+(-posicion+10)+")";
	}
	// Netscape
	else {
		window.document.galeria.left = posicion;
		window.document.galeria.clip.right = (-posicion+300);
		window.document.galeria.clip.left = (-posicion+10);
	}
}

// Scroll derecha
function derecha(){
	if (posicion>(-58*Galeria.nFotos+300)){
		posicion -= 5;
		moverA(posicion);
	}
	if (scroll==1){setTimeout("derecha()",50);}
}

// Scroll izquierda
function izquierda(){
	if (posicion<10){
		posicion += 5;
		moverA(posicion);
	}
	if (scroll==1){setTimeout("izquierda()",50);}

}

// Muestra una foto
function mostrarFoto(imagen,texto){

	s="\n<table width='100%' border='0' cellspacing='0' cellpadding='0' height='100'>"
	s+="\n<tr align='center' valign='middle'>";
    s+="\n<td>";
    s+="\n<table width='95%' border='1' cellspacing='0' cellpadding='0' height='200' bordercolor='#FFFFFF'>";
    s+="\n<tr align='center' valign='middle' bordercolor='#666666'>";
    s+="\n<td><img src='img/galerias/"+imagen+"'></td>";
    s+="\n</tr>";
    s+="\n</table>";
    s+="\n<br>";
    s+="\n<span class='pequena'>"+texto+"</span></td>";
	s+="\n</tr>";
	s+="\n</table>";
	if (document.all){
		document.all.foto.innerHTML = s;
	}else{
		window.document.foto.document.open();
		window.document.foto.document.write(s);
		window.document.foto.document.close();
	}
}

// Muestra un texto indicando que no hay foto
function mostrarNoHayFoto(){

	s="\n<table width='100%' border='0' cellspacing='0' cellpadding='0' height='100'>"
	s+="\n<tr align='center' valign='middle'>";
    	s+="\n<td>";
	s+="\n<table width='95%' border='1' cellspacing='0' cellpadding='0' height='200' bordercolor='#FFFFFF'>";
    	s+="\n<tr align='center' valign='middle' bordercolor='#666666'>";
    	s+="\n<td class='normal'>No hay fotograf&iacute;as disponibles.</td>";
    	s+="\n</tr>";
    	s+="\n</table>";
    	s+="\n</td>";
	s+="\n</tr>";
	s+="\n</table>";
	if (document.all){
		document.all.foto.innerHTML = s;
	}else{
		window.document.foto.document.open();
		window.document.foto.document.write(s);
		window.document.foto.document.close();
	}
}


// Muestra la primera foto
function verPrimera(){
	// Hago un pequeño ajuste en IExplore
	if (document.all){
		document.all.galeria.style.overflow='hidden';
	}
	if (Galeria.nFotos>0){
		// Pongo la foto
		mostrarFoto(Galeria.Foto[0].imagen,Galeria.Foto[0].texto);
	}else{
		// Pongo un texto indicando que no hay fotos
		mostrarNoHayFoto();		
	}
}

// Constructor para el objeto que contiene las fotos
function objFoto(imagen,texto){
	this.imagen = imagen;
	this.texto = texto;
}

// Constructor para el objeto galeria
function objGaleria(){

	this.nFotos = 0;
	this.Foto = new Array();

	// Muestra la galeria
	this.mostrar = function mostrar(){
		s="\n<table border='0' cellspacing='3' cellpadding='0' height='55'>";
    		s+="\n<tr align='center' valign='middle'>";
		if (this.nFotos>0){
		  for (i=0;i<this.nFotos;i++){
			s+="\n<td width='55' height='55'>";
			s+="\n<a href='#' onclick='javascript:mostrarFoto(\""+this.Foto[i].imagen+"\",\""+this.Foto[i].texto+"\");return false;'>";
			s+="\n<img src='img/galerias/miniaturas/"+this.Foto[i].imagen+"' border='0'>";
			s+="\n</a>"
			s+="\n</td>";
		  }
		}else{
			s+="\n<td width='250' height='55' align='center' valign='middle'>";
			s+="\n<span class='normal'>No hay fotograf&iacute;as disponibles</span>";
			s+="\n</td>";
		}
		s+="\n</tr>\n</table>";
		if (window.document.all){
			document.write(s);
		} else {
			window.document.galeria.document.open();
			window.document.galeria.document.write(s);
			window.document.galeria.document.close();
		}
	}

	// Anhade una foto a la galeria
	this.add = function add(imagen,texto){
		this.Foto[this.nFotos] = new objFoto(imagen,texto);
		this.nFotos++;
	}
}

var Galeria = new objGaleria();