/*
	js zum veraendern der schriftgroesse.
    eine fuer das dizk angepasste version von efa_fontsize (www.einfach-fuer-alle.de)
*/


function Cookiemanager(name,defaultExpiration,expirationUnits,defaultDomain,defaultPath) {
 this.name = name;
 this.defaultExpiration = this.getExpiration(defaultExpiration,expirationUnits);
 this.defaultDomain = (defaultDomain)?defaultDomain:(document.domain.search(/[a-zA-Z]/) == -1)?document.domain:document.domain.substring(document.domain.indexOf('.') + 1,document.domain.length);
 this.defaultPath = (defaultPath)?defaultPath:'/';
 this.cookies = new Object();
 this.expiration = new Object();
 this.domain = new Object();
 this.path = new Object();
 this.getDocumentCookies();
}

Cookiemanager.prototype.getExpiration = function(expiration,units) {
 expiration = (expiration)?expiration:7;
 units = (units)?units:'days';
 var date = new Date();
 switch(units) {
 	case 'years': date.setFullYear(date.getFullYear() + expiration);
 				  break;
	case 'months': date.setMonth(date.getMonth() + expiration);
 				   break;
 	case 'days': date.setTime(date.getTime()+(expiration*24*60*60*1000));
				 break;
	case 'hours': date.setTime(date.getTime()+(expiration*60*60*1000));
				  break;
	case 'minutes': date.setTime(date.getTime()+(expiration*60*1000));
					break;
	case 'seconds': date.setTime(date.getTime()+(expiration*1000));
					break;
	default: date.setTime(date.getTime()+expiration);
			 break;
 }
 return date.toGMTString();
}

Cookiemanager.prototype.getDocumentCookies = function() {
 var cookie,pair;
 var cookies = document.cookie.split(';');
 var len = cookies.length;
 for(var i=0;i < len;i++) {
 	cookie = cookies[i];
 	while (cookie.charAt(0)==' ') 
 		cookie = cookie.substring(1,cookie.length);
 	pair = cookie.split('=');
 	this.cookies[pair[0]] = pair[1];
 }
}

Cookiemanager.prototype.setDocumentCookies = function() {
 var expires = '';
 var cookies = '';
 var domain = '';
 var path = '';
 for(var name in this.cookies) {
 	expires = (this.expiration[name])?this.expiration[name]:this.defaultExpiration;
 	path = (this.path[name])?this.path[name]:this.defaultPath;
 	domain = (this.domain[name])?this.domain[name]:this.defaultDomain;
 	cookies = name + '=' + this.cookies[name] + '; expires=' + expires + '; path=' + path + '; domain=' + domain;
 	document.cookie = cookies;
 }
 return true;
}

Cookiemanager.prototype.getCookie = function(cookieName) {
 this.getDocumentCookies();
 var cookie = this.cookies[cookieName];
 return (cookie)?cookie:false;
}

Cookiemanager.prototype.setCookie = function(cookieName,cookieValue,expiration,expirationUnits,domain,path) {
 this.cookies[cookieName] = cookieValue;
 if (expiration) 
 	this.expiration[cookieName] = this.getExpiration(expiration,expirationUnits);
 if (domain) 
 	this.domain[cookieName] = domain;
 if (path) 
 	this.path[cookieName] = path;
	
 this.setDocumentCookies();
 return true;
}

var cookieManager = new Cookiemanager('cookieManager',1,'years');

/* ----------------- */



var efa_default = 0.69;
var efa_app_default = 1;
var efa_increment = 0.1;
var efa_bigger = [	'', 
					'<img src="'+imgBasePath+'/plus1.gif"  alt="'+message_inc+'"  />', 
					message_inc, 
					'',
					'',
 					'',
					'',
					'',
					'',
					'',
					'',
					'' ]

var efa_smaller = [	'',
					'<img src="'+imgBasePath+'/minus1.gif" alt="'+message_dec+'" />',
					message_dec,
					'',
					'',
					'',
					'',
					'',
					'',
					'',
					'',
					'' ]
					
var efa_standard = ['',
					'<img src="'+imgBasePath+'/a1.gif" alt="'+message_def+'" />',
					message_def,
					'',
					'',
					'',
					'',
					'',
					'',
					'',
					'',
					'' ]					

function Efa_Fontsize06(increment,bigger,standard,smaller,def) {
 this.w3c = (document.getElementById);
 this.ms = (document.all);
 this.userAgent = navigator.userAgent.toLowerCase();
 this.isMacIE = ((this.userAgent.indexOf('msie') != -1) && (this.userAgent.indexOf('mac') != -1) && (this.userAgent.indexOf('opera') == -1));
 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_fontSize06";
 	this.cookieName = 'efaSize06_v0.2';
 	this.increment = increment;
	this.def = def;
 	this.defPx = Math.round(16*def)
 	this.base = 1;
	this.pref = this.getPref();
 	this.size = this.calculateSize();
 	this.testHTML = '<div id="efaTest" style="position:absolute;visibility:hidden;line-height:1em;">&nbsp;</div>';
 	this.biggerLink = this.getLinkHtml(1,bigger);
 	this.standardLink = this.getLinkHtml(0,standard);
 	this.smallerLink = this.getLinkHtml(-1,smaller);
 } else {
 	this.biggerLink = '';
 	this.standardLink = '';
 	this.smallerLink = '';
 	this.efaInit = new Function('return true;');
 }

 //this.allLinks = message_fontsize + ':<br />' +  this.smallerLink + this.standardLink + this.biggerLink ;
 this.allLinks = this.smallerLink + this.standardLink + this.biggerLink ;
}

Efa_Fontsize06.prototype.efaInit = function() {
 this.pref = this.getPref();
 this.size = this.calculateSize();
 //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) + 'em';
 if (!is_app) {
  this.body.fontSize = this.size + 'em';
 }
}

Efa_Fontsize06.prototype.getLinkHtml = function(direction,properties) {
 var html = properties[0] + '<a href="javascript:void(0)" onclick="efa_fontSize06.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] + '"':'';
 html += (properties[11])?'style="' + properties[11] + '"':'';
 return html += '>'+ properties[1] + '<' + '/a>' + properties[10];
}



Efa_Fontsize06.prototype.getPref = function() {
 var pref = this.getCookie(this.cookieName);
 if (pref) return parseFloat(pref);
 else return this.def;
}

Efa_Fontsize06.prototype.calculateSize = function() {
 var size = this.pref;
 if (is_app) {
  size = size * (efa_app_default / efa_default);
 }
 return size;
}

Efa_Fontsize06.prototype.setSize = function(direction) {
 this.pref = this.getPref();
 this.pref = (direction)?this.pref+(direction*this.increment):this.def;
 this.size = this.calculateSize();
 this.setCookie(this.cookieName,this.pref);
 
 if (is_app) {
  document.getElementById('container').style.fontSize = this.size + 'em';
  /* 
   * dreckiger hack: die roten sterne hinter den menu-items (affectedAreas) werden bei einer 
   * schriftgr??en?nderung nicht automat. verschoben. dies passiert erst wenn man das element
   * das den text (menupunkt) enth?lt, irgendwie ver?ndert. 
   */
  var timestamp = new Date().getTime();
  var naviEle = document.getElementById('navi');
  var naviLinks = naviEle.getElementsByTagName('SPAN');
  for( var ii = 0; ii < naviLinks.length; ii++ ){
   naviLinks[ii].style.width = timestamp + '%';
   naviLinks[ii].style.width = '100%';
   naviLinks[ii].style.display = 'none';
   naviLinks[ii].style.display = 'inline';
  }
 } else {
  this.body.fontSize = this.size + 'em';
 }
}

Efa_Fontsize06.prototype.getCookie = function(cookieName) {
 var cookie = cookieManager.getCookie(cookieName);
 return (cookie)?cookie:false;
}

Efa_Fontsize06.prototype.setCookie = function(cookieName,cookieValue) {
 return cookieManager.setCookie(cookieName,cookieValue);
}

/* ----------------- */

var is_app = isApp();
function isApp(){
	return (document.location.href.indexOf('/dizk/') > -1 ||
	document.location.href.indexOf('/profil/') > -1);
}

var efa_fontSize06 = new Efa_Fontsize06(efa_increment,efa_bigger,efa_standard,efa_smaller,efa_default);