// JavaScript Document
//************** COLOCAR ESTE SCRIPT EN EL LUGAR DONDE VA A APARECER LA IM&Aacute;GEN *********************//


//********************************* DEFINICI&Oacute;N DE VARIABLES ****************************************//
var slideshow_width='148px'; //ANCHO DE LA IM&Aacute;GEN
var slideshow_height='119px'; //ALTO DE LA IM&Aacute;GEN
var pause=2000; //TIEMPO QUE TARDAN EN CAMBIAR LAS IM&Aacute;GENES (En milisegundos)
//**************************************************************************************************//

//************ ARRAY CON LAS IM&Aacute;GENES - SE PUEDEN A&Ntilde;ADIR O QUITAR SEG&Uacute;N SE NECESITE ****************//
var fadeimages=new Array();

fadeimages[0]="home_democracia_r2_c2_1.gif";
fadeimages[1]="home_democracia_r2_c2_2.gif";
fadeimages[2]="home_democracia_r2_c2_3.gif";

//**************************************************************************************************//


//******************************* NO MODIFICAR A PARTIR DE AQU&Iacute; ************************************//

var preloadedimages=new Array();

for (p=0;p<fadeimages.length;p++)
{
  preloadedimages[p]=new Image();
  preloadedimages[p].src="img/"+fadeimages[p];
}

var ie4=document.all;
var dom=document.getElementById;

if (ie4||dom)
{
  document.write('<div style="position:relative;width:'+slideshow_width+';height:'+slideshow_height+';overflow:hidden"><div  id="sanvas0" style="position:absolute;width:'+slideshow_width+';height:'+slideshow_height+';top:0;left:0;filter:alpha(opacity=10);-moz-opacity:10"></div><div id="sanvas1" style="position:absolute;width:'+slideshow_width+';height:'+slideshow_height+';top:0;left:0;filter:alpha(opacity=10);-moz-opacity:10"></div></div>');
}
else
{
  document.write('<img name="defaultslide" src="img/'+fadeimages[0]+'" border=0>');
  //document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0" height="154" background="images/'+fadeimages[0]+'">');
}

var curpos=10;
var degree=10;
var cursanvas="sanvas0";
//var curimageindex=Math.floor(Math.random()*fadeimages.length);
//var nextimageindex=Math.floor(Math.random()*fadeimages.length);
var curimageindex=0;
var nextimageindex=1;
var indice_aux = 0;

//while (nextimageindex==curimageindex)
//{
  //nextimageindex=Math.floor(Math.random()*fadeimages.length);
//}

function fadepic()
{
  if (curpos<100)
  {
	curpos+=10;
	
	if (tempobj.filters)
	{
	  tempobj.filters.alpha.opacity=curpos;
	  
	}
	else if (tempobj.style.MozOpacity)
	{
	  tempobj.style.MozOpacity=curpos/100;
	}
  }
  else
  {
	clearInterval(dropslide);
	nextsanvas=(cursanvas=="sanvas0")? "sanvas0" : "sanvas1";
	tempobj=ie4? eval("document.all."+nextsanvas) : document.getElementById(nextsanvas);
	tempobj.innerHTML='<img src="img/'+fadeimages[nextimageindex]+'" border=0>';
	//tempobj.innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0" height="154" background="images/'+fadeimages[nextimageindex]+'">';
	
	//indice_aux = Math.floor(Math.random()*fadeimages.length);
	indice_aux = nextimageindex+1;
	if (indice_aux>=fadeimages.length)
	{
	  indice_aux = 0;
	}
	nextimageindex=indice_aux;
	
	setTimeout("rotateimage()",pause);
  }
}

function rotateimage()
{
  if (ie4||dom)
  {
	resetit(cursanvas);
	var crossobj=tempobj=ie4? eval("document.all."+cursanvas) : document.getElementById(cursanvas);
	crossobj.style.zIndex++;
	var temp='setInterval("fadepic()",50)';
	dropslide=eval(temp);
	cursanvas=(cursanvas=="sanvas0")? "sanvas1" : "sanvas0";
  }
  else
  {
	document.images.defaultslide.src="img/"+fadeimages[curimageindex];
  }

  curimageindex=(curimageindex<fadeimages.length-1)? curimageindex+1 : 0;
}

function resetit(what)
{
  curpos=10;
  var crossobj=ie4? eval("document.all."+what) : document.getElementById(what);
  
  if (crossobj.filters)
  {
    crossobj.filters.alpha.opacity=curpos;
	
  }
  else if (crossobj.style.MozOpacity)
  {
	crossobj.style.MozOpacity=curpos/100;
  }
}

function startit()
{
  var crossobj=ie4? eval("document.all."+cursanvas) : document.getElementById(cursanvas);
  crossobj.innerHTML='<img src="img/'+fadeimages[curimageindex]+'" border=0>';
  //crossobj.innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0" height="154" background="images/'+fadeimages[curimageindex]+'">';
  rotateimage();
}

if (ie4||dom)
{
  window.onload=startit;
}
else
{
  setInterval("rotateimage()",pause);
}
//**************************************************************************************************//
