
var ArrayImages = new Array();
var whichimage = new Array();
var whichlink=0
var ArrayCount=0

var slideimages=new Array()
var slidelinks=new Array()

function slideshowimages()
{
  slideimages[ArrayCount] = new Array()
  whichimage[ArrayCount] = 0
  
  for (i=0;i<slideshowimages.arguments.length;i++)
  {
  	slideimages[ArrayCount][i]=new Image()
	slideimages[ArrayCount][i].src=slideshowimages.arguments[i];
  }

  ArrayCount++
}

function slideshowlinks(){
  for (i=0;i<slideshowlinks.arguments.length;i++)
  slidelinks[i]=slideshowlinks.arguments[i]
}

function gotoshow(){
  if (!window.winslide||winslide.closed)
    winslide=window.open(slidelinks[whichlink])
  else
    winslide.location=slidelinks[whichlink]
    winslide.focus()
}


//configure the speed of the slideshow, in miliseconds
var slideshowspeed=3500


function DoIEBlending(id, iWhichArray, speed)
{
  if (!document.images)
    return
    
    slideshowspeed=speed
    
    var image = document.getElementById(id);

    var crossFadeDuration = 3
    
    if (document.all)
    {
	image.style.filter="blendTrans(duration=2)"
	image.style.filter="blendTrans(duration=crossFadeDuration)"
	image.filters.blendTrans.Apply()

//	document.images.slide.style.filter="blendTrans(duration=2)"
//	document.images.slide.style.filter="blendTrans(duration=crossFadeDuration)"
//	document.images.slide.filters.blendTrans.Apply()
    }
//    document.images.slide.src=slideimages[iWhichArray][whichimage].src
    image.src=slideimages[iWhichArray][whichimage[iWhichArray]].src

    if (document.all)
    {
      image.filters.blendTrans.Play()
//      document.images.slide.filters.blendTrans.Play()
    }
     
//    whichlink=whichimage

  if (whichimage[iWhichArray]<slideimages[iWhichArray].length-1)
    whichimage[iWhichArray]++
  else
    whichimage[iWhichArray]=0

//  setTimeout("DoIEBlending(id,iWhichArray)",slideshowspeed)
  
  setTimeout(function() {DoIEBlending(id,iWhichArray, speed)}, slideshowspeed)

}





function DoFFBlending(id, iWhichArray, speed, pause, caption)
{
    if(speed == null)
    {
        speed = 35;
    }
    
    if(pause == null)
    {
        pause = 1500;
    }

    var image = document.getElementById(id);

    ArrayImages[iWhichArray] = new Image();
    ArrayImages[iWhichArray] = slideimages[iWhichArray][0];

    startBlending(image, speed, pause, caption, iWhichArray);
}


//make image a block-element and set the caption
function startBlending(image, speed, pause, caption, iWhichArray)
{
    image.src = ArrayImages[iWhichArray].src;
	
    image.style.display = 'block';

    if(caption != null) 
    {
	document.getElementById(caption).innerHTML = image.alt;
    }

    continueFadeImage(image, 0, speed, pause, caption, iWhichArray);
}



//make image invisible and set next one as current image
function getNextImage(image, iWhichArray)
{

    if (next = nextImage(image, iWhichArray))
    {
//	image.style.display = 'none';
//	image.style.zIndex = 0;

	next.style.display = 'block';
//	next.style.display = 'inline';
	next.style.zIndex = 100;

    }
    else
    {
	//if there is not a next image, get the first image again
	next = firstChildImage(image.parentNode);
    }

    return next;
}



//set an increased opacity and check if the image is done blending
function continueFadeImage(image, opacity, speed, pause, caption, iWhichArray)
{
    image.src = ArrayImages[iWhichArray].src;
    opacity = opacity + 3;

    if (opacity < 103) {

	setTimeout(function() {fadeImage(image, opacity, speed, pause, caption, iWhichArray)}, speed);

    }
    else 
    {
	//if the image is done, set it to the background and make it transparent
//	image.parentNode.style.backgroundImage = "url("+image.src+")";

	image.parentNode.style.background="url("+image.src+") no-repeat center center";
//	image.parentNode.style.height=image.height;
//	image.parentNode.style.width=image.width;

	// ASC: pause 1sec here to prevent MSIE image flash ...
	var paws=pause-1000;

	if (paws < 0 )
        {
	   paws = 0;
	}

	//pausecomp(1000);

	setOpacity(image,0);

	//get the next image and start blending it again
	image = getNextImage(image, iWhichArray);

	setTimeout(function() {startBlending(image, speed, pause, caption, iWhichArray)}, paws);		
    }
}

//set the opacity to a new value and continue the fading

function fadeImage(image, opacity, speed, pause, caption, iWhichArray)
{
    setOpacity(image,opacity);
    continueFadeImage(image, opacity, speed, pause, caption, iWhichArray);
}

//find first image inside an element

function firstChildImage(o)
{
    
    o = o.firstChild;
        
    while(o && (o.tagName != 'IMG') ) {
        o = o.nextSibling;
    }
    
    return o;
}


//find next image
function nextImage(o, iWhichArray)
{
  if (whichimage[iWhichArray] < slideimages[iWhichArray].length-1)
    whichimage[iWhichArray]++
  else
    whichimage[iWhichArray]=0

  ArrayImages[iWhichArray] = slideimages[iWhichArray][whichimage[iWhichArray]]; 

  return o;
}


function pausecomp(millis)
{
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while(curDate-date < millis);
} 

//set the opacity of an element to a specified value
function setOpacity(obj, o)
{

    obj.style.opacity = (o / 100);
    obj.style.MozOpacity = (o / 100);
    obj.style.KhtmlOpacity = (o / 100);
    obj.style.filter = 'alpha(opacity=' + o + ')';
}

