/**
 A utiliser avec l'extension fontresize
*/

// Initialize the arrays containing our size info.

var pixelArray = new Array('10','11','12','13','14','15', '16', '18', '20', '24'); // Possible font px sizes
var countOfPixels = pixelArray.length;
var initSize = 2; // Array position of inital px size

function fontSizer(inc) {
	var size = readCookie('size');
	size = parseInt(inc)+parseInt(size);
	if (size < 0 ) { size = 0; }
	if (size > countOfPixels ) { size = countOfPixels; }
	doFontSizing(size);
	createCookie("size", size, 365);
}

function fontSizerOnLoad(preferredSize) {
	var size = readCookie('size');	
	if (size < 0 ) { size = 0; }
	if (size > countOfPixels ) { size = countOfPixels; }

	doFontSizing(size);
}

function doFontSizing(theFontSize) {
    var selectorByClass = $$('#formatType, .resume_page ,  .blocContenu ,  .titre_page, #formatType .titre, #formatType .titre_master a '); 
    selectorByClass.each(function(a) {a.setStyle({ fontSize :pixelArray[theFontSize] + 'px' } )});  
}

function normalSize() {

	var size = initSize;	
	doFontSizing(size);	
	createCookie("size", size, 365);
}

function normalSizePrint() {
	/*if (!document.getElementById) return;*/	
	var size = initSize;	
	doFontSizing(size);	
}

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 initSize;
}

window.onload = function(e) {
	fontSizerOnLoad(readCookie("size"));
}
