﻿//Photo Container functionality
var photoChangeInterval = 0;
var changePeriod = 7000;

var currentPictureIndex = 0;

function SetPhotoChangeInterval() {

    photoChangeInterval = setInterval("ChangePicture(true, false)", changePeriod);
}

//flash like functionality
function initImage(imageId) {
    image = document.getElementById(imageId);
    setOpacity(image, 0);
    image.style.visibility = 'visible';
    fadeIn(imageId, 0);
}

function setOpacity(obj, opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;

    // IE/Win
    obj.style.filter = "alpha(opacity:" + opacity + ")";

    // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = opacity / 100;

    // Older Mozilla and Firefox
    obj.style.MozOpacity = opacity / 100;

    // Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity / 100;
}

function fadeIn(objId, opacity) {
    if (document.getElementById) {
        obj = document.getElementById(objId);
        if (opacity <= 100) {
            setOpacity(obj, opacity);
            opacity += 10;
            window.setTimeout("fadeIn('" + objId + "'," + opacity + ")", 10);
        }
    }
}

//photo container functionlity
function ChangePicture(move_forward, remove_interval) {
          
    if (remove_interval)
        ClearPhotoChangeInterval();

    if (move_forward) {
        if (currentPictureIndex + 1 == photos.length)
            currentPictureIndex = -1; //outside of the array before the first element
        document.getElementById("photo_container").style.backgroundImage = "url(" + photos[++currentPictureIndex] + ")";

        //flash like functionality
        initImage("photo_container");
    }
    else {
        if (currentPictureIndex == 0)
            currentPictureIndex = photos.length; //on the second element
        document.getElementById("photo_container").style.backgroundImage = 'url("' + photos[--currentPictureIndex] + '")';
    }
}

//clear the photo interval
function ClearPhotoChangeInterval() {
    clearInterval(photoChangeInterval);
}

