	var paginas;
	var paginaAtual		= 0;
	var idEvento;
	var diretorio;
	var startGal		= 0;
	var fotoInicio;
	var marcaAgua;

	var settings = jQuery.extend({
			// Configuration related to overlay
			overlayBgColor: 		'#000',		//cor do fundo
			overlayOpacity:			0.8,		//transparencia
			imageLoading:			'/imagens/lightbox-ico-loading.gif', //icone carregando
			imageFechar:			'/imagens/gal-close.png',
			imageBtnAnterior:		'/imagens/gal-ante.png',
			imageBtnProxima:		'/imagens/gal-prox.png',
			URLmin:					'/estrutura/galeria/miniaturas.php',
			URLfoto:				'/estrutura/galeria/verFoto.php',
		},settings);


$(function() {
		   
	$('#AbrirGal').click(function() {
		$('body').append('<div id="CamadaGal"></div><div id="galeria-box-container"><a href="javascript:void(0);" id="BtAnterior"><img src="'+settings.imageBtnAnterior+'" alt="Voltar Fotos" border="0" /></a><a href="javascript:void(0);" id="BtProxima"><img src="'+settings.imageBtnProxima+'" alt="Mais Fotos" border="0" /></a><a href="javascript:void(0);" id="BtClose"><img src="'+settings.imageFechar+'" alt="Fechar Galeria" border="0" /></a><div id="miniaturas"><p id="LoadMin">CARREGANDO...</p></div><div id="foto-container"><div id="foto"><p id="PLFoto">&nbsp;</p></div></div></div>');
	
	var arrPageSizes = ___getPageSize();
		
	$('#CamadaGal').css({
		backgroundColor:	settings.overlayBgColor,
		opacity:			settings.overlayOpacity,
		width:				arrPageSizes[0],
		height:				arrPageSizes[1]
	}).fadeIn();
	
	$('embed, object, select').css({ 'visibility' : 'hidden' });
	
	MaisFotos();
	CFoto(fotoInicio);

	//fechar galeria
	$('#BtClose,#CamadaGal').click(function() {
		_finish();							
	});
	
	//proximas fotos
	$('#BtProxima').click(function() {
		MaisFotos();
	});
	$('#BtAnterior').click(function() {
		MenosFotos();
	});
	$('.galeria').click(function() {
		alert('teste');
	});

	});
	
	//fechar galeria
	function _finish() {
		$('#galeria-box-container').remove();
		$('#CamadaGal').fadeOut(function() { $('#CamadaGal').remove(); });
		// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
		$('embed, object, select').css({ 'visibility' : 'visible' });
		paginaAtual	= 0;
		startGal	= 0;
	}
	
	//tamanho da pagina
	function ___getPageSize() {
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
	};


	//Mais fotos
	function MaisFotos(){
		paginaAtual+=1;
		if(paginaAtual<=paginas){
			$("#miniaturas").html('<p id="LoadMin">CARREGANDO...</p>');	
			$("#miniaturas").load(settings.URLmin,{pasta:diretorio,id:idEvento,pg:paginaAtual});
			
		}else{
			paginaAtual-=1;	
		}
	}
	//Menos fotos
	function MenosFotos(){
		paginaAtual-=1;
		if(paginaAtual>=1){
			$("#miniaturas").html('<p id="LoadMin">CARREGANDO...</p>');	
			$("#miniaturas").load(settings.URLmin,{pasta:diretorio,id:idEvento,pg:paginaAtual});
			
		}else{
			paginaAtual+=1;	
		}
	}
	
})

	//Carregar foto
	function CFoto(url){
		if(startGal==0){
			startGal=1;
			$("#foto").load(settings.URLfoto,{pasta:diretorio,foto:url,logo:marcaAgua});
		}else{
			$("#foto").append('<p id="CarregandoFoto">&nbsp;</p>');
			$("#foto").load(settings.URLfoto,{pasta:diretorio,foto:url,logo:marcaAgua});
		}
	}
