// JavaScript Document
var Ac = {
	size:12,
	letraMaior:function() {
		if ( this.size < 16 ) {
			this.size++;
createCookie("fs", this.size, 365);
			document.body.style.fontSize = this.size+'px';
		}
	},
	letraMenor:function() {
		if ( this.size > 11 ) {
			this.size--;
createCookie("fs", this.size, 365);
			document.body.style.fontSize = this.size+'px';
		}
	},
	contraste:function() {
		setActiveStyleSheet('Acessível')
	},
	normal:function() {
		setActiveStyleSheet('Padrão');

	},
	impressao:function() {
		setActiveStyleSheet('Impressão');
		var print = document.getElementById("print_preview_aviso");
		if ( print != null ) {
			print.innerHTML = "";
			var aviso = document.createElement("div");
			aviso.className = "aviso";
			var strong = document.createElement("strong");
			strong.appendChild(document.createTextNode("Atenção, esta é uma versão para impressão da página que você estava."));
			aviso.appendChild(strong);
			aviso.appendChild(document.createElement("br"));
			aviso.appendChild(document.createTextNode("O que será impresso é o documento a partir do tracejado abaixo."));
			aviso.appendChild(document.createElement("br"));
			var a = document.createElement("a");
			a.appendChild(document.createTextNode("Após a impressão, clique aqui para voltar a página anterior."));
			a.onclick = function(){setActiveStyleSheet('Padrão'); this.parentNode.parentNode.removeChild(this.parentNode); return false;};
			a.href = "javascript:;";
			aviso.appendChild(a);
			print.appendChild(aviso);
			print.appendChild(document.createElement("hr"));
var img = document.createElement("img");
img.src = "/opencms/export/system/modules/br.gov.capes.portal/resources/logo_print.gif";
document.getElementById("logo_print").appendChild(img);

		}
	}

}


function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function goanchor(an) {document.location = (document.location+"").split("#")[0]+"#"+an;}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);

  var fs = readCookie("fs");
  if ( !isNaN(parseInt(fs)) ) {
    document.body.style.fontSize = parseInt(fs)+"px";
    Ac.size = parseInt(fs);
  }
}


if ( document.body ) {
  var fs = readCookie("fs");
  if ( !isNaN(parseInt(fs)) ) {
    document.body.style.fontSize = parseInt(fs)+"px";
    Ac.size = parseInt(fs);
  }
}



window.onunload = function(e) {
  var title = getActiveStyleSheet();
  if (title != 'Impressão') {
	  createCookie("style", title, 365);
  }
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);


var slides = {
	fx:null,
	i:1,
	paused:true,
	go:function( n ) {
		if ( this.i == n  || (this.fx != null && this.fx.now != 1) ) {
			return;
		}
		$( 'd' + this.i ).setStyle('opacity', 0);
		this.i = n 
		var el = $('d'+this.i);
		this.fx = new Fx.Style(el, 'opacity', {duration:500});
		this.fx.custom(0, 1);
		el.setStyle('display', '');
		$("b1").className = (n==1)?"selected":"";
		$("b2").className = (n==2)?"selected":"";
		$("b3").className = (n==3)?"selected":"";
		$("b4").className = (n==4)?"selected":"";
	},
	pause:function() {
		if ( this.paused ) {
			this.ti = setInterval(this.forward.bind(this), 12000);
		} else {
			clearInterval(this.ti);
		}
		this.paused = !this.paused;
		if ( this.paused ) {
			$("pause").className = "paused";
		} else {
			$("pause").className = "playing";
		}
	},
	forward:function() {
		var t = this.i + 1;
		if ( t > 4 ) {
			t = 1;
		}
		this.go( t );
	},
	rewind:function() {
		var t = this.i - 1;
		if ( t < 1 ) {
			t = 4;
		}
		this.go( t );
	}
};