﻿var ValtozoIdo = 1000;
function SetAtlatszo(anyag, atlatszoSzazalek) 
{
    // IE.
    anyag.style.filter = 'alpha(opacity=' + atlatszoSzazalek + ')';
    // Old mozilla and firefox
    anyag.style.MozOpacity = atlatszoSzazalek / 100;
    // Everything else.
    anyag.style.opacity = atlatszoSzazalek / 100;
}
function ValtsAtlatszo(id, idohoszz, kezdoIdo, honnan, meddig) {
    var element = document.getElementById(id);
    var mostan = (new Date()).getTime();
    var atlatszo = honnan + (meddig - honnan) * (mostan - kezdoIdo) / idohoszz;
    if (atlatszo >= 100) {
        SetAtlatszo(element, 100);
        element.timer = undefined;
    }
    else if (atlatszo <= 0) {
        SetAtlatszo(element, 0);
        element.timer = undefined;
    }
    else {
        SetAtlatszo(element, atlatszo);
        element.timer = window.setTimeout("ValtsAtlatszo('" + id + "'," + idohoszz + "," + kezdoIdo + "," + honnan + "," + meddig + ")", 10);
    }
}
function FadeInImage(foregroundID, newImage, backgroundID) {
    var foreground = document.getElementById(foregroundID);
    if (foreground.timer) window.clearTimeout(foreground.timer);
    if (backgroundID) {
        var background = document.getElementById(backgroundID);
        if (background) {
            if (background.src) {
                foreground.src = background.src;
                SetAtlatszo(foreground, 100);
            }
            background.src = newImage;
            background.style.backgroundImage = 'url(' + newImage + ')';
            background.style.backgroundRepeat = 'no-repeat';
            var startMS = (new Date()).getTime();
            foreground.timer = window.setTimeout("ValtsAtlatszo('" + foregroundID + "'," + ValtozoIdo + "," + startMS + ",100,0)", 10);
        }
    } else {
        foreground.src = newImage;
    }
}
var slideCache = new Array();
function FenykepAlbum(pictureID, backgroundID, displaySecs, imageFiles) {
    var imageSeparator = imageFiles.indexOf(";");
    var nextImage = imageFiles.substring(0, imageSeparator);
    if (slideCache[nextImage] && slideCache[nextImage].loaded) {
        FadeInImage(pictureID, nextImage, backgroundID);
        var futureImages = imageFiles.substring(imageSeparator + 1, imageFiles.length)
      + ';' + nextImage;
        setTimeout("FenykepAlbum('" + pictureID + "','" + backgroundID + "'," + displaySecs + ",'" + futureImages + "')",
      displaySecs * 1000);
        // Identify the next image to cache.
        imageSeparator = futureImages.indexOf(";");
        nextImage = futureImages.substring(0, imageSeparator);
    } else {
    setTimeout("FenykepAlbum('" + pictureID + "','" + backgroundID + "'," + displaySecs + ",'" + imageFiles + "')",
      250);
    }
    // Cache the next image to improve performance.
    if (slideCache[nextImage] == null) {
        slideCache[nextImage] = new Image;
        slideCache[nextImage].loaded = false;
        slideCache[nextImage].onload = function() { this.loaded = true };
        slideCache[nextImage].src = nextImage;
    }
}

