window.onload = function() {
	
	posicionarImagens();
	
	// Monta os link's para os arquivos na tela de home e exposições.
	montarLinks();
	
	// Monta os link's de anterior e próximo na tela de galeria.
	montarLinksGaleria();
	
}

function posicionarImagens() {
	// calculando a posição do cotovelo.
	var left = parseInt(Position.cumulativeOffset($('header'))[0]) + 960;
	$('cotovelo').style.left = left + 'px';
	
	// Calculando a posição da boneca 1.
	var boneca1_top = parseInt(Position.cumulativeOffset($('page_3'))[1]) - 143;
	$('boneca_1').style.top = boneca1_top + 'px';

	// Calculando a posição da boneca 2.
	var boneca2_top = parseInt(Position.cumulativeOffset($('page_3'))[1]) + 44;
	$('boneca_2').style.top = boneca2_top + 'px';

	$('cotovelo').style.display = 'block';
	$('boneca_1').style.display = 'block';
	$('boneca_2').style.display = 'block';
}

function montarLinks() {
	var links = $$('#arquivo_ano a[href]');
	var count = links.length;
	for (var i=0; i<count; i++) {
		links[i].href = "javascript:getExposicoes('"+ links[i].href +"', '"+ links[i].innerHTML +"');";
	}
}

function montarLinksGaleria() {
	var linksAnterior = $$('#anterior a[href]');
	var linksProximo = $$('#proximo a[href]');
	
	if (linksAnterior.length > 0) {
		var parametro = '';
		if (linksAnterior[0].href.indexOf('pagina') == -1) {
			parametro = "?pagina=1";
		}
		linksAnterior[0].href = "javascript:getPagina('"+ linksAnterior[0].href +  parametro + "');";
	}

	if (linksProximo.length > 0) {
		var parametro = '';
		if (linksProximo[0].href.indexOf('pagina') == -1) {
			parametro = "?pagina=1";
		}
		linksProximo[0].href = "javascript:getPagina('"+ linksProximo[0].href + parametro + "');";
	}
}

var retorno = '';
function getExposicoes(url, ano) {
	if (($(ano).style.display == 'none') || ($(ano).style.display == '')) {
		retorno = ano;
		new Ajax.Request(url, {method:"get",
									  asynchronous:false,
									  onSuccess:function(Response) { 
											$(retorno).innerHTML = Response.responseText;
											$(retorno).style.display = 'block';
									  }
									 });	
	} else {
		$(ano).style.display = 'none';
	}
}

function getExposicao(url) {
	new Ajax.Request(url, {method:"get",
								  asynchronous:false,
								  onSuccess:function(Response) { 
										$('conteudo_1').innerHTML = Response.responseText;
										posicionarImagens();
								  }
								 });	
}

function getObra(url) {
	new Ajax.Request(url, {method:"get",
								  asynchronous:false,
								  onSuccess:function(Response) { 
										$('galeria_1').innerHTML = Response.responseText;
										posicionarImagens();
								  }
								 });	
}

function getPagina(url) {
	new Ajax.Request(url, {method:"get",
								  asynchronous:false,
								  onSuccess:function(Response) { 
										$('conteudo_2').innerHTML = Response.responseText;
										montarLinksGaleria();
								  }
								 });	
}