var video;
var GALERIA_FOTO = {
			idGaleria:0,
			indiceFoto:0,
			itens:0,
			intervalo:0,
			velocidade:5500,
			galerias:'',
			Init:function(galerias,v){
					GALERIA_FOTO.galerias = galerias;

              //  alert(GALERIA_FOTO.galerias);
					GALERIA_FOTO.velocidade = v||GALERIA_FOTO.velocidade;
				},
			Reset:function(){
					GALERIA_FOTO.indiceFoto = 0;
					GALERIA_FOTO.itens = 0;
				},	
			buscarFoto:function(){
					if((GALERIA_FOTO.indiceFoto < GALERIA_FOTO.itens.length) && (GALERIA_FOTO.indiceFoto >=0)){
						var html = GALERIA_FOTO.itens[GALERIA_FOTO.indiceFoto].embed;
						var legenda = GALERIA_FOTO.itens[GALERIA_FOTO.indiceFoto].legenda;
						var credito = GALERIA_FOTO.itens[GALERIA_FOTO.indiceFoto].credito;
						if(credito){
							legenda+=' - <i>Crédito: '+credito+'</i>';
						}
						$('#fac-galeria_foto_atual').html(html);
						$('#fac-galeria_legenda_foto').html(legenda);
						GALERIA_FOTO.atualizaPosicao();
						return true;
					}else{
						return false;
					}
				},
			avancarFoto:function(){
					GALERIA_FOTO.indiceFoto++;
					if(!GALERIA_FOTO.buscarFoto()){
						GALERIA_FOTO.indiceFoto = 0;
						GALERIA_FOTO.buscarFoto();
					}
				},
			voltarFoto:function(){
					GALERIA_FOTO.indiceFoto--;
					if(!GALERIA_FOTO.buscarFoto()){
						GALERIA_FOTO.indiceFoto = GALERIA_FOTO.itens.length-1;
						GALERIA_FOTO.buscarFoto();
					}
				},
			pausarSlide:function(){
				clearInterval(GALERIA_FOTO.intervalo);
				},
			playSlide:function(){
					GALERIA_FOTO.intervalo = setInterval(function(){
						GALERIA_FOTO.avancarFoto();
					},GALERIA_FOTO.velocidade);
				},
			abrir:function(id){
					GALERIA_FOTO.Reset();
					GALERIA_FOTO.idGaleria = id;

                 //alert(GALERIA_FOTO.galerias[GALERIA_FOTO.idGaleria]);

					GALERIA_FOTO.itens = GALERIA_FOTO.galerias[GALERIA_FOTO.idGaleria].itens;
                
					GALERIA_FOTO.atualizaQuantidade();
					GALERIA_FOTO.atualizaTitulo();
					$('#TB_window').show();
					$('#TB_overlay').show();
					GALERIA_FOTO.buscarFoto();
					//GALERIA_FOTO.playSlide();
				},
			fechar:function(){
					$('#TB_window').hide();
					$('#TB_overlay').hide();
					GALERIA_FOTO.pausarSlide();
				},
			atualizaQuantidade:function(){
					$('#fac-galeria_qtd_fotos').val(GALERIA_FOTO.itens.length);
				},
			atualizaTitulo:function(){
                    $('#fac-titulo_galeria-text').html(GALERIA_FOTO.galerias[GALERIA_FOTO.idGaleria].nome_galeria);
				},	
			atualizaPosicao:function(){
					$('#fac-galeria_posicao').val(GALERIA_FOTO.indiceFoto+1);
					//alert(GALERIA_FOTO.indiceFoto);
				}	
		};
		
$(function(){
	GALERIA_FOTO.Init(galerias_multimidia,2500);
	
	$('#fac-galeria_avancar').click(function(){
		GALERIA_FOTO.avancarFoto();
	});
	$('#fac-galeria_voltar').click(function(){
		GALERIA_FOTO.voltarFoto();
	});
	$('#fac-galeria_pausar').click(function(){
		GALERIA_FOTO.pausarSlide();
	});
	$('.fac-galeria_foto').click(function(){
		var id = $(this).attr('id').split('_')[1];
		GALERIA_FOTO.abrir(id);
		//GALERIA_FOTO.playSlide();
	});
	$('#fechar_galeria').click(function(){
		GALERIA_FOTO.fechar();
	});
});
if(video != true){
	GALERIA_FOTO.playSlide(); /** auto play  para fotos**/
}
