// JavaScript Document
var topo = -1;
var fotos = new Array();
var ran_number = 0;

function adicionar_foto_slideshow( _p ){fotos[ fotos.length?fotos.length:0 ] = _p;}
function ir_para_topo(){topo = -2;}
function retroceder_qts(){history.go( topo );}
function limpa_pesquisa(){document.getElementById( 'pesquisar' ).value = '';}

function mostrar_imagem_slideshow(){
	if ( document.getElementById( 'img_slideshow' ) && fotos[ ran_number ] )
		document.getElementById( 'img_slideshow' ).src = endereco_foto + fotos[ ran_number ];
}

function inicializar(){
	if ( document.getElementById( 'links_controlo' ) && history.length > 1 )
		document.getElementById( 'links_controlo' ).className = 'links_controlo_class';
	
	if ( document.getElementById( 'noticias_destaque' ) )
		document.getElementById( 'noticias_destaque' ).innerHTML = noticias_destaque_var;
	
	slideshow();
	
	//mover_destaques();
}

function slideshow(){
	if ( !document.getElementById( 'img_slideshow' ) )
		return;
	
	var ran_unrounded = Math.random() * ( fotos.length - 1 );
	ran_number = Math.floor( ran_unrounded );

	mostrar_imagem_slideshow();
	
	setTimeout( 'slideshow()' , 60000 );
}

function mostrar_div( id ){
	if ( !document.getElementById( 'div_' + id ) ) return;
	
	if ( document.getElementById( 'div_' + id ).className == 'div_escondido' )
	{
		document.getElementById( 'span_' + id ).innerHTML = '&uarr; ';
		document.getElementById( 'div_' + id ).className = 'div_visivel';
	}	
	else
	{
		document.getElementById( 'span_' + id ).innerHTML = '&darr; ';
		document.getElementById( 'div_' + id ).className = 'div_escondido';
	}
}


function mover_destaques()
{
	startY = 177;
	var padding = 30;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	document.getElementById("noticias_destaque").style.top = startY + 'px';
	
	window.stayTopLeft = function()
	{
		var pY = ns ? window.pageYOffset : document.documentElement.scrollTop;
		var topo = document.getElementById("noticias_destaque").style.top;
		var teste = parseInt( topo.substring(0,topo.length-2) ) + (pY + padding - topo.substring(0,topo.length-2))/8;
		
		
		if ( document.getElementById("noticias_destaque").style.top != teste + 'px' )
		{
			if ( teste < startY )
			{
				if ( document.documentElement.clientHeight > document.body.clientHeight )
					document.getElementById("noticias_destaque").style.height = document.body.clientHeight - 75 - startY + 'px';
				else
					document.getElementById("noticias_destaque").style.height = document.documentElement.clientHeight - 245 + 'px';
				
				document.getElementById("noticias_destaque").style.top = startY + 'px';
			}

			else
			{
				document.getElementById("noticias_destaque").style.height = document.documentElement.clientHeight - 100 + 'px';
				
				document.getElementById("noticias_destaque").style.top = teste + 'px';
			}
		}
				
		setTimeout("stayTopLeft()", 10);
	}
	
	stayTopLeft();
}
