<!--
/* Author: Dilan Shyar */
/* Date: 01/11/2006 */

var imageholder = new Array();

for (i=0; i<judoPhotos.length; i++)
{ //preload images
    imageholder[i] = new Image();
    imageholder[i].src = "images/Slideshow/" + judoPhotos[i].fileLocation;
    imageholder[i].alt = judoPhotos[i].caption;
}

function opacity(id, bg, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

function currentOpac(id, bg, opacEnd, millisec) {
    //standard opacity is 100
    var currentOpac = 100;
    
    //if the element has an opacity set, get it
    if(document.getElementById(bg).style.opacity < 100) {
        currentOpac = document.getElementById(bg).style.opacity * 100;
    }

    //call for the function that changes the opacity
    opacity(id, null, currentOpac, opacEnd, millisec)
} 

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, null, 0, 100, millisec);
    } else {
        opacity(id, null, 100, 0, millisec);
    }
} 

function fadeInImage(imageid, imagebg, imagefile) {

    //make image visible 100%
    changeOpac(100, imageid);

    //make new image
    document.getElementById(imageid).src = imagefile;

    /* The following stage is not needed. Because the image is the same as the bg*/
    //fade in image
    //opacity(imageid, null, 0, 100, 5000);
    //currentOpac(imageid, imagebg, 100, 5000);
}

function fadeOutImage(imageid, imagebg, imagefile) {

    //set the next image background
    document.getElementById(imagebg).style.backgroundImage = "url(" + imagefile + ")";

    //fade out image
    opacity(imageid, imagebg, 100, 0, 4900);
}

var runShow = false;
function toggleRunShow() {
    if( runShow ) {
        runShow = false;
    }
    else {
        runShow = true;
    }

}

var whichimage = 0;
var fadeout = true;
function runSlideShow(imageid, imagebg, displaySecs)
{

    if( runShow ) {

        if (!document.getElementById(imageid))
            return;

        if (fadeout){
            // Fetch next image in the list
            whichimage = (whichimage<judoPhotos.length-1)? whichimage+1 : 0;
            var nextImage = imageholder[whichimage].src;

            // Set image next image as bg and fade out current image
            fadeOutImage(imageid, imagebg, nextImage);
            fadeout = false;
            setTimeout("runSlideShow('"+imageid+"', '"+imagebg+"', "+displaySecs+")", 5000);
        }
        else{

            // This image is set as bg
            var nextImage = imageholder[whichimage].src;

            //Make this image as current image
            fadeInImage(imageid, imagebg, nextImage);

            document.getElementById( "sportsCaption" ).innerHTML = 
                imageholder[whichimage].alt;

            fadeout = true;
            setTimeout("runSlideShow('"+imageid+"', '"+imagebg+"', "+displaySecs+")", (displaySecs*2));
        }
    }
}


function movePhoto( pr_Increment )
{
    runShow = false;

    whichimage += pr_Increment;
    if( whichimage < 0 ) {
        whichimage = totalPhotos - 1;
    } else if( whichimage >= totalPhotos ) {
        whichimage = 0;
    }
    
    document.getElementById( "sport_image" ).src = 
        imageholder[whichimage].src;

    document.getElementById( "sportsCaption" ).innerHTML = 
        imageholder[whichimage].alt + imageholder[whichimage].src;

}


-->
