try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}

foto = 0;
inicioSlide = 0;
campo = "idevento";
tipo  = "DESC";
pg = 0;

var ajax = {
	
	album : function(pasta, pagina){
		pg = pagina;
		diretorio = pasta;
		alvo = document.getElementById("miniaturas");
		anime.fade(alvo, 100, 20);
		xmlhttp.open("GET", "ajax.php?pasta="+pasta+"&pg="+pagina, true);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if(xmlhttp.status == 200) {
					alvo.innerHTML = xmlhttp.responseText;
					imagens = alvo.getElementsByTagName("img");
					ajax.exibe(imagens[0].title, imagens[0]);
					ultimo = imagens.length - 1;
					imagens[ultimo].onload = function() { anime.appear(alvo, 20, 100, 100); }
				}
			}
		}
		xmlhttp.send(null);
	},
	
	mostraFoto : function(lado){
		total_de_fotos = document.getElementById('TotalDeFotos').value;
		if(lado == 'ant') {
			if(foto > 0) {
				foto -= 1;
				ajax.exibe(imagens[foto].title, imagens[foto]);
			}else{
				pg -= 1;
				if(pg >= 0) {
					ajax.album(diretorio, pg);
				}
			}
		}else{
			if(foto < 9) {
				foto = parseInt(foto)+1;
				if(imagens[foto]){
					ajax.exibe(imagens[foto].title, imagens[foto]);
				}else{
					foto -= 1;
				}
			}else{
				pg += 1;
				if(pg < (total_de_fotos/10)) {
					ajax.album(diretorio, pg);
				}
			}
		}
	},
	
	exibe : function(caminho, proxima){
		foto = proxima.id
		exibe = document.getElementById('foto');
		loaded = document.getElementById('load');
		anime.fade(loaded, 100, 20, 100);
		loaded.style.display = 'block';
		exibe.style.display = 'none';
		exibe["src"] = caminho;
		exibe.onload = function(){
			loaded.style.display = 'none';
			exibe.style.display = 'block';
			anime.appear(exibe, 0, 100, 100); 
		}
	}
}

var anime = {
	setadown : function(item){
		if(item.id == "ant")
			item.src = "images/seta_esq_down.gif";
		if(item.id == "prox")
			item.src = "images/seta_dir_down.gif";
	},

	setaup : function(item){
		if(item.id == "ant")
			item.src = "images/seta_esq_up.gif";
		if(item.id == "prox")
			item.src = "images/seta_dir_up.gif";
	},

	fade : function(item, inicio, fim, time){
		if(fim < inicio) {
			inicio -= 20;
			item.style["filter"] = "Alpha(opacity="+inicio+")";
			item.style["opacity"] = inicio/100;
		}else{
			return;
		}
		setTimeout(function(){ anime.fade(item, inicio, fim); }, time);
	},

	appear : function(item, inicio, fim, time){
		if(fim > inicio) {
			inicio += 20;
			item.style["filter"] = "Alpha(opacity="+inicio+")";
			item.style["opacity"] = inicio/100;
		}else{
			return;
		}
		setTimeout(function(){ anime.appear(item, inicio, fim); }, time);
	},

	zoomFoto : function(tipo, status){
		imagens = document.getElementById('miniaturas').childNodes;
		x = imagens[0].width;
		y = imagens[0].height;
		if(tipo == "+") {
			if(x < 140) {
				for(i=0;i<imagens.length;i++){
					imagens[i].width = x+20;
					imagens[i].height = y+15;
				}
			}
		} else {
			if(x > 60) {
				for(i=0;i<imagens.length;i++){
					imagens[i].width = x-20;
					imagens[i].height = y-15;
				}
			}
		}
	}
}
