try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}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 = 1;

var ajax = {
	
	album : function(id){
		
		diretorio = id;
		alvo = document.getElementById('miniaturas');
		anime.fade(alvo, 100, 20);
		xmlhttp.open('GET', '../controles/ScriptPublico.php?cmd=ver_noticia_fotos&codigo='+id, true);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if(xmlhttp.status == 200) {
					alvo.innerHTML = xmlhttp.responseText;
					imagens = alvo.getElementsByTagName('img');
					
					var imgWidth=(imagens[0].alt.replace(/'/g,''));
					var imgHeight=imagens[0].name.replace(/'/g,'');
					
					if (imgWidth == 360)
						imgWidth = 380;
					else
						imgWidth = 500;
					
					if (imgHeight == 360)
						imgHeight = 380;
					else
						imgHeight = 500;
						
					ajax.exibe(imagens[0].src, imagens[0], imagens[0].title, imgWidth, imgHeight);
					ultimo = imagens.length;
					imagens[ultimo-1].onload = function(){anime.appear(alvo, 20, 100, 100);}
				}	
			}
		}
		xmlhttp.send(null);
	},
	
	exibe : function(caminho, proxima, popup, imgWidth, imgHeight){
		
		
		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["srcPop"] = '../../imagens/noticia/'+popup;
		exibe["imgWidth"] = imgWidth;
		exibe["imgHeight"] = imgHeight;

		exibe.onload = function(){
			loaded.style.display = 'none';
			exibe.style.display = 'block';
			anime.appear(exibe, 0, 100, 100); 
		}
		
		
	}
}

var anime = {
	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);
		
	}
}