/* Saemtliche Rechte: Aktion Mensch - Einfach fuer Alle */
/* Lizenzbedingungen zur freien Nutzung: http://www.einfachfueralle.de/lizenz/ */

var efa_default = 100;
var efa_increment = 10;
var efa_bigger = ['<span class="extra">',
	'+',
	'Schrift gr&ouml;&szlig;er stellen',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'<' + '/span>'
	]

var efa_reset = ['<span class="extra">',
	' = ',
	'Schrift zur&uuml;cksetzen',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'<' + '/span>'
	]

var efa_smaller = ['<span class="extra">',
	'-',
	'Schrift kleiner stellen',
	'',
	'',
	'',
	'',
	'',
	'',
	'',
	'<' + '/span>'
	]

function Efa_Fontsize(increment,bigger,reset,smaller,def) {
	this.w3c = (document.getElementById);
	this.ms = (document.all);
	this.userAgent = navigator.userAgent.toLowerCase();
	this.isOldOp = ((this.userAgent.indexOf('opera') != -1)&&(parseFloat(this.userAgent.substr(this.userAgent.indexOf('opera')+5)) <= 7));

	if ((this.w3c || this.ms) && !this.isOldOp && !this.isMacIE) {
		this.name = "efa_fontSize";
		this.cookieName = 'efaSize';
		this.increment = increment;
		this.def = def;
		this.defPx = Math.round(16*(def/100))
		this.base = 1;
		this.pref = this.getPref();
		this.testHTML = '<div id="efaTest" style="position:absolute;visibility:hidden;line-height:1em;">&nbsp;</div>';
		this.biggerLink = this.getLinkHtml(1,bigger);
		this.resetLink = this.getLinkHtml(0,reset);
		this.smallerLink = this.getLinkHtml(-1,smaller);
	} else {
		this.biggerLink = '';
		this.resetLink = '';
		this.smallerLink = '';
		this.efaInit = new Function('return true;');
	}

	this.allLinks = "<nobr>" + this.biggerLink + this.resetLink + this.smallerLink + "</nobr>";
//        alert("Text: >" + this.allLinks + "<");
}

Efa_Fontsize.prototype.efaInit = function() {
		document.writeln(this.testHTML);
		this.body = (this.w3c)?document.getElementsByTagName('body')[0].style:document.all.tags('body')[0].style;
		this.efaTest = (this.w3c)?document.getElementById('efaTest'):document.all['efaTest'];
		var h = (this.efaTest.clientHeight)?parseInt(this.efaTest.clientHeight):(this.efaTest.offsetHeight)?parseInt(this.efaTest.offsetHeight):999;
		if (h < this.defPx) this.base = this.defPx/h;
		this.body.fontSize = Math.round(this.pref*this.base) + '%';
		
		this.initCSS(this.pref);
}

Efa_Fontsize.prototype.getLinkHtml = function(direction,properties) {
	this.ms = (document.all);
	this.hreftext = "";
	if(this.ms) {this.hreftext = "#"; }
	var html = properties[0] + '<a href="' + this.hreftext + '" onclick="efa_fontSize.setSize(' + direction + '); return false;"';
	html += (properties[2])?'title="' + properties[2] + '"':'';
	html += (properties[3])?'class="' + properties[3] + '"':'';
	html += (properties[4])?'id="' + properties[4] + '"':'';
	html += (properties[5])?'name="' + properties[5] + '"':'';
	html += (properties[6])?'accesskey="' + properties[6] + '"':'';
	html += (properties[7])?'onmouseover="' + properties[7] + '"':'';
	html += (properties[8])?'onmouseout="' + properties[8] + '"':'';
	html += (properties[9])?'onfocus="' + properties[9] + '"':'';
	return html += '>'+ properties[1] + '<' + '/a>' + properties[10];
}

Efa_Fontsize.prototype.getPref = function() {
	var pref = this.getCookie(this.cookieName);
	if (pref) return parseInt(pref);
	else return this.def;
}

Efa_Fontsize.prototype.initCSS = function(proz) {
        return;
	this.ms = (document.all);
//        alert(this.getStyleSheetInfo("#leftFooter", "paddingLeft"));
	if(!this.ms) {
          this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "102px");
        } else {
          this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "120px");
	  if (proz < 100)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "116px");
	  if (proz < 90)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "113px");
	  if (proz < 80)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "102px");
	  if (proz < 70)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "97px");
	  if (proz == 100)
          this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "1px");
	  if (proz > 100)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "134px");
	  if (proz > 110)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "160px");
	  if (proz > 120)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "146px");
	  if (proz > 130)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "149px");
	  if (proz > 140)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "190px");
	  if (proz > 150)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "200px");
	  if (proz > 160)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "172px");
	  if (proz > 170)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "183px");
	  if (proz > 180)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "186px");
	  if (proz > 190)
             this.setStyleSheetInfo("#rightFooter .footerNav", "paddingTop", "193px");
        }
        alert("PROZ: " + proz + " / " + this.getStyleSheetInfo("#rightFooter .footerNav", "paddingTop"));
}


Efa_Fontsize.prototype.setSize = function(direction) {
	this.pref = (direction)?this.pref+(direction*this.increment):this.def;

//        if (this.pref > 130) {this.pref = 130;};
//        if (this.pref < 70) {this.pref = 70;};
  
        this.initCSS(this.pref);
        
//        test = this.getStyleSheetInfo("#rightFooter .footerNav", "paddingTop");
//        alert(test);
	this.setCookie(this.cookieName,this.pref);
	this.body.fontSize = Math.round(this.pref*this.base) + '%';
	this.ms = (document.all);
	if(!this.ms) {
//	  this.repaint();
//	  this.body.repaint();
	}
}

Efa_Fontsize.prototype.getStyleSheetInfo = function(name, attr) {
     if(!name || !document.styleSheets) return null;
     var i = document.styleSheets.length;
     while(i--)
     {
         var rules = document.styleSheets[i].rules ? document.styleSheets[i].rules :
         document.styleSheets[i].cssRules;
         var j = rules.length;
         while(j--) { 
                if(rules[j].selectorText == name) {
                   return (rules[j].style[attr]);
                 }
         }
     }
      return null;;
}

Efa_Fontsize.prototype.setStyleSheetInfo = function(name, attr, wert) {
     if(!name || !document.styleSheets) return null;
     var i = document.styleSheets.length;
     while(i--)
     {
         var rules = document.styleSheets[i].rules ? document.styleSheets[i].rules :
         document.styleSheets[i].cssRules;
         var j = rules.length;
         while(j--) { 
                if(rules[j].selectorText == name) {
                   rules[j].style[attr] = wert;
                   return (rules[j].style[attr]);
                 }
         }
     }
      return null;;
}


Efa_Fontsize.prototype.getCookie = function(cookieName) {
	var cookie = cookieManager.getCookie(cookieName);
	return (cookie)?cookie:false;
}

Efa_Fontsize.prototype.setCookie = function(cookieName,cookieValue) {
	return cookieManager.setCookie(cookieName,cookieValue);
}

var  efa_fontSize = new Efa_Fontsize(efa_increment,efa_bigger,efa_reset,efa_smaller,efa_default);

