// JavaScript Document
function createLayer(layerName)	{

	div = document.getElementById('dvAll');

	if(!document.getElementById(layerName))	{
		newLayer = document.createElement('div');
		newLayer['id'] = layerName;
		
		div.appendChild(newLayer);
		anime.appear(newLayer, 0, 100, 500);
		return true;
		}
	else	{
		alert('A tela já se encontra aberta!');
		return false;
		}
	}

var anime = {
	
	setadown : function(item){
		if(item.id == "ant")
			item.src = "img/seta_esq_down.gif";
		
		if(item.id == "prox")
			item.src = "img/seta_dir_down.gif";
		
	},
	
	setaup : function(item){
		if(item.id == "ant")
			item.src = "img/seta_esq_up.gif";
		
		if(item.id == "prox")
			item.src = "img/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);
		
	},
	
	resizeAbre : function(local, conteudo, winicio, winc, wfim, hinicio, hinc, hfim){
		
		if(winicio < wfim){
			winicio += winc;
			local.style.width = winicio+"px";
		}else{
			if(hinicio < hfim) {
				hinicio += hinc;
				local.style.height = hinicio+"px";
			}else{
				local.innerHTML = conteudo;
				return;
			}
		}
		
		setTimeout(function(){ anime.resizeAbre(local, conteudo, winicio, winc, wfim, hinicio, hinc, hfim); }, 40);
		
	},
	
	resizeFecha : function(local, winicio, winc, wfim, hinicio, hinc, hfim){
		
		if(hinicio > hfim) {
			hinicio -= hinc;
			local.style.height = hinicio+"px";
		}else{
			if(winicio > wfim){
				winicio -= winc;
				local.style.width = winicio+"px";
			}else{
				div = document.getElementById('dvAll');
				div.removeChild(local);
				return;
			}
		}
		
		setTimeout(function(){ anime.resizeFecha(local, winicio, winc, wfim, hinicio, hinc, hfim); }, 40);
	}	
}

function closeLayer(id) {
	document.getElementById('dvAll').removeChild(document.getElementById(id));
	}


function loadInLayer(url, id) {
	if(createLayer(id))			
		ajaxLoader(url, id);
	else
		return false;	
	}

