﻿// JScript File

var imgArray = new Array(8);
//var txtArray = new Array(8);
var frame = 0;
//var timer = null;
//var imgElement = null;
var imgCount;
//var filterFunction ="blendTrans(duration=2)"; //"revealTrans(duration=1, transition=12)";
//var imageRef = "aniImage";
//var divRef = "aniImageDiv";
var newframe;
var newImage;
var currImage;

function preload()
{
    imgArray = document.getElementById("aniImageDiv").getElementsByTagName("img");
    imgCount = imgArray.length;
    

    currImage = imgArray[0];
    
    for(i=1; i<imgCount; i++)
    {
        changeObjOpac(0,imgArray[i]);
        imgArray[i].style.display = "block";
    }
    
    animate();
}

function animate()
{
    transform();
    timer = setTimeout("animate()", 5000);
}   


function changeObjOpac(opacity, object) { 
    object.style.opacity = (opacity /101); 
    object.style.MozOpacity = (opacity /101); 
    object.style.KhtmlOpacity = (opacity / 100); 
    object.style.filter = "alpha(opacity=" + opacity + ")"; 
}

function fade(opacity, down, up)
{
    changeObjOpac(opacity, imgArray[up] );
    changeObjOpac((100 - opacity), imgArray[down]);
}

function setCaption()
{
    //get description from <img> alt attribute
    
    document.getElementById("caption").firstChild.nodeValue = imgArray[frame].alt;
    
} 

function transform()
{
    var millisec = 2000;
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

   
   // set image to next picture
   newframe = (frame + 1)%imgCount;
   
   newImage = imgArray[newframe];
   
   
   // slowly show image 
   for(i=0; i <= 100; i++)
   {
    setTimeout("fade(" + i + "," +frame +","+ newframe + ")", (speed*i));
    timer++;
   }
   frame = newframe;
   setCaption();
}

