/* **************************************************************
*                         --XJS--	                            *
* Desenvolvedora: Rhianna Cantarelli							*
* Versão: 1.5													*
* Data: 17.05.2007												*
* Email: r.rhianna@yahoo.com.br									*
************************************************************** */







/* **************************************************************
Cria um objeto ImageGalery

	.isDescLabel = true/false : Define se o label da imagem será usado como Descrição
	.isChangeButtom = true/false : Quando à Botões habilitados ou não.
	    Use sufixo '_on' e '_off' nos botões para os mesmos serem identificados.
    .idButtonPrev           : ID do botão Anterior
    .idButtonNext           : ID do botão Próxima
	.addImage(src, label)	: Adiciona uma imagem à lista do Thumb
	.setImg()				: Usado Externamente para Iniciar um Thumb
	.prevImg()				: Avança para a Próxima Imagem
	.nextImg()				: Retorna para Imagem Anterior
************************************************************** */
function objImageGalery(idImg, idLabel, strMessage) {
	this.img = idImg;
	this.label = idLabel;
	this.message = strMessage;
	this.nAtual = 0;
	this.isDescLabel = false;
	this.isChangeButtom = false;
	this.idButtonPrev = '';
	this.idButtonNext = '';

	this.thumbImg = new Array();
	this.thumbImgLabel = new Array();
	
	this.addImage = function(src, label) {
		indexAtual = this.thumbImg.length;
		this.thumbImg[indexAtual] = src;
		this.thumbImgLabel[indexAtual] = label;
	};
	
	this.setImg = function() { 
		id(this.img).src = this.thumbImg[this.nAtual]; 
		this.setMessage();
		this.setButtons();
	};
	
	this.setButtons = function() {
	    i = this.nAtual;
	    last = this.thumbImg.length - 1;
	    buttonP = id(this.idButtonPrev);
	    buttonN = id(this.idButtonNext);
	    if(this.thumbImg.length == 1){ // Se só Haver 1 imagem
	        buttonP.src = buttonP.src.replace('_on', '_off');
	        buttonN.src = buttonN.src.replace('_on', '_off');
	    }
	    else if(this.nAtual == 0){ // Se estiver na Primeira
	        buttonP.src = buttonP.src.replace('_on', '_off');
	        buttonN.src = buttonN.src.replace('_off', '_on');
	    }
	    else if(this.nAtual == last) {
	        buttonP.src = buttonP.src.replace('_off', '_on');
	        buttonN.src = buttonN.src.replace('_on', '_off');
	    }
	    else {
	        buttonP.src = buttonP.src.replace('_off', '_on');
	        buttonN.src = buttonN.src.replace('_off', '_on');
	    }
	};
	
	this.nextImg = function() {
		last = this.thumbImg.length - 1;
		if(this.nAtual < last){ this.nAtual++; this.setImg(); } 
	};

	this.prevImg = function() {
		if(this.nAtual > 0){ this.nAtual--; this.setImg(); } 
	};


	this.setMessage = function() {
		if(this.isDescLabel == true) { id(this.label).innerHTML = this.thumbImgLabel[this.nAtual]; }
		else {
			if(this.message != '') {
				finalMessage = '';
				if(this.message.indexOf('*atual*') != -1) { 
					nAtual = this.nAtual + 1;
					finalMessage = this.message.replace('*atual*', nAtual);
				}
				if(this.message.indexOf('*total*') != -1) { 
					nTotal = this.thumbImg.length;
					if(finalMessage != ''){ finalMessage = finalMessage.replace('*total*', nTotal); }
					else { finalMessage = this.message.replace('*total*', nTotal); }
				}
				id(this.label).innerHTML = finalMessage; 
			}
		}
    };
}