﻿// JScript File

function imageItem(image_location) {
    this.image_item = new Image();
    this.image_item.src = image_location;
    }
    function get_ImageItemLocation(imageObj) {
    return(imageObj.image_item.src)
}
function randNum(x, y) {
    var range = y - x + 1;
    return Math.floor(Math.random() * range) + x;
}
function getNextImage() {
    ImageNum = (ImageNum+1) % number_of_image;
    var new_image = get_ImageItemLocation(imageArray[ImageNum]);
    switchThumb(ImageNum);
    return(new_image);
}

function getPrevImage() {
    if (ImageNum == 0)
        ImageNum = number_of_image - 1;
    else
        ImageNum = (ImageNum-1) % number_of_image;
    var new_image = get_ImageItemLocation(imageArray[ImageNum]);
    switchThumb(ImageNum);
    return(new_image);
}

function prevImage(place) {
    if (slideshowIsPlaying)
        stopSlideShow('PhotoMainImage');
    var new_image = getPrevImage();
    document.getElementById(place).src = new_image;
}

function rotateImage(place) {
    var new_image = getNextImage();
    document.getElementById(place).src = new_image;
    //document[place].src = new_image;
    var recur_call = "rotateImage('"+place+"')";
    timerID = setTimeout(recur_call, interval);
}

function nextImage(place) {
    if (slideshowIsPlaying)
        stopSlideShow('PhotoMainImage');
    var new_image = getNextImage();
    document.getElementById(place).src = new_image;
}

function startSlideShow(place) {
    if (!slideshowIsPlaying)
    {
        var new_image = getNextImage();
        document.getElementById(place).src = new_image;
        //document[place].src = new_image;
        var recur_call = "rotateImage('"+place+"')";
        timerID = setTimeout(recur_call, interval);
        slideshowIsPlaying = true;
    }
}

function showPhoto(photoNum) {
    ImageNum = photoNum;
    if (slideshowIsPlaying)
        stopSlideShow('PhotoMainImage');
    //if (document.getElementById('slideShowPlay').checked)
    //    {
    //       clearTimeout(timerID);
    //       document.getElementById('slideShowPlay').checked = false; 
    //    }
    var new_image = get_ImageItemLocation(imageArray[photoNum]);
    document.getElementById('PhotoMainImage').src = new_image;
    
    switchThumb(photoNum);
}

function switchThumb(photoNum) {
    for (i = 0; i < number_of_image; i++)
        {
            if (i == photoNum)
                document.getElementById('slideshowThumb[' + i + ']').className = 'slideshowthumbover';
            else
                document.getElementById('slideshowThumb[' + i + ']').className = 'slideshowthumb';
        }
}

function stopSlideShow(place) {
    if (slideshowIsPlaying)
    {
        clearTimeout(timerID);
        slideshowIsPlaying = false;
    }
}

function onSlideShowPlayClick(c) {
    if (c.checked)
        startSlideShow('PhotoMainImage');
    else
        stopSlideShow();
}

function switchControlImages(imgno) {
    for (i = 0; i < 4; i++)
    {
        if (i == imgno)
            document.getElementById('slideshowcontrol[' + i + ']').src = 'style/images/slideshowcontrol_' + i + '_on.gif';
        else
            document.getElementById('slideshowcontrol[' + i + ']').src = 'style/images/slideshowcontrol_' + i + '.gif';        
    }
}


