// very simple fontsizer
// LANDSIEDEL | MÜLLER | FLAGMEYER - www.l-m-f.de
// 2009/2010

// default fontsize
var defaultFontsize=12;

// cookie name
var cookieName='acon';

// script fontsize
var fontsize=12;

// tag id
var tagId='content';

// current date
var a = new Date();

// read cookie and switch the style
function getTextSize() {	
	try	{
		if (document.cookie) {
			document.getElementById(tagId).style.fontSize=""+getCookie()+"px";
		}
		else
			document.getElementById(tagId).style.fontSize=defaultFontsize+"px";
	}
	catch(Exception){}
}

// fontsize switcher
function setTextSize(dec) {
	fontsize=(document.getElementById(tagId).style.fontSize) ? pxByNumber(document.getElementById(tagId).style.fontSize) : fontsize;
	if (dec!=0) {
		if (dec==1)
			fontsize<16 ? fontsize+=1 : fontsize=fontsize;
		else
			fontsize>9 ? fontsize-=1 : fontsize=fontsize;
	}
	else
		fontsize=defaultFontsize;

	document.getElementById(tagId).style.fontSize=""+fontsize+"px";
	
	setCookie(fontsize);
}

// get current fontsize value and replace 'px' from value
function pxByNumber(px) {
	return px.substring(0,px.length-2)*1;
}

// save the fontsize to cookie
function setCookie(fontsize) {
	a = new Date(a.getTime() +1000*60*60*24*365);
	document.cookie = cookieName+'_fontsize='+fontsize+'; expires='+a.toGMTString()+';';
}

// get cookie with the fontsize value
function getCookie(){
   var i=0  //Suchposition im Cookie
   var suche = cookieName+"_fontsize=";
   while (i<document.cookie.length){
      if (document.cookie.substring(i, i+suche.length)==suche){
         var ende = document.cookie.indexOf(";", i+suche.length)
         ende = (ende>-1) ? ende : document.cookie.length
         var cook = document.cookie.substring(i+suche.length, ende)
         return unescape(cook)
      }
      i++
   }
   return null
}
