/*Galeria*/

function trocaFoto (imagem) {
	document.images["foto"].src=imagem
}

function fadeOut(id, tempo) {
	target = document.getElementById(id);
	alpha = 100;
	timer = (tempo*1000)/50;
	var i = setInterval(
			function() {
				if (alpha <= 40)
					clearInterval(i);
				setAlpha(target, alpha);
				alpha -= 2;
			}, timer);
}

function fadeIn(id, tempo) {
	target = document.getElementById(id);
	alpha = 40;
	timer = (tempo*1000)/50;
	var i = setInterval(
			function() {
				if (alpha >= 100)
					clearInterval(i);
				setAlpha(target, alpha);
				alpha += 2;
			}, timer);
}

function setAlpha(target, alpha) {
	target.style.filter = "alpha(opacity="+ alpha +")";
	target.style.opacity = alpha/100;
}

/*############################################################################
		Preloader - Imagens
##############################################################################*/	

var loadImage = function(w, h, url, target, aposFinalizar) {
	var img = new Image(w, h);
	//img.src = url;
	img.style.visibility = "hidden";
	
	var molde = document.createElement("div");
	
	var style = molde.style;
	style.background = "url(css/img/carregando.gif)  no-repeat center center";
	
	document.getElementById(target).appendChild(molde);
	
	molde.appendChild(img);
	img.onload = function() {
		this.style.visibility = "visible";
		molde.style.background = "none";
		
		//Executa a funçao após o onload
		if (typeof(aposFinalizar) == "function")
			aposFinalizar();
			
	}
	
	img.setAttribute("src", url);
	
}

/*############################################################################
		Carrega Miniatura dos Clientes
##############################################################################*/
function carregaCliente(url, destino) {
	new loadImage(80, 70, "i/a/" +  url, destino);
}

