//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="col2";
//Id of our new element
var fontresizer="drkfontresizer";
//visible label
var label = "Zoom: ";
//visible links
var links = new Array("A","A","A","A");
//link title attributes
var title = new Array("Kleine Schrift","Normale Schrift","Gro%DFe Schrift","Sehr gro%DFe Schrift");
//standard font size
var fsize=75;
//zoomstep size
var zoomStep=25;
//cookie name
var cookieName="drk-font-size";

//RSS Link
//visible link
var rsslink="RSS Link Icon";    
//link title attributes
var rsstitle="RSS";

//Generates a rss url
var tempUrl= self.location.href;
var selfUrl= tempUrl.substr(0,tempUrl.lastIndexOf(".")+5);
    selfUrl=selfUrl+"?type=100";

//imagepath
var rssIconPath="typo3conf/ext/drk_layout/templates/news/rss_link.png";    

//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);
      bodySelect.style.width = '14em';
      bodySelect.style.height = '2em';
      bodySelect.style.padding = '0.1em';
      var info = document.createTextNode(label);
      bodySelect.appendChild(info);
      //append geht hier nicht kein Platz
      //document.getElementById(container).appendChild(bodySelect);
      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','drkzoomlink0'+i);
      optionLink.setAttribute('title',unescape(title[i]));
      optionLink.setAttribute('class','drkzoomlink');   
      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;
      }

      optionLink = document.createElement("a");
      optionLink.setAttribute('href',selfUrl);
      optionLink.setAttribute('id','drkrsslink');
      optionLink.setAttribute('title',unescape(rsstitle));
      optionLink.setAttribute('class','drkrsslink');   
      optionLink.style.textDecoration = 'none'; 
      optionLink.style.padding = '1px';            
      
      var img=document.createElement("img");
      img.setAttribute("src", rssIconPath);
      img.setAttribute("class", "rssicon");
      img.setAttribute("alt",rsslink);
      
      //var txt = document.createTextNode(rsslink);
      optionLink.appendChild(img);
      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);

