// TafT FontAdjust 1.0
// By Csordas Zoltan
// @ Dotcom.lu
// 12/06/2008

//INITIANISATION DES BOUTONS JS / DESACTIVATION DES BOUTONS PHP
document.getElementById("less").href="#";
document.getElementById("reset").href="#";
document.getElementById("more").href="#";

//*********************************************************************************/
function SetCookie (name, value)
{
	//nouvel objet date
	var aujourdhui = new Date() ;
	 
	//nouvel objet date
	var expdate = new Date() ;
	 
	//plus an an à partir d'aujourdh'ui le cookie ne s'efface jamais
	expdate.setTime( aujourdhui.getTime() + ( 365*24*60*60*1000 ) )
	 
	//creation du cookie
	document.cookie = name + "=" + value + ";expires=" + expdate.toGMTString() ;
}
/*********************************************************************************/
function GetCookie (name) {
         if ( document.cookie) { // Le cookie est-il valide ?
                  index = document.cookie.indexOf(name);//existe-t-il?
                  if ( index != -1) {
                           nDeb = (document.cookie.indexOf( "=", index) + 1);
                           nFin = document.cookie.indexOf( ";", index);
                           if (nFin == -1) {nFin = document.cookie.length;}
                           return unescape(document.cookie.substring(nDeb, nFin));
                  }
         }
         return null;
}
/*********************************************************************************/
var isNav, isIE;
var w, h;
isNav = false;
isIE = false;
res_influence = 0.90;
c_window_influence = 0.05;// réduction en fonction du ratio écran fenetre
c_max_resize= 100;//proportion maximale de grossissement
min_resize=90;
//teste
test_string='';
defaultCtrl_resize = 0;


timer = setInterval('TaftSize()',50);

function TaftSize(bigger)
{
		myCookie=GetCookie("sc_taft");
		if(myCookie){
		//alert("Coockie trouvé = "+myCookie);
		ctrl_resize = parseInt(myCookie);
		}else{
		ctrl_resize = 0;
		}

		pageBody = document.getElementsByTagName('body');
		
		if ( parseInt(navigator.appVersion) >= 3 ){
			if ( navigator.appName == "Netscape" ) {isNav = true;}else{isIE= true;}
		}
		h = 3;
		w = 5;
		if ( isNav ){
			h = self.innerHeight;
			w = self.innerWidth; 
		}
		if ( isIE ){
			h = document.body.clientHeight;
			w = document.body.clientWidth;
		}
		sc_w=screen.width;
		max_resize=(sc_w/800)*c_max_resize;
		//max_resize= Math.sqrt(sc_w/800)*c_max_resize;
		window_influence = c_window_influence/((sc_w/800));// + de résolution, + de réduction
		ratio=(w/sc_w); // RAPPORT FENETRE sur TAILLE ECRAN 0.x0 ou %
		
		// On calcule la taille de la police + grande pour les grandes résolutions
		if(sc_w>800){
			//								(1.xxxx - 1)  * 0.xxx
			//resolutionRatio=Math.round((1+(((sc_w/800)-1)*res_influence))*100);
			//								(1.xxxx) *100 = 1xx%
			//resolutionRatio=Math.round(((sc_w/800))*100);
			resolutionRatio=Math.round(sc_w/10);
		}else{
			resolutionRatio=100;
		}
		//						O.xx
		ratioDelta = Math.round((ratio)*resolutionRatio);
		//ratioDelta = Math.round((((1-ratio)*window_influence)+ratio)*resolutionRatio);
		//						ratio interface/ecran * proportion pixel
		
		// NEWSIZE :Calcule l'incrément du zoom proportionné selon la résolution 
		//zoom = (sc_w/1024)*20;
		zoom = 20;
		switch(bigger)
		{
		case 1:			//Augmentation de la taille de police
						newSize=ratioDelta+ctrl_resize+zoom;
						tmp_ctrl_resize =ctrl_resize+zoom;
						test_string+="Cas Grossissement<br />";
						break;
						
		case 0:			//Reset de la taille de police
						newSize=ratioDelta;
						ctrl_resize=tmp_ctrl_resize =0;// * Reset complet sinon le default if suivant ne sera pas exécuté!
						test_string+="Cas Reset<br />";
						break;
						
		case -1:		//Réduction de la taille de police
						newSize=ratioDelta+ctrl_resize-zoom;
						tmp_ctrl_resize =ctrl_resize-zoom;
						test_string+="Cas Reduction<br />";
						break;
						
		default:		// Affichage du texte à l'échelle de base: ratiocalculé + crtl_resize
						newSize=ratioDelta+ctrl_resize;
						tmp_ctrl_resize =ctrl_resize;
						test_string+="Cas Rafraîchissement<br />";
						break;
		}
		// Limiteur de taille:
		if(newSize>=max_resize)
		{
			test_string+="Max size reached!<br />";
			newSize=max_resize;
			ctrl_resize=max_resize-ratioDelta;
		}
		else if(newSize<=min_resize)
		{
			test_string+="Min size reached!<br />";
			newSize=min_resize;
			ctrl_resize=min_resize-ratioDelta;
		}
		else
		{
			test_string+="Common size<br />"; // * voir plus haut
			ctrl_resize=tmp_ctrl_resize;
		}
		SetCookie("sc_taft",ctrl_resize);
		applySize(newSize);
		
		test_string +="myCookie before ="+myCookie+"<br />ratio ="+ratio+"<br />window_influence ="+window_influence+"<br />ratioDelta ="+ratioDelta+"<br />max_resize ="+max_resize+"<br />newSize ="+newSize+"<br /> ctrl_resize ="+ctrl_resize;
		//document.getElementById("data").innerHTML = test_string;
		test_string='';//RESET
}


function applySize(NewRatio)
{
	pageBody = document.getElementsByTagName('body');
	TheRatio = NewRatio+"%";
	//alert("newSize ="+newSize );
	
	for (i=0; i < pageBody.length; i++){
		pageBody[i].style.fontSize = TheRatio;
	}	
}

