function Fotos() {
    var fotos;
    var current_id = -1;
}

Fotos.prototype.set_fotos = function (afotos) {
    this.fotos = afotos;
    this.current_id = 0;
}

Fotos.prototype.current = function() {
    return this.fotos[this.current_id];
}

Fotos.prototype.is_first = function() {
    return (this.current_id == 0);
}

Fotos.prototype.is_last = function() {
    return (this.current_id == this.fotos.length - 1);
}

Fotos.prototype.set_current = function(afoto) {
    var i;
    for (i = 0; i < this.fotos.length; i++) {
	if (this.fotos[i] == afoto) {
	    this.current_id = i;
	    break;
	}
    }
}

Fotos.prototype.next = function() {
    return this.fotos[++this.current_id];
}

Fotos.prototype.prev = function() {
    return this.fotos[--this.current_id];
}

function prev(where) {
    document.getElementById('img_main').src = where + fotos.prev();
    check_arrows(where);
}

function next(where) {
    document.getElementById('img_main').src = where + fotos.next();
    check_arrows(where);
}

function check_arrows(where) {
    if(fotos.is_first())
	document.getElementById("prev").innerHTML = '<img src="../img/no_arrow.gif" alt="" />';
    else
	document.getElementById("prev").innerHTML = '<a href="javascript:prev(\'' + where + '\');"><img src="../img/arrow_l.gif" alt="prev" /></a>';
    if(fotos.is_last())
	document.getElementById("next").innerHTML = '<img src="../img/no_arrow.gif" alt="" />';
    else
	document.getElementById("next").innerHTML = '<a href="javascript:next(\'' + where + '\');"><img src="../img/arrow_r.gif" alt="next" /></a>';
}

function swap(id) {
    document.getElementById('fotopral').src = '../img/empresa' + id + '.jpg';
}

function swapfr(idx) {
    document.getElementById('fotopral').src = fotos[idx];
    document.getElementById('fabricacio').innerHTML = descs[idx];
}

function swapre(id, idx) {
    document.getElementById('fotopral').src = '../imgre/' + id + '_' + idx + '.jpg';
}
