var fading = false;
var imgId = '';

function setOpacity(obj, opacity) 
{
    opacity = (opacity == 100)?99.999:opacity;
  
    // IE/Win
    obj.style.filter = "alpha(opacity:"+opacity+")";
  
    // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = opacity/100;
  
    // Older Mozilla and Firefox
    obj.style.MozOpacity = opacity/100;
  
    // Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity/100;
}

function switchImage(imgName, imgSrc) 
{
    if (document.images)
    {
        if (imgSrc != "none")
        {
            var img = new Image(350, 250);
            img.src = imgSrc;
            document.images[imgName].src = imgSrc;
        }
    }
}

var newImg;

function fadeIn(objId, opacity) 
{    
    obj = document.getElementById(imgId);

    if (opacity <= 100 && !fading && newImg.complete) 
    {        
        opacity += 25; 
        setOpacity(obj, opacity);
                          
        if (opacity >= 100)
        {
            fading = false;
        }
        else
        {
        		window.setTimeout("fadeIn('"+objId+"', "+opacity+")", 10); 
        }
    }
    else
    {
        window.setTimeout("fadeIn('"+objId+"', "+opacity+")", 200);
    }
}

function fadeOut(objId, imgSrc, opacity) 
{
  if (document.getElementById) 
  {        
        imgId = objId;
        obj = document.getElementById(objId);
        if (opacity >= 0) 
        {
            opacity -= 25;        
            setOpacity(obj, opacity);            
            window.setTimeout("fadeOut('"+objId+"', '" + imgSrc + "' ,"+opacity+")", 10);
        }
        else
        {
            newImg = new Image(350, 250);
            newImg.src = imgSrc;
            document.images[objId].src = imgSrc;
            fading = false;
        }
   }
   else
   {
   	  window.setTimeout("fadeOut('"+objId+"', '" + imgSrc + "' ,"+opacity+")", 100);
   }
}

function switchImageWithFade(imgName, imgSrc) 
{
    if (document.images && fading == false)
    {
        fading = true;
        fadeOut(imgName, imgSrc, 100);
        fadeIn(imgName, 0);
    }
}


var libros = new Array();
libros["aquilino"] = 2;
libros["cuentosenfamilia"] = 3;
libros["dezpordous"] = 0;
libros["herculesycrunia"] = 2;
libros["historiaderomanobombeiro"] = 2;
libros["opequenodafamiliafantasma"] = 2;
libros["quesabemosdodiadasletrasgalegas"] = 0;
libros["sobranaspalabras"] = 0;
libros["suca"] = 3;
libros["titolongueiron"] = 4;
libros["avoatentreceanos"] = 3;

var textos = new Array();
textos["aquilino"] = "Aquilino pinta una nube y un camaleón. 2001. Combel";
textos["cuentosenfamilia"] = "Cuentos en familia. 2006. Anaya";
textos["dezpordous"] = "Dez por dous. 2004. Biblos";
textos["herculesycrunia"] = "Hércules y Crunia. 2005. Kalandraka";
textos["historiaderomanobombeiro"] = "Historia de Román o bombeiro. 2005. Everest";
textos["opequenodafamiliafantasma"] = "O pequeno da familia fantasma. 2005. Sotelo Blanco";
textos["quesabemosdodiadasletrasgalegas"] = "¿Qué sabemos do Día das Letras Galegas? 2001. Xunta de Galicia";
textos["sobranaspalabras"] = "Sobran as palabras. 1999. Xunta de Galicia";
textos["suca"] = "Suca. 2001. Everest";
textos["titolongueiron"] = "Tito Longueirón. 2005. BD Banda";
textos["avoatentreceanos"] = "A miña avoa ten trece anos. 2007. Edelvives";


function muestra_libro(nombre)
{
	var numimgs = libros[nombre];
	var resHtml = "";
	
   if (numimgs == 0)
   {
		switchImage("dibujo", "../../blanco.gif");   	
   }	
   else
   {
		switchImage("dibujo", "../../imaxes/libros/" + nombre + "1.jpg");   
   }
	
	for (var i = 1; i <= numimgs; i++)
	{	   
		resHtml = resHtml + "<a href=\"javascript:switchImage('dibujo', '../../imaxes/libros/" + nombre + i + ".jpg');\">[ " + i + " ]</a>";	
	}
	
   document.getElementById('enlaces_libro').innerHTML = resHtml;
   document.getElementById('texto_libro').innerHTML = textos[nombre];
   switchImage("portada", "../../imaxes/libros/" + nombre + ".jpg");
}


var nombres = new Array();
nombres["castro"] = "Fidel Castro";
nombres["cezanne"] = "Paul Cézanne";
nombres["chagall"] = "Marc Chagall";
nombres["cortazar"] = "Julio Cortázar";
nombres["curziomalaparte"] = "Curzio Malaparte";
nombres["henrylevi"] = "Bernard-Henry Levi";
nombres["hitchcock"] = "Alfred Hitchcock";
nombres["kandinsky"] = "Wassily Kandinsky";
nombres["kirchner"] = "Ernst Ludwig Kirchner";
nombres["klimt"] = "Gustav Klimt";
nombres["kokoschka"] = "Oskar Kokoschka";
nombres["lautrec"] = "Henri de Toulouse-Lautrec";
nombres["lecorbusier2"] = "Le Corbusier";
nombres["lecorbusier"] = "Le Corbusier";
nombres["mattisse"] = "Henri Mattisse";
nombres["miro"] = "Joan Miró";
nombres["nietzsche"] = "Friedrich Wilheim Nietzsche";
nombres["pessoa2"] = "Fernando Pessoa";
nombres["picasso"] = "Pablo Ruiz Picasso";
nombres["stravinsky"] = "Igor Stravinsky";
nombres["tchaikovsky"] = "Pyotr Ilych Tchaikovsky";
nombres["wolfe"] = "Tom Wolfe";
nombres["woodyallen"] = "Woody Allen";


function muestra_caricatura(nombre)
{
   document.getElementById('titCaricatura').innerHTML = nombres[nombre];
   switchImageWithFade("caricatura", nombre + ".jpg");
}




