// JavaScript Document
//************** COLOCAR ESTE SCRIPT EN EL LUGAR DONDE VA A APARECER LA IM&Aacute;GEN *********************//


//********************************* DEFINICI&Oacute;N DE VARIABLES ****************************************//
var slideshow_width='357px'; //ANCHO DE LA IM&Aacute;GEN
var slideshow_height='214px'; //ALTO DE LA IM&Aacute;GEN
var pause=3000; //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]="foto_00.jpg";
fadeimages[1]="foto_01.jpg";
fadeimages[2]="foto_02.jpg";
fadeimages[3]="foto_03.jpg";
fadeimages[4]="foto_04.jpg";
fadeimages[5]="foto_05.jpg";
fadeimages[6]="foto_06.jpg";

//**************************************************************************************************//


//******************************* 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="imagenes/"+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="canvas0" style="position:absolute;width:'+slideshow_width+';height:'+slideshow_height+';top:0;left:0;filter:alpha(opacity=10);-moz-opacity:10"></div><div id="canvas1" 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="imagenes/'+fadeimages[0]+'" onClick=ampliar(0); class=mano border=0>');
  //document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0" height="154" background="imagenes/'+fadeimages[0]+'">');
}

var curpos=10;
var degree=10;
var curcanvas="canvas0";
var curimageindex=Math.floor(Math.random()*fadeimages.length);
var nextimageindex=Math.floor(Math.random()*fadeimages.length);
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);
	nextcanvas=(curcanvas=="canvas0")? "canvas0" : "canvas1";
	tempobj=ie4? eval("document.all."+nextcanvas) : document.getElementById(nextcanvas);
	tempobj.innerHTML='<img src="imagenes/'+fadeimages[nextimageindex]+'" onClick=ampliar('+nextimageindex+'); class=mano border=0>';
	//tempobj.innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0" height="154" background="imagenes/'+fadeimages[nextimageindex]+'">';
	
	indice_aux = Math.floor(Math.random()*fadeimages.length);
	while (indice_aux==nextimageindex)
	{
	  indice_aux = Math.floor(Math.random()*fadeimages.length);
	}
	nextimageindex=indice_aux;
	
	setTimeout("rotateimage()",pause);
  }
}

function rotateimage()
{
  if (ie4||dom)
  {
	resetit(curcanvas);
	var crossobj=tempobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas);
	crossobj.style.zIndex++;
	var temp='setInterval("fadepic()",50)';
	dropslide=eval(temp);
	curcanvas=(curcanvas=="canvas0")? "canvas1" : "canvas0";
  }
  else
  {
	document.images.defaultslide.src="imagenes/"+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."+curcanvas) : document.getElementById(curcanvas);
  crossobj.innerHTML='<img src="imagenes/'+fadeimages[curimageindex]+'" onClick=ampliar('+curimageindex+'); class=mano border=0>';
  //crossobj.innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0" height="154" background="imagenes/'+fadeimages[curimageindex]+'">';
  rotateimage();
}

if (ie4||dom)
{
  window.onload=startit;
}
else
{
  setInterval("rotateimage()",pause);
}

function ampliar(id)
{
	nwindow('ampliacion_imgs.php?img=gran_'+fadeimages[id]+'','Galeria',200,200,'no','center');
}

function nwindow(mypage,myname,w,h,scroll,pos)
{
  if (pos=="random")
  {
    LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
    TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
  }
  else if (pos=="center")
  {
    LeftPosition=(screen.width)?(screen.width-w)/2:100;
    TopPosition=(screen.height)?(screen.height-h)/2:100;
  }
  else
  {
    LeftPosition=0;
    TopPosition=20;
  }

  settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
  win=window.open(mypage,myname,settings);

  if(win.focus)
  {
    win.focus();
  }
}

//**************************************************************************************************//