//simple fontresize script to use this as an optional feature
// Michael Kasten April 2010, Copyright under GPL
//tested with: FF 3.6, Chrome 5.0, IE7, IE8

//Font Resize
//Id of the element where we will see the fontresize controlbar
var container="meta";
//Id of our new element
var fontresizer="fontresizer";
//visible label
var label = "Schriftgröße:";
//visible links
var links = new Array("=","+","++");
//link title attributes
var title = new Array("Normale Schrift","Gro%DFe Schrift","Sehr gro%DFe Schrift");
//standard font size
var fsize=100.1;
//zoomstep size
var zoomStep=25;
//cookie name
var cookieName="ka-font-size";

//crossbrowser
function addLoadEvent(func){   
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
        window.onload = func;
    } else {
        window.onload = function(){
        oldonload();
        func();
        }
    }
}

//basic resize function
function getTheseValue(values){
   pBody= document.getElementsByTagName("body")[0];
   values= values.substr(1);
   pBody.style.fontSize= values+"%";   
   createCookie(cookieName,values,365);
   }

//initial function will
//create a control bar
//and use an existing cookie
function initResize(){
   
   //first: is there any cookie out there?
   var cvalue = document.cookie.split(';');
   if(cvalue!=""){
      for(var i=0; i<cvalue.length; i++){
         if(cvalue[i].indexOf(cookieName)!=-1){
            var temp =cvalue[i]; 
            }
         }
      if(temp!=undefined){ 
      var cookieSize = temp.substr(temp.indexOf('=')+1);
      pBody= document.getElementsByTagName("body")[0];
      pBody.style.fontSize= cookieSize+"%"; 
      }
   }
   
   containerBody= document.getElementById(container);
   if(document.getElementById(fontresizer) == null ){    
      bodySelect = document.createElement('div');
      bodySelect.setAttribute('id',fontresizer);
      var info = document.createTextNode(label);
      bodySelect.appendChild(info);
      document.getElementById(container).insertBefore(bodySelect, document.getElementById("col2_content_oben"));
   } 
   
   //create some links to set the fontsize by the user
   
   //fsize=fsize-zoomStep;
   for(var i=0; i<links.length; i++){
      optionLink = document.createElement("a");
      optionLink.setAttribute('href','#'+fsize);
      optionLink.setAttribute('id','ka-zoomlink0'+i);
      optionLink.setAttribute('title',unescape(title[i]));
      optionLink.setAttribute('class','ka-zoomlink');   
      optionLink.onclick = function () {getTheseValue(this.hash); return false;}            
      optionLink.style.textDecoration = 'none'; 
      //optionLink.style.padding = '2px';
      //optionLink.style.fontSize = fsize+zoomStep+'%';
      
      var txt = document.createTextNode(links[i]);
      optionLink.appendChild(txt);
      document.getElementById(fontresizer).appendChild(optionLink);	
      fsize=fsize+zoomStep;
      }
      document.getElementById(fontresizer).appendChild(optionLink);	
         
}//initResize

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=/';
}

//finaly fire up the scripts
addLoadEvent(initResize);

