// JavaScript Document

function init(){
	var qtd = $('.accordion dd').size();
	var dd = Array(qtd);
	var indice = $('.accordion dt.active').prevAll('dt').size();	
	for(a = 0; a < qtd; a ++){
		dd['item' + a] = $('.accordion dd:eq('+a+')').height();
		$('.accordion dt:eq('+a+')').click(function(){
			if($(this).next('dd').height() > 0){
				$('.accordion dt').removeClass('active');
				$(this).children('span').html('+')
				$(this).next('dd').animate({
					height: 0 + 'px',
					paddingTop: 0 + 'px',
					paddingBottom: 0 + 'px'
				}, 500, function(){
					$(this).animate({
						border: 0					   
					}, 100);
				});
			}else{
				$('.accordion dt').removeClass('active');
				$('.accordion dt').children('span').html('+')
				$(this).children('span').html('-')
				$(this).addClass('active');
				indice = $('.accordion dt.active').prevAll('dt').size();
				
				$(this).next('dd').prevAll('dd').animate({
					height: 0 + 'px',
					paddingTop: 0 + 'px',
					paddingBottom: 0 + 'px'
				}, 500, function(){
					$(this).animate({
						border: 0					   
					}, 100, function(){
					
					});
				});
				$(this).next('dd').nextAll('dd').animate({
					height: 0 + 'px',
					paddingTop: 0 + 'px',
					paddingBottom: 0 + 'px'
				}, 500, function(){
					$(this).animate({
						border: 0					   
					}, 100, function(){
					
					});
				});
				
				$(this).next('dd').height(0);
				$(this).next('dd').css('border', '1px solid #D5D9E3');
				$(this).next('dd').css('padding', '0 3%');
				$(this).next('dd').animate({
					height: dd['item' + indice] + 'px',
					paddingTop: 15 + 'px',
					paddingBottom: 15 + 'px'
				}, 500);
			}
		});
	}
	$('.accordion dt.active').next('dd').nextAll('dd').height(0);
	$('.accordion dt.active').next('dd').nextAll('dd').css('border', 'none');
	$('.accordion dt.active').next('dd').nextAll('dd').css('padding', '0 15px');
}


$(document).ready(function(){	
	init();
// Banner home
	$('#banner .slide').cycle({
		fx: 'scrollLeft',
		speed: 700,
		next: '#banner .right',
		prev: '#banner .left',
		timeout: 5000,
		pager: '#banner ul',
		pagerAnchorBuilder: pagerFactory
	});
	function pagerFactory(idx, slide) {
		return '<li>'+(idx+1)+'</li>';
	};
	
// abas home	
	$('.abas li').click(function(){
		$('.abas li a').removeClass('active');
		$(this).children('a').addClass('active');
		$('.tab').hide();						 
		var a = $(this).prevAll().size() +1;	
		$('.tab'+a).show();
	});
	
// linha do tempo
	$('.desc').cycle({
		fx: 'fade',
		timeout:0,
		next: '.tempo .next',
		prev: '.tempo .prev',
		pager: '.line',
		after: function(){$('.desc').css('height', $('.desc li:eq(' + $('.line li.active').prevAll().size() + ')').css('height'))},
		activePagerClass:'active',
		pagerAnchorBuilder: pagerFactoryn
	});	
	function pagerFactoryn(idx, slide) {
		return '<li title="' + $('.desc li:eq(' + idx + ')').children('h4').text() + '">'+ $('.desc li:eq(' + idx + ')').children('h4').text() +'</li>';
	};
	
	$('a[rel="lightbox"]').colorbox({
		title: function(){var tit = $(this).children('img').attr('alt'); return tit;}							
	});
	$('a[rel="lightbox1"]').colorbox({
		title: function(){var tit = " "; return tit;}											
	});
});



