
// Browser Slide-Show script. With image cross fade effect for those browsers
// that support it.
// Script copyright (C) 2004-2008 www.cryer.co.uk.
// Script is free to use provided this copyright header is included.
var FadeDurationMS=1000;
function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}
function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var msNow = (new Date()).getTime();
  var opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity>=100)
  {
    SetOpacity(element,100);
    element.timer = undefined;
  }
  else if (opacity<=0)
  {
    SetOpacity(element,0);
    element.timer = undefined;
  }
  else 
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",10);
  }
}

function FadeInImage(foregroundID,newImage,backgroundID)
{	
  var foreground=document.getElementById(foregroundID);
  if (foreground.timer) window.clearTimeout(foreground.timer);
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    if (background)
    {
      if (background.src)
      {
        foreground.src = background.src; 
        SetOpacity(foreground,100);
      }
      background.src = newImage;
      background.style.backgroundImage = 'url(' + newImage + ')';
      background.style.backgroundRepeat = 'no-repeat';
      var startMS = (new Date()).getTime();
      foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "'," + FadeDurationMS + "," + startMS + ",100,0)",10);
    }
  } else {
    foreground.src = newImage;
  }
}

var slideCache = new Array();


function RunSlideShow(pictureID,backgroundID,imageFiles,displaySecs)
{
  var imageSeparator = imageFiles.indexOf(";");
  var nextImage = imageFiles.substring(0,imageSeparator);
  slideCache[nextImage] = new Image;
  slideCache[nextImage].src = nextImage;
  if (!slideCache[nextImage].complete){
	    setTimeout("RunSlideShow('"+pictureID+"','"+backgroundID+"','"+imageFiles+"',"+displaySecs+")",100);
		return;	
	  }
  FadeInImage(pictureID,nextImage,backgroundID);
  if (nextImage.indexOf("/0.png")!=-1){
	  var futureImages = imageFiles.substring(imageSeparator+1,imageFiles.length);  
  } else {
  	  var futureImages = imageFiles.substring(imageSeparator+1,imageFiles.length)+ ';' + nextImage;
  }
  setTimeout("RunSlideShow('"+pictureID+"','"+backgroundID+"','"+futureImages+"',"+displaySecs+")",displaySecs*1000);
  // Cache the next image to improve performance.
  imageSeparator = futureImages.indexOf(";");
  nextImage = futureImages.substring(0,imageSeparator);
  if (slideCache[nextImage] == null)
  {
    slideCache[nextImage] = new Image;
    slideCache[nextImage].src = nextImage;
  }
}


function RunSlideShow2(pictureID,backgroundID,imageFiles,displaySecs)
{
  if (sigue){
	  var imageSeparator = imageFiles.indexOf(";");
	  var idImage = imageFiles.substring(0,imageSeparator);
	  var nextImage='img/galeria/'+idImage+'.jpg';
	  slideCache[nextImage] = new Image;
	  slideCache[nextImage].src = nextImage;
	  if (!slideCache[nextImage].complete){
			setTimeout("RunSlideShow2('"+pictureID+"','"+backgroundID+"','"+imageFiles+"',"+displaySecs+")",100);
			return;	
	  }
	  var topoActual=document.getElementById('punto'+idImage);
	  topoActual.src="img/galeria/iconos/n.png";
	  for (i=1; i<= numFotos; i++){
		  if (i!=idImage){
			var topoOtro=document.getElementById('punto'+i);
			topoOtro.src="img/galeria/iconos/b.png";	
		  }
	  }
	  FadeInImage(pictureID,nextImage,backgroundID);
 	  actual=parseInt(idImage);
	  var futureImages = imageFiles.substring(imageSeparator+1,imageFiles.length)+ ';' + idImage;
	  setTimeout("RunSlideShow2('"+pictureID+"','"+backgroundID+"','"+futureImages+"',"+displaySecs+")",displaySecs*1000);
	  // Cache the next image to improve performance.
	  imageSeparator = futureImages.indexOf(";");
	  idImage = futureImages.substring(0,imageSeparator);
	  nextImage='img/galeria/'+idImage+'.jpg';
	  if (slideCache[nextImage] == null)
	  {
		slideCache[nextImage] = new Image;
		slideCache[nextImage].src = nextImage;
	  }
  }
}

function CambiaFoto(pictureID,backgroundID,i)
{
	if (i==-1){
		i=(actual-1);	
		if (i<1){
			i=numFotos;	
		}
	}
	if (i==-2){
		i=(actual+1);
		if (i>numFotos){
			i=1;	
		}
	}
	var nextImage="img/galeria/"+i+".jpg";
	var topoActual=document.getElementById('punto'+i);
	topoActual.src="img/galeria/iconos/n.png";
	for (j=1; j<= numFotos; j++){
		  if (j!=i){
			var topoOtro=document.getElementById('punto'+j);
			topoOtro.src="img/galeria/iconos/b.png";	
		  }
	}
	for (j=1; j<= numFotos; j++){
			var topoOtro=document.getElementById('2punto'+j);
			topoOtro.src="img/galeria2/iconos/b.png";	
	}
	FadeInImage(pictureID,nextImage,backgroundID);
	actual=i;
	sigue=false;
}


function CambiaFoto2(pictureID,backgroundID,i)
{
	if (i==-1){
		i=(actual-1);	
		if (i<1){
			i=numFotos;	
		}
	}
	if (i==-2){
		i=(actual+1);
		if (i>numFotos){
			i=1;	
		}
	}
	var nextImage="img/galeria2/"+i+".jpg";
	var topoActual=document.getElementById('2punto'+i);
	topoActual.src="img/galeria2/iconos/n.png";
	for (j=1; j<= numFotos; j++){
		  if (j!=i){
			var topoOtro=document.getElementById('2punto'+j);
			topoOtro.src="img/galeria2/iconos/b.png";	
		  }
	}
	for (j=1; j<= numFotos; j++){
			var topoOtro=document.getElementById('punto'+j);
			topoOtro.src="img/galeria/iconos/b.png";	
	}
	FadeInImage(pictureID,nextImage,backgroundID);
	actual=i;
	sigue=false;
}

