Galeria = {
	Itens : null,
	Indice : -1,
	Ordem : 1,
	Automatico : true,
	Timeout : null,
	Carregar : function(itens){
		this.Itens = itens;
		this.Proximo();
    },
    Proximo : function(){
		this.Preencher(1);
    },
    Anterior : function(){
		this.Preencher(0);
    },
    Navegacao : function(){
		this.Automatico = !this.Automatico;
		if(this.Automatico){
			this.Agendar();
		}else{
			clearTimeout(this.Timeout);
		}
    },
    Executar : function(){
		this.Preencher(this.Ordem);
    },
    Preencher : function( ordem ){
		this.Ordem = ordem;

		var aux = this.Indice;
		if(this.Ordem == 1){
			aux = aux+1;
		}else{
			aux = aux-1;
		}
		
		if( (aux >= 0) && (aux <= (this.Itens.length-1)) ){
			this.Indice = aux;
		}else
		if( (aux < 0) ){
			this.Indice = aux = this.Itens.length-1;
		}else
		if( (aux > (this.Itens.length-1)) ){
			this.Indice = aux = 0;
		}
		
		//this.Atualizar(this.Itens[aux], this.Indice);
		this.Atualizar(this.Itens, this.Indice);
		
		if(this.Automatico){
			this.Agendar();
		}
    },
    Visualizar : function( aux ){
		
		if( (aux >= 0) && (aux <= (this.Itens.length-1)) ){
			this.Indice = aux;
		}else
		if( (aux < 0) ){
			this.Indice = aux = this.Itens.length-1;
		}else
		if( (aux > (this.Itens.length-1)) ){
			this.Indice = aux = 0;
		}
		
		this.Atualizar(this.Itens, this.Indice);
		
		if(this.Automatico){
			this.Agendar();
		}
    },
	Agendar : function(){
		clearTimeout(this.Timeout);
		this.Timeout = setTimeout("Galeria.Executar()", (1000*5));
	},
	Atualizar : function(value, indice){
		
		for(var i=0; i < value.length; i++){
			var obj = document.getElementById("galeria-destaque-view-"+i);
			if(obj != null){
				obj.style.display = "none";
			}
		}
		$('#galeria-destaque-view-'+indice).fadeIn('slow');		
		
		/*var d0 = document.getElementById("d0");
		var d1 = document.getElementById("d1");
		var d3 = document.getElementById("d3");
		
		d0.innerHTML = value[0];
		d1.href = value[1];
		d1.title = value[0];
		//d1.style.backgroundImage = "url("+value[2]+")";
		d3.innerHTML = value[3];
		
		this.AtualizarStyle(indice);*/
	},
	AtualizarStyle : function(indice){
		for(var i=0; i < this.Itens.length; i++){
			var obj = document.getElementById("lk"+i);	
			if(obj != null){
				obj.className = "";
			}
		}
		var obj1 = document.getElementById("lk"+indice);
		if(obj1 != null){
			obj1.className = "s";
		}
	}
}
