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

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;

    if( judoPhotos[whichimage].orientation == 'P' ) {
        document.getElementById( imageid ).style.width = 267;
        document.getElementById( imageid ).style.backgroundImage = "";
    } else {
        document.getElementById( imageid ).style.width = 600;
    }

    /* 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;

//            alert("FadeOut: " + nextImage );

            // 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;

//            alert("FadeIn: " + nextImage );

            //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;
    }

    if( judoPhotos[whichimage].orientation == 'P' ) {
        document.getElementById( "sport_image" ).style.width = 267;
//        document.getElementById( "sport_bg" ).style.backgroundImage = "";
    } else {
        document.getElementById( "sport_image" ).style.width = 600;
    }

    document.getElementById( "sport_image" ).src = 
        imageholder[whichimage].src;

    caption = "[" + (whichimage + 1) + "] " + imageholder[whichimage].alt;;

    document.getElementById( "sportsCaption" ).innerHTML = 
        caption;

}

function openPicturePopup( intWidth, intHeight, blnNewWindow, charOrientation ) {

    var intScreenHeight = 0;
    var intScreenWidth = 0;
    var leftPos = 0;
    var topPos = 0;

    //	get screen height
    if( parseInt( navigator.appVersion ) > 3 ) {
        intScreenHeight = screen.availHeight;
        intScreenWidth = screen.availWidth;
        if( !intScreenHeight ) {
            intScreenHeight = screen.height;
        }
        if( !intScreenWidth ) {
            intScreenWidth = screen.width;
        }
    } else if( ( navigator.appName == "Netscape" ) && 
               ( parseInt( navigator.appVersion ) == 3 ) && 
               ( navigator.javaEnabled() ) ) {

        var jToolkit = java.awt.Toolkit.getDefaultToolkit();
        var jScreenSize = jToolkit.getScreenSize();
        intScreenHeight = jScreenSize.height;
        intScreenWidth  = jScreenSize.width;
    } else {
        alert( 'Can\'t detect screen resolution' );
        return;
    }
    //	adjust dimensions if necessary
    if( intHeight > intScreenHeight ) {
        intHeight = intScreenHeight - 10;
    }

//    alert( "intH: " + intHeight 
//        + "   intW: " + intWidth
//        + "   imgH: " + largeImageholder[whichimage].height
//        + "   imgW: " + largeImageholder[whichimage].width );

    if( intHeight < intScreenHeight - 10 ) {
        topPos = ( intScreenHeight - intHeight ) / 2 + 5;
    }
    if( intWidth < intScreenWidth ) {
        leftPos = ( intScreenWidth - intWidth ) / 2;
    }
    if( blnNewWindow ) {

        //	new window
        var largePicture = imageholder[whichimage].src;
        largePicture = largePicture.replace("s_", "" );

        var openPopup = window.open(  largePicture,
                                     'popup',
                                     'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width='
                                        + intWidth 
                                        + ',height=' + intHeight
                                        + ',left=' + leftPos 
                                        + ',top=' + topPos );
        openPopup.focus();
    } else {
        //	same window
        window.resizeTo( intWidth, intHeight );
    }
    return;
}

-->