$(document).ready(function(){
	$('.conteudoDet .texto').hide();
	showContent($('.conteudoDet .texto:first'));
//	showContent('#info_local');
	
	$('.paginador a.aVoltar').click(function(event){
		event.preventDefault();
		
		current = $('.conteudoDet .texto:visible');
		
		previous = current.prev('div.conteudoDet .texto');
		if (!previous.length) previous = $('.conteudoDet .texto:last');
		showContent(previous);
	});
	
	$('.paginador a.aMais').click(function(event){
		event.preventDefault();
		current = $('.conteudoDet .texto:visible');
		
		next = current.next('div.conteudoDet .texto');
		if (!next.length) next = $('.conteudoDet:first .texto');
		showContent(next);
	});
	
	$('.submenu .link a').click(function(event){
		event.preventDefault();
		showContent($('.texto', $(this).attr('href')));
	});
	
	$('.conteudoDet .cabecalho')
		.hover(
			function(){
				$(this).addClass('hover');
			},
			function(){
				$(this).removeClass('hover');
			}
		)
		.click(function(){
    		pageTracker._trackPageview(document.location.href+'#'+$(this).text());
//    		pageTracker._trackPageview('/'+$(this).text());
//			pageTracker._trackPageview('/'+$(this).attr('href').replace('#',''));
			target = $(this).next();
			switchContent(this, true);
		});
		
	winPrint = null;
	$('.btPrint').click(function(){
		if (winPrint) {
			winPrint.close();
		}
		
		winWidth = 680;
		var lado = (screen.width - winWidth) / 2;
		
		winPrint = popUp('', 'printWindow', 'toolbars=yes,status=yes,resize=no,scrollbars=yes,width='+winWidth+',height=600,top=15,left='+lado+'');
	})
});

function resetPaginador()
{
	$('.paginador a.aVoltar').show();
	$('div.conteudoDet .texto:first:visible').each(function(){
		$('.paginador a.aVoltar').hide();
	});
	
	$('.paginador a.aMais').show();
	$('div.conteudoDet .texto:last:visible').each(function(){
		$('.paginador a.aMais').hide();
	});
}
/*
function showContent(target)
{
	content = $(target);
	
	if (content.length) {
		$('.conteudoDet .texto:visible').hide('blind');
		content.show('blind');
		resetPaginador();
		
		$('.submenu .cont a').each(function(){
			$(this).removeClass('current');
			
			if ($(this).attr('href') == '#'+$(content).attr('id')) {
				$(this).addClass('current');
			}
		});
	}
}
*/

function switchContent(source, closeSelf)
{
	switchingBoxes = true;
	
	targetId = $(source).parents('.conteudoDet:first').attr('id');
	target = $('.texto:hidden', '#'+targetId);
	
	boxesToClose = $('.conteudoDet .texto:visible');
	
	if (!closeSelf) {
		boxesToClose = boxesToClose.filter(':not(#'+targetId+' .texto)')
	}
	
	hideContent(boxesToClose);
	showContent(target);
}

function showContent(el)
{
	efct = $.browser.msie ? null : 'blind';
	$(el)
		.show(efct)
		.parents('.conteudoDet:first')
			.addClass('open')
			.removeClass('closed');
}

function hideContent(el)
{
	efct = $.browser.msie ? null : 'blind';
	$(el)
		.hide(efct)
		.parents('.conteudoDet:first')
			.addClass('closed')
			.removeClass('open');
}
