$(document).ready(function() {
	//Historia	
	if($('.listagem-anos')[0]){		
		var i = 1;		
		$('.listagem-anos').each(function(){		
			i	= 1;			
			ul	= $(this).find('li');			
			ul.each(function(){			
				$(this).removeAttr('style');			
				if(i % 3 == 0){
					$(this).addClass('last');
				}				
				i++;				
			});			
		});		
	}
	//end Historia
});

// +historia
var tempHTML		= '';
var newHTML			= '';
var selectedYear	= 0;

function fecharBox(elemento){
			
	$('.listagem-anos li').removeAttr('style');
	$('.listagem-anos').removeAttr('style');
			
	$('.ativa').find('li.ativo').html(tempHTML).removeClass('ativo');
	$('.ativa').removeClass('ativa');
	
	$('#'+idElemento).html(tempHTML);
	
	return false;

}

function abreBox(link){

	$('.listagem-anos li.decada-historia').removeAttr('style');
	$('.listagem-anos').removeAttr('style');
	
	elemento		= $(link).parent();
	idElemento		= elemento.attr('id');
	
	$('.ativa').find('li.ativo').html(tempHTML).removeClass('ativo');
	$('.ativa').removeClass('ativa');
	
	tempHTML		= elemento.html();
	
	link.innerHTML += '<span class="carregando-decada hide-text">Carregando</span>';
	
	selectedYearId	= elmId($(link).find('.decada-texto').attr("id"));
	
	newHTML = $.ajax({
		url: rootUrl + "timelineItems/loadItems/decadeId/" + selectedYearId + "/language/" + activeLanguage, 
		async: false
	}).responseText;
								
	//Coloca na Div a classe ativa
	elemento.parent().addClass('ativa');
	
	//Atribui ao li o novo HTML
	elemento.html(newHTML).addClass('ativo');
	
	relLink			= $(link).attr('rel');
	
	if(relLink == 1){
		elemento.html(newHTML).addClass('left');
		ulPai		= elemento.parent();
		primeiroLi	= ulPai.find('li.decada-historia')[1];
		segundoLi	= ulPai.find('li.decada-historia')[2];
		$(primeiroLi).css({
			marginRight : 2,
			marginLeft	: 15,
			marginBottom: 17
		});
		$(segundoLi).css({
			marginRight : 2,
			marginLeft	: 15
		});
		
		if($.browser.msie && ($.browser.version == "6.0")){
			$(primeiroLi).css({
				marginRight : 0,
				marginLeft	: 17,
				marginBottom: 17
			});
			$(segundoLi).css({
				marginRight : 0,
				marginLeft	: 17
			});
		}
			
	} else if(relLink == 2){
		ulPai		= elemento.parent();
		primeiroLi	= ulPai.find('li.decada-historia')[0];
		$(primeiroLi).css({
			marginBottom: 17
		});
	} else if(relLink == 3){
		ulPai		= elemento.parent();
		segundoLi	= ulPai.find('li.decada-historia')[1];
		$(segundoLi).css({
			position	: 'absolute',
			bottom		: 0,
			left		: 0,
			marginBottom: 0
		});
	}
	
}

function escolheAno(elemento){
	conteudoAno		= $('.conteudo-ano');
	selectedItem	= elmId($(elemento).attr("id"));
	
	$('.navegacao-anos-decada').find('.ano-ativo').removeClass('ano-ativo');
	$(elemento).addClass('ano-ativo');
	
	conteudoAno.html('<div class="carregando-ano"></div>');
	conteudoAno.load(rootUrl + 'timelineItems/view/id/' + selectedItem);
}
// end  historia