﻿var timerFoto = 0;
var speed = 5000;
var i = 0;
var trans = 0.1;

function fadeout() {
    document.getElementById('fotoPortada').style.opacity = trans / 100;
    document.getElementById('fotoPortada').style.filter = 'alpha(opacity = ' + trans + ')';
    trans -= 20;
    if (trans >= 3)
        window.setTimeout(fadeout, 10);
    else {
        document.getElementById('fotoPortada').style.opacity = 0;
        document.getElementById('fotoPortada').style.filter = 'alpha(opacity = 0)';
        document.getElementById('fotoPortada').src = imatges[index];
        document.getElementById('fotoPortada').style.opacity = 0;
        document.getElementById('fotoPortada').style.filter = 'alpha(opacity = 0)';
        window.setTimeout(fadein, 100);
    }
}

function fadein() {

    document.getElementById('fotoPortada').style.opacity = trans / 100;
    document.getElementById('fotoPortada').style.filter = 'alpha(opacity = ' + trans + ')';
    trans += 20;
    if (trans <= 100)
        window.setTimeout(fadein, 10);
    else {
        document.getElementById('fotoPortada').style.opacity = 1;
        document.getElementById('fotoPortada').style.filter = 'alpha(opacity = 100)';
        window.setTimeout(canviafoto, speed);
    }
}

function canviafoto() {
    index++;
    if (index >= imatges.length) index = 0;
    trans = 100;
    window.setTimeout(fadeout, 10);
}