// JavaScript Document

function changeFoto(numFoto) {
    contador = 0;
    try
    {
        var objThumb = document.getElementById('thumb' + fotoAtual);
        objThumb.className = 'thumb';
    }
    catch (Error)
    {
        return;
    }

    fotoAtual = numFoto;
    objThumb = document.getElementById('thumb' + fotoAtual);
    objThumb.className = 'thumbOn';

    clearInterval(timerAlteraFoto);

    var obj = document.getElementById('imagemGrande');
    if (obj) obj.src = fotos[numFoto];

    var obj1 = document.getElementById('LinkImagem');
    if (obj1) obj1.href = fotosLink[numFoto];

    obj.onload = function() {
        if (statusSlide)
            startTimer();
    }
}

var contador = 0;
var timerAlteraFoto;
var fotoAtual = 0;
var statusSlide = 1;

function startTimer() {
    timerAlteraFoto = setInterval("aumentaContador()", 100);
}

function showStatusBar() {
    var obj = document.getElementById('tempoProximaFoto');
    obj.style.width = contador + "%";
}

function changeSlideshowStatus() {
    statusSlide = !statusSlide;
    //var obj = document.getElementById('opcaoSlideshow');
    var obj = document.getElementById('playpause');
    if (statusSlide) {
        startTimer();
        //obj.innerHTML = "Parar slideshow";        
        if (obj) obj.src = "/img/pause.png";
    }
    else {
        clearInterval(timerAlteraFoto);
        contador = 0;
        showStatusBar();
        //obj.innerHTML = "Continuar slideshow";
        if (obj) obj.src = "/img/play.png";
    }

    
    
}

function aumentaContador() {
    contador = contador + 1;

    if (contador > 100) {
        contador = 100;
        foto = fotoAtual + 1 >= fotos.length ? 0 : fotoAtual + 1;
        changeFoto(foto);
    }
    else {
        showStatusBar();
    }

}

function showhide(element, show) {
    if (show == true && element != assistindo) document.getElementById(element).style.display = 'block';
    else document.getElementById(element).style.display = 'none';
}

function showvideo(videoid, text) {
    writetext('Você está assistindo: ' + text, 'assistindo');
    assistindo = videoid;
}

function writetext(text, id) {
    var txtField = document.getElementById(id);
    txtField.innerHTML = text;
    document.getElementById(id).style.display = 'block';
}

function NewWindow(mypage, myname, w, h, scroll) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=' + scroll + ',noresizable'
    win = window.open(mypage, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
