$(document).ready(function(){
	$(".indice a").click(function(){
		if(!$(this).hasClass("selected")){
			var selectedIndex = $(this).index();
			var page = $(this).attr("href").replace("#","");
			
			$(".indice").find(".selected").removeClass("selected");
			$(".indice:eq(0) a:eq(" + selectedIndex + "),.indice:eq(1) a:eq(" + selectedIndex + ")").addClass("selected");
			
			window.scrollTo(0, $("#menu").position().top);
			
			$.ajax({
				url: "carregaImagens.php",
				type: "POST",
				data: {"pagina":page},
				async: false,
				context: $("#conteudoint"),
				success: function(data){
					$(this).find(".imagemimprensa").each(function(){
						$(this).remove();
					});
					$(this).find(".indice:eq(0)").after(data);
				}
			});
		}
	return false;
	});
});// JavaScript Document

function AreaTotal(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // todos menos Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...funcionaria tb no Explorer 6 modo Strict, Mozilla e Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) { // todos menos Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 modo Strict 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // outros Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	if (yScroll < windowHeight){
		AlturaTotal = windowHeight;
	} else {
		AlturaTotal = yScroll;
	}
	if (xScroll < windowWidth){
		LarguraTotal = windowWidth;
	} else {
		LarguraTotal = xScroll;
	}
	
	return [LarguraTotal,AlturaTotal,windowWidth,windowHeight];
}

function PagNot(pag,pm){
	var elems = document.getElementById("inner").getElementsByTagName("a");
	//alert(elems[0]);
	for (var i in elems){
		//if (elems[i].className == "inline escolh"){
		//alert(elems[i].className);
		elems[i].className = "inline";
	//}
	}
	
	document.getElementById("numeropag"+pm).className = "inline escolh";
	
	var elemsd = document.getElementById("conteudomenu").getElementsByTagName("div");
	
	for (var d in elemsd){
		if (elemsd[d].className == "blocolinks") elemsd[d].style.display = "none";
	}
	document.getElementById("menu"+pag).style.display = "block";
	
	if (pm<10) pagst = "0"+pm; 
	else pagst = pm;
	
	pagst = "p&aacute;g. "+pagst
	
	document.getElementById("numeroatual").innerHTML = pagst;
}
function PagVideos(pag){
	var elems = document.getElementById("inner").getElementsByTagName("a");
	for (var i in elems){
	//if (elems[i].className == "inline escolh") 
		elems[i].className = "inline";
	}
	
	document.getElementById("numeropag"+pag).className = "inline escolh";
	
	var elemsd = document.getElementById("coluna1").getElementsByTagName("div");
	for (var d in elemsd){
		if (elemsd[d].className == "blocolinks") elemsd[d].style.display = "none";
	}
	
	document.getElementById("pag"+(pag-1)).style.display = "block";
	
	if (pag<10) pagst = "0"+pag;
	else pagst = pag;
	
	pagst = "p&aacute;g. "+pagst
	
	document.getElementById("numeroatual").innerHTML = pagst;	
}
function ScrollLateral(elem,increm){
	if (increm=="d"){
		document.getElementById(elem).scrollLeft -= 3;
	} else {
		document.getElementById(elem).scrollLeft += 3;
	}
}

var intervalo = null;

function ScrollContinuo(elem,increm){
	intervalo = setInterval("ScrollLateral('"+elem+"','"+increm+"')",10);
}
function ScrollPara(elem,increm){
	clearInterval(intervalo);
	intervalo = null;
}
function MudaVideo(idv,leg){
	MostrAJAX("video.php?titulo="+unescape(leg)+"&video="+idv,"coluna2");
}
function MudaFoto(arq,leg){
	document.getElementById("fotoampliada").src = arq;
	document.getElementById("fotoampliadalegenda").innerHTML = leg;
}
function Overlay(uri,w,h,lang) {
	var objBody = document.getElementsByTagName('body').item(0);
	var Area = AreaTotal();
	var Largura = Area[0];
	var Altura = Area[1];
	var LarguraTela = Area[2];
	var AlturaTela = Area[3];
	var bodyOverlay = document.createElement("div");
	
	bodyOverlay.setAttribute('id','bodyOverlay');
	bodyOverlay.style.height = Altura + 'px'; // fundo com o tamanho total da página.
	if (!document.getElementById('bodyOverlay')) {
		objBody.insertBefore(bodyOverlay, objBody.firstChild);
	}
	
	var bed = document.createElement("div");
	bed.setAttribute('id','bedOverlay');
	bed.style.width = '100%';
	bed.style.height = Altura + 'px';
	bed.style.top = ((AlturaTela/2)-(h/2)) + "px";
	bed.style.left = ((LarguraTela/2)-(w/2)) + "px";
	
	objBody.insertBefore(bed, objBody.firstChild);
	
	var imagem = document.createElement("img");
	imagem.setAttribute('id','imgOverlay');
	imagem.setAttribute('src',uri);
	imagem.style.border = "1px solid #fff";
	bed.appendChild(imagem);
	
	var fechar = document.createElement("a");
	fechar.setAttribute('id','fecharimagem');
	
	if (lang==1) fechar.innerHTML = "fechar";
	else fechar.innerHTML = "close"; 
	fechar.setAttribute('href','javascript:removerOverlay()');
	fechar.style.width = (w-8) + "px";
	bed.appendChild(fechar);}function removerOverlay() {
	
	var bodyOverlay = document.getElementById('bodyOverlay');
	if (bodyOverlay) {
		bodyOverlay.parentNode.removeChild(bodyOverlay);
	}
	
	document.getElementById('bedOverlay').parentNode.removeChild(document.getElementById('bedOverlay'));
}

function MostrAJAX(uri, elem){
    if (window.XMLHttpRequest) reqvar = new XMLHttpRequest();
	else if (window.ActiveXObject) reqvar = new ActiveXObject("Microsoft.XMLHTTP");
    reqvar.onreadystatechange= function() {
		if (reqvar.readyState==4) {
			if (reqvar.status==200) {
				//alert(reqvar.responseText);
				document.getElementById(elem).innerHTML = reqvar.responseText;
			} else { 
				//if (reqvar.status == 404){
				document.getElementById(elem).innerHTML = "<div class='caixadeerro'>Erro: <span>" + reqvar.statusText + "<h3>" + uri + "</h3></span></div>";
			} 
		} else if (reqvar.readyState == 1) { 
			//carregando
			document.getElementById(elem).innerHTML = "<div class='carregando'><span>carregando...</span></div>";
		}    
	}
    reqvar.open("POST",uri,true);
	
    if (window.XMLHttpRequest) 
		reqvar.send(null);
	else if (window.ActiveXObject) 
		reqvar.send();
}
