var gallery=new Object();

gallery.elementos=new Array();
gallery.whichImageLoad=new Array();
gallery.isInfinite=new Array();

gallery.addImage=function(galleryName, imageName){
        var im = new Image();
        im.src = imageName;
        if (this.elementos[galleryName] == undefined)
        {
                this.elementos[galleryName] = new Array();
                this.whichImageLoad[galleryName] = 0;
        }
        this.elementos[galleryName][this.elementos[galleryName].length] = im
}

gallery.infinite=function(galleryName) {
        this.isInfinite[galleryName]=true;
}

gallery.previous=function(galleryName,spanName) {
        this.changeImage(galleryName,-1);
	this.textoFoto(galleryName,spanName);
}

gallery.next=function(galleryName,spanName) {
        this.changeImage(galleryName,+1);
	this.textoFoto(galleryName,spanName);
}

gallery.changeImage=function(galleryName,direction) {
    this.whichImageLoad[galleryName] += direction;
    if (this.whichImageLoad[galleryName] < 0)
        if (this.isInfinite[galleryName])
                this.whichImageLoad[galleryName] = this.elementos[galleryName].length - 1;
        else
                this.whichImageLoad[galleryName] += direction * -1;
    if (this.whichImageLoad[galleryName] == this.elementos[galleryName].length)
        if (this.isInfinite[galleryName])
                this.whichImageLoad[galleryName] = 0;
        else
                this.whichImageLoad[galleryName] += direction * -1;
    if (document.images)
        document[galleryName].src = this.elementos[galleryName][this.whichImageLoad[galleryName]].src;
}

gallery.textoFoto=function(galleryName, spanName) {
	var sp = document.getElementById(spanName);
	sp.innerHTML = (1+this.whichImageLoad[galleryName]) + " de " + this.elementos[galleryName].length;
}