
// Initialize the arrays containing our size info.
var pixelArray = new Array('0.65em','0.70em','0.80em','1em','1.05em','1.1em'); // Possible font px sizes
var countOfPixels = pixelArray.length -1;
var initSize = 2; // Array position of inital px size

function fontSizer(inc) {
	/*if (!document.getElementById) return;*/

	var size = readCookieFont('chiusapesio_font');
	size = parseInt(inc)+parseInt(size);

	if (size < 0 ) { size = 0; }	
	if (size >= countOfPixels ) { size = countOfPixels; }
	
	doFontSizing(size);	
	
	createCookie("chiusapesio_font", size, 365);
}

function fontSizerOnLoad(preferredSize) {	
	/*if (!document.getElementById) return;*/
	var size = readCookieFont('chiusapesio_font');	
	if (size < 0 ) { size = 0; }
	if (size > countOfPixels ) { size = countOfPixels; }
	
	/*switchPic();*/
	doFontSizing(size);
}

function doFontSizing(theFontSize) {	
	// if you rather want to size an individual element by ID, use this:
	// resizeContainer = document.getElementById('nameOfConainingElement');	
	// and uncomment the if statements at the start of each function
	resizeContainer = window.document.getElementsByTagName('body')[0];
	resizeContainer.style.fontSize = pixelArray[theFontSize];	
}

function normalSize() {
	/*if (!document.getElementById) return;*/
	var size = 2;
	doFontSizing(size);	
	createCookie("chiusapesio_font", size, 365);
}

//scrive il Cookie
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=/';
};

//legge il Cookie Css
function readCookieCss(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);
		}
	}
};

//legge il Cookie Font
function readCookieFont(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 initSize;
};

//estrae il nome del foglio di stile
function setCSS(nome_file_css) 
{ 
	createCookie("chiusapesio_skin",nome_file_css,365);
	location.reload();
};

//applica il foglio di stile
function setCSShref(nome_file_css) 
{
	var link_ = document.getElementsByTagName("link");
	var href = "";
	var posiz = 0;
	
	if(link_[0].media=="screen") 
	{ 
		href = link_[0].href;
		posiz = href.lastIndexOf("/"); 
		href = href.substring(0, posiz + 1);
		link_[0].href=href + nome_file_css + ".css";
	}
};

window.onload = function(e) {
	//fontSizerOnLoad(readCookie("chiusapesio_font"));
	var size = readCookieFont("chiusapesio_font");
	if(size)
	{
		fontSizerOnLoad(size);
    }
	
	var nome_file_css = readCookieCss("chiusapesio_skin");
	if(nome_file_css)
	{
	  setCSShref(nome_file_css);
    }
	
	//link target _blank
	if(!document.getElementsByTagName) return;
	l=document.getElementsByTagName("a");
	for(i=0;i<l.length;i++)
	{
	  if(l[i].className.indexOf("blank")!=-1)
	  {
	    l[i].onclick=function(){
	    	window.open(this.href);
	    	return(false);};
	  }
	 }
};


















