// JS padrao dos sites


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;
}



// Para fazer funcionar o menu do site em IE
function IEHoverPseudo() {
	var navItems = document.getElementById("menucss").getElementsByTagName("li");
	
	for (var i=0; i<navItems.length; i++) {
		navItems[i].onmouseover=function() {
			this.oldClass = this.className; this.className += " over";
		}
		navItems[i].onmouseout=function() {
			this.className = this.oldClass;
		}
	}
}


// Estabelece o aumento das fontes	
function zoom(how) {
	if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) {
		//era o navegador Opera
		document.getElementById("container").style.fontSize=how+"px";
	}
	else {
		//era outro navegador
		document.all.container.style.fontSize=how+"px";
		document.all.container;
	}
	createCookie("tamanho", how, 365);
}

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 changeFontSize(v) {
	estilo = getActiveStyleSheet();
	
	if (v == "+") {
		if (estilo == "default")  { estilo = "acessib1"; }
		else
		if (estilo == "acessib1") { estilo = "acessib2"; }
		else
		if (estilo == "acessib2") { estilo = "acessib3"; }            
		else {
			estilo = "acessib3";
			alert("O tamanho máximo é o atual");
		}
	}
	if (v == "-") {
		if (estilo == "acessib3") { estilo = "acessib2"; }
		else
		if (estilo == "acessib2") { estilo = "acessib1"; }
		else
		if (estilo == "acessib1") { estilo = "default"; }          
		else {
			estilo = "default";
			alert("O tamanho mínimo é o atual");
		}
	}
	setActiveStyleSheet(estilo);
}

function changeActiveStyleSheet() {
	var actual, other;
	
	actual = getActiveStyleSheet();
	if (actual == 'default') {
		setActiveStyleSheet('acessivel');
	}
	else {
		setActiveStyleSheet('default');
	}
}

function changeSize() {
	var actualsize;
	
	if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) {
		//era o navegador Opera
		actualsize = document.getElementById("container").style.fontSize;
	}
	else {
		//era outro navegador
		actualsize = document.all.container.style.fontSize;
	}
	//alert(actualsize);
	if (actualsize == '11px') {
		document.getElementById("plus").style.visibility = 'hidden';
		document.getElementById("menos").style.visibility = 'visible';      	
		zoom('20');
	}
	else {
		document.getElementById("plus").style.visibility = 'visible';
		document.getElementById("menos").style.visibility = 'hidden';      	
		zoom('11');
	}

}

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 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;
}


window.onload = function(e) {
	IEHoverPseudo();
	var cookie = readCookie("style");
	// var title = readCookie("style");
	var size = readCookie("tamanho");
	//  var title = cookie ? cookie : getPreferredStyleSheet();
	var title = cookie ? cookie : getPreferredStyleSheet();
	if (title == '' || title == null || title.lenght <= 2 || title == 'null') {
		title = 'default';
	}
	if (size == '' || size == null || size == 'null') {
		size = '11';
	}
	setActiveStyleSheet(title);
	zoom(size);  
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}


var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);