// JavaScript Document

function Galeria(){
	var Obj = this;
	this.fotos = new Array();
	this.foto_atual = 0;
	
	var alterar = 0;
	var total = 0;
	
	$(document).ready(function(){
		total = $('.miniaturas img').length;
		
		$('#foto_principal').load(function(){
			$(this).animate({'opacity': 1}, 'fast');
		});
		
		$('.miniaturas img').load(function(){
			$(this).animate({'opacity':.7}, 'fast');
		}).click(function(){
			Obj.foto_atual = $(this).attr('i');
			Alterar_img();
		}).mouseover(function(){
			$(this).animate({'opacity': 1}, 'fast');	
		}).mouseout(function(){
			$(this).animate({'opacity': .7}, 'fast');
		});
		
		$('#galeria .seta_l').click(function(){
			Obj.Anterior();
		});
		
		$('#galeria .seta_r').click(function(){
			Obj.Proximo();
			
		});
		
		$('#galeria .voltar').click(function(){
			Obj.Fechar();
		});
	});
	
	this.Abrir = function(){
		$('#tel_' + tela_atual).animate({'opacity': 0}, 'fast');
		$('#galeria').show().animate({'opacity': 1}, 'fast');
	}
	
	this.Fechar = function(){
		$('#tel_' + tela_atual).animate({'opacity': 1}, 'fast');
		$('#galeria').animate({'opacity': 0}, 'fast', function(){
			$(this).hide();
		});
	}
	
	this.Proximo = function(){
		Obj.foto_atual++;
		if(Obj.foto_atual > total){
			Obj.foto_atual = 0;
		}
		 Alterar_img();
	}
	this.Anterior = function(){
		Obj.foto_atual--;
		if(Obj.foto_atual < 0){
			Obj.foto_atual = total;
		}
		 Alterar_img();
	}
	
	function Alterar_img(){
		var src = $('.miniaturas img[i='+Obj.foto_atual+']').attr('local');
		$('#foto_principal').animate({'opacity': 0}, 'fast', function(){
			$(this).attr('src', 'imagem.php?i='+ src+'&x=700');
		});
	}
}


var fotos = new Array();
var foto_atual = 0;
var alterar = 0;

function Alterar_Img(img){
	if (alterar == 0){
		alterar = 1;
		Sumir_Img(img, 100);
	}
}
function Sumir_Img(img, op){
	$("#imagem").animate({opacity: 0}, "slow");
	setTimeout(function(){Surgir_Img(img, op)}, 1000);
}

function Surgir_Img(img, op){
	imagem.onload;
	imagem.src = fotos[img];
	foto_atual = img;
	$("#imagem").animate({opacity: 1}, "slow");
	alterar = 0;
}

/*
function Ativar_Galeria(op){
	var tela_a = document.getElementById("tel_" + tela_atual);
	var galeria = document.getElementById("galeria");
	var gal_funco = document.getElementById("gal_fundo");
	
	fade_stop = 1;
	if (galeria.style.display != ""){
			galeria.style.display = "";
			gal_fundo.style.display = "";
	}
	op = op + 10;
	galeria.style.opacity = op/100;
	galeria.style.filter = "alpha(opacity="+op+")";
	if (op <= 70){
		gal_fundo.style.opacity = op/100;
		gal_fundo.style.filter = "alpha(opacity="+op+")";
	}
	if (op < 100){
		setTimeout(function(){Ativar_Galeria(op)}, 5);
	}
	else{
		tela_a.style.display = "none";	
	}
}

function Desativar_Galeria(op){
	var tela_a = document.getElementById("tel_" + tela_atual);
	var galeria = document.getElementById("galeria");
	var gal_funco = document.getElementById("gal_fundo");
	fade_stop = 0;
	op = op - 10;
	galeria.style.opacity= op/100;
	galeria.style.filter = "alpha(opacity="+op+")";
	if (op <=70){
		gal_fundo.style.opacity = op/100;
		gal_fundo.style.filter = "alpha(opacity="+op+")";
	}
	if (op <= 0){
		galeria.style.display = "none";
		gal_fundo.style.display = "none";
		tela_a.style.display = "";	
	}
	else{
		setTimeout(function(){Desativar_Galeria(op)}, 5);
	}
}
*/
/*




function Proxima(){
	i = foto_atual + 1;
	if (i >= fotos.length){
		i = 0;
	}
	Alterar_Img(i);
}
function Anterior(){
	i = foto_atual -1;
	if (i < 0){
		i = fotos.length - 1;
	}
	Alterar_Img(i);
}

function Acender_Seta(id, op){
		if (op < 100){
			op = op + 10;
			id.style.opacity = op/100;
			id.style.filter = "alpha(opacity="+op+")";
			setTimeout(function(){Acender_Seta(id, op)}, 5);
		}
}
function Apagar_Seta(id, op){
	if (op > 50){
		op = op -10;
		id.style.opacity = op/100;
		id.style.filter = "alpha(opacity="+op+")";
		setTimeout(function(){Apagar_Seta(id, op)}, 5);
	}
}
*/
