//window.onload = initImageGallery;


onload = function(){
	initImageGallery()
	initImageGallery2()
}


var Swap_Gallery_Interval = 8000;
var Swap_Gallery_Speed = 10;
var Swap_Gallery_Index = -1;
var Swap_Gallery_Images = new Array();
var Swap_Gallery_Opacity;


function showGallery()
{
	Swap_Gallery_Opacity = 100;
	Swap_Gallery_Index = (Swap_Gallery_Index == Swap_Gallery_Images.length - 1)? 0 : Swap_Gallery_Index + 1;
	var next_image = (Swap_Gallery_Index + 1 == Swap_Gallery_Images.length)? 0 : Swap_Gallery_Index + 1;
	
	Swap_Gallery_Images[next_image].style.display = 'block';

	var mipie = document.getElementById("mipie");
	mipie.innerHTML = Swap_Gallery[next_image][3];
	
	var mas_ampliar = document.getElementById("mas_ampliar");
	var ampliar_link = '<a class="txt06ar_bl" ';
	ampliar_link += ' href="img/noticias/' + Swap_Gallery[next_image][1] + '"rel="lightbox[gal_0]" title="ampliar imagen destacada" ';
	ampliar_link += ' onclick="wOpen(\'img/noticias/' + Swap_Gallery[next_image][1] + '\',785,535);return false" ';
	ampliar_link += ' onkeypress="wOpen(\'img/noticias/' + Swap_Gallery[next_image][1] + '\');return false" ';
	ampliar_link += ' >ampliar</a>';
	
	mas_ampliar.innerHTML = ampliar_link;


	revealImage();
}

function revealImage()
{
	var next_image = (Swap_Gallery_Index + 1 == Swap_Gallery_Images.length)? 0 : Swap_Gallery_Index + 1;
	
	Swap_Gallery_Opacity--;
	
	if (document.all)
	{
		Swap_Gallery_Images[Swap_Gallery_Index].style.filter = 'alpha(opacity='+Swap_Gallery_Opacity+')';
		Swap_Gallery_Images[next_image].style.filter = 'alpha(opacity='+(100-Swap_Gallery_Opacity)+')';
	}
	else
	{
		Swap_Gallery_Images[Swap_Gallery_Index].style.opacity = Math.max(0.01,Swap_Gallery_Opacity/100);
		Swap_Gallery_Images[next_image].style.opacity = Math.min(0.99,(1 - (Swap_Gallery_Opacity/100)));
	}
	
	if (Swap_Gallery_Opacity > 0)
		setTimeout('revealImage()', Swap_Gallery_Speed);
	else
	{
		Swap_Gallery_Images[Swap_Gallery_Index].style.display = 'none';	
		setTimeout('showGallery()', Swap_Gallery_Interval);
	}
}

function initImageGallery()

{	
	var container = document.getElementById('imagen_destacada');
	
	container.getElementsByTagName('img')[0].setAttribute('id', 'galleryImage0');
	Swap_Gallery_Images[Swap_Gallery_Images.length] =  container.getElementsByTagName('img')[0];
	
	for (var x = 1; x < Swap_Gallery.length; x++)
	{
		var img = document.createElement('img');
		img.setAttribute('id', 'galleryImage' + x);
		img.setAttribute('src', 'img/' + Swap_Gallery[x][0]);
		img.setAttribute('alt', Swap_Gallery[x][2]);
		img.setAttribute('title', Swap_Gallery[x][2]);
		img.setAttribute('width', '242');
		img.setAttribute('height', '196');
		img.style.display = 'none';
		
		container.appendChild(img);
		
		Swap_Gallery_Images[Swap_Gallery_Images.length] =  img;
	}

	setTimeout('showGallery()', Swap_Gallery_Interval);
	
}







/*---------------------------------------------- galeria 2-------------------------------------- */


var Swap_Gallery_Interval2 = 3000;
var Swap_Gallery_Speed2 = 10;
var Swap_Gallery_Index2 = -1;
var Swap_Gallery_Images2 = new Array();
var Swap_Gallery_Opacity2;
var desfaseFotos=true;




function showGallery2()
{
	Swap_Gallery_Opacity2 = 100;
	Swap_Gallery_Index2 = (Swap_Gallery_Index2 == Swap_Gallery_Images2.length - 1)? 0 : Swap_Gallery_Index2 + 1;
	var imagen_siguiente = (Swap_Gallery_Index2 + 1 == Swap_Gallery_Images2.length)? 0 : Swap_Gallery_Index2 + 1;
	Swap_Gallery_Images2[imagen_siguiente].style.display = 'block';
	
	var mas_ampliar2 = document.getElementById("imagen_destacada2");
	var ampliar_link2 = '<a class="txt06ar_bl" ';
	ampliar_link2 += ' href="contenidos/compromisos_2003.htm"   title="Ver compromisos cumplidos" alt="Ver compromisos cumplidos" width="242" height="160" ';
	ampliar_link2 += ' onclick="document.location = \'contenidos/compromisos_2003.htm\'" onkeypress="contenidos/compromisos_2003.htm" ';
	ampliar_link2 += ' ><img  src="img/' + Swap_Gallery2[imagen_siguiente][0] +'" alt="Ver compromisos cumplidos" 	/></a>';
	
	
	mas_ampliar2.innerHTML = ampliar_link2;
	
	
	
	/* esto evita que sean simultáneos */
	Swap_Gallery_Interval2 = 8000; 
	
	revealImage2();
}

function revealImage2()
{
	var imagen_siguiente = (Swap_Gallery_Index2 + 1 == Swap_Gallery_Images2.length)? 0 : Swap_Gallery_Index2 + 1;
	
	Swap_Gallery_Opacity2--;
	
	if (document.all)
	{
		Swap_Gallery_Images2[Swap_Gallery_Index2].style.filter = 'alpha(opacity='+Swap_Gallery_Opacity2+')';
		Swap_Gallery_Images2[imagen_siguiente].style.filter = 'alpha(opacity='+(100-Swap_Gallery_Opacity2)+')';
	}
	else
	{
		Swap_Gallery_Images2[Swap_Gallery_Index2].style.opacity = Math.max(0.01,Swap_Gallery_Opacity2/100);
		Swap_Gallery_Images2[imagen_siguiente].style.opacity = Math.min(0.99,(1 - (Swap_Gallery_Opacity2/100)));
	}
	
	if (Swap_Gallery_Opacity2 > 0)
		setTimeout('revealImage2()', Swap_Gallery_Speed2);
	else
	{
		Swap_Gallery_Images2[Swap_Gallery_Index2].style.display = 'none';	
		setTimeout('showGallery2()', Swap_Gallery_Interval2);
	}
}

function initImageGallery2()

{	
	var container2 = document.getElementById('imagen_destacada2');
	
	container2.getElementsByTagName('img')[0].setAttribute('id', 'galleryImage2_0');
	Swap_Gallery_Images2[Swap_Gallery_Images2.length] =  container2.getElementsByTagName('img')[0];
	
	for (var x = 1; x < Swap_Gallery2.length; x++)
	{
		var imagen = document.createElement('img');
		imagen.setAttribute('id', 'galleryImage2_' + x);
		imagen.setAttribute('src', 'img/' + Swap_Gallery2[x][0]);
		imagen.setAttribute('alt', Swap_Gallery2[x][2]);
		imagen.setAttribute('title', Swap_Gallery2[x][2]);
		imagen.setAttribute('width', '242');
		imagen.setAttribute('height', '160');
		imagen.style.display = 'none';
		
		container2.appendChild(imagen);
		
		Swap_Gallery_Images2[Swap_Gallery_Images2.length] =  imagen;
	}

	setTimeout('showGallery2()', Swap_Gallery_Interval2);

}


