function ClickThumb(fl,tx) {
    var mainfoto = document.getElementById('mainfoto');
    mainfoto.setAttribute('src',fl);
    mainfoto.parentNode.setAttribute('href',fl);
    var captn = mainfoto.parentNode.parentNode.nextSibling;
    while(captn.nodeType != 1){captn = captn.nextSibling};
    captn.innerText=tx;
    //captn.removeChild(captn.firstChild);
    //captn.appendChild(document.createTextNode(tx));
}

function ShiftThumbs(direction) {
    var countPics = picList.length - 1;
    var jcorr=0;
    if(direction=='next') {
            var lastPic = document.getElementById('foto3').getAttribute('src');}
    else {  var lastPic = document.getElementById('foto1').getAttribute('src')};
    if(lastPic.indexOf(window.location.protocol)==0){ // Opera 8, IE url parsing 
        var rt = window.location.href.replace(/(.+\/foto\/).+/,'$1');
    } else { // Opera 9, Firefox url parsing
        var rt = ''; 
    };
    for(var j=0,jl;jl=picList[j];j++) if((rt=='' && jl[1]==lastPic) || (rt!='' && jl[1].replace('./',rt)==lastPic)) break;
    jcorr = j-1; if(jcorr<0) jcorr=countPics;
    document.getElementById('foto1').setAttribute('src',picList[jcorr][1]);
    document.getElementById('foto1').setAttribute('alt',picList[jcorr][0]);
    
    document.getElementById('foto2').setAttribute('src',picList[j][1]);
    document.getElementById('foto2').setAttribute('alt',picList[j][0]);
    
    jcorr = j+1; if(jcorr>countPics) jcorr=0;
    document.getElementById('foto3').setAttribute('src',picList[jcorr][1]);
    document.getElementById('foto3').setAttribute('alt',picList[jcorr][0]);
    
    ClickThumb(picList[j][1],picList[j][0]+' ('+(j+1)+'/'+picList.length+')');
}

function firstPics() {
    document.getElementById('foto3').setAttribute('src',picList[0][1]);
    ShiftThumbs('next');
    ClickThumb(picList[0][1],picList[0][0]+' (1/'+picList.length+')');
}
